Skip to content

Lusitaniae/b2_exporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

B2 Exporter

Prometheus exporter for Backblaze B2 storage metrics. Collects bucket statistics (file count and total size) and exposes them via HTTP endpoint.

Prerequisites

  • Go 1.23+

Installation

go  mod  download
go  build  -o  b2_exporter

Usage

Basic Example

./b2_exporter  \
-endpoint-url https://s3.eu-central-003.backblazeb2.com \
-credentials-file  ~/.aws/credentials

Options

  • -endpoint-url - B2 endpoint URL (required)

  • -credentials-file - Path to credentials file (AWS format)

  • -access-key-id - B2 access key ID

  • -secret-access-key - B2 secret access key

  • -include-buckets - Comma-separated list of buckets to include

  • -exclude-buckets - Comma-separated list of buckets to exclude

  • -update-interval - Metrics recalculation interval (default: 1h)

  • -listen-addr - Listen address for Prometheus (default: :8080)

  • -max-concurrency - Parallel bucket processing limit (default: 20)

  • -bucket-timeout - Timeout per bucket listing (default: 3m)

Authentication

Credentials can be provided via:

  • Credentials file: -credentials-file ~/.aws/credentials

  • Environment variables: B2_ACCESS_KEY_ID and B2_SECRET_ACCESS_KEY

  • Command line flags: -access-key-id and -secret-access-key

Examples

Filter buckets:

./b2_exporter  -endpoint-url  https://s3.eu-central-003.backblazeb2.com  \
-credentials-file ~/.aws/credentials \
-include-buckets  bucket1,bucket2

Custom settings:

./b2_exporter  -endpoint-url  https://s3.eu-central-003.backblazeb2.com  \
-credentials-file ~/.aws/credentials \
-update-interval  30m  \
-max-concurrency 10

Metrics

Available at http://localhost:8080/metrics:

  • b2_total_size{bucket="name"} - Total bytes in bucket

  • b2_total_files{bucket="name"} - File count in bucket

  • b2_last_update_time - Last update timestamp

  • b2_update_duration_seconds - Last update duration

  • b2_update_errors_total - Error count

Prometheus Configuration

scrape_configs:
-  job_name:  'b2_exporter'
static_configs:
-  targets: ['localhost:8080']

Grafana Dashboard

A pre-configured Grafana dashboard is available in dashboard.json. Import it into Grafana to visualize B2 storage usage and cost:

  1. Open Grafana
  2. Go to Dashboards → Import
  3. Upload dashboard.json or paste its contents
  4. Select your Prometheus data source

The dashboard includes:

  • Total storage usage per bucket
  • File counts per bucket
  • Storage trends over time
  • Cost estimates based on B2 pricing

Credentials File Format

[default]
aws_access_key_id  = YOUR_B2_KEY_ID
aws_secret_access_key  = YOUR_B2_SECRET_KEY

Alternatively, the AWS SDK will use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.

Health Check

curl  http://localhost:8080/health

License

MIT

About

B2 / S3 object store exporter with total file count and size

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published