Prometheus exporter for Backblaze B2 storage metrics. Collects bucket statistics (file count and total size) and exposes them via HTTP endpoint.
- Go 1.23+
go mod download
go build -o b2_exporter./b2_exporter \
-endpoint-url https://s3.eu-central-003.backblazeb2.com \
-credentials-file ~/.aws/credentials-
-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)
Credentials can be provided via:
-
Credentials file:
-credentials-file ~/.aws/credentials -
Environment variables:
B2_ACCESS_KEY_IDandB2_SECRET_ACCESS_KEY -
Command line flags:
-access-key-idand-secret-access-key
Filter buckets:
./b2_exporter -endpoint-url https://s3.eu-central-003.backblazeb2.com \
-credentials-file ~/.aws/credentials \
-include-buckets bucket1,bucket2Custom settings:
./b2_exporter -endpoint-url https://s3.eu-central-003.backblazeb2.com \
-credentials-file ~/.aws/credentials \
-update-interval 30m \
-max-concurrency 10Available 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
scrape_configs:
- job_name: 'b2_exporter'
static_configs:
- targets: ['localhost:8080']A pre-configured Grafana dashboard is available in dashboard.json. Import it into Grafana to visualize B2 storage usage and cost:
- Open Grafana
- Go to Dashboards → Import
- Upload
dashboard.jsonor paste its contents - 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
[default]
aws_access_key_id = YOUR_B2_KEY_ID
aws_secret_access_key = YOUR_B2_SECRET_KEYAlternatively, the AWS SDK will use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.
curl http://localhost:8080/healthMIT