Skip to content

Commit

Permalink
Merge pull request #15 from natrontech/docs/docker-secrets
Browse files Browse the repository at this point in the history
add docs for docker-secrets & improve error handling
  • Loading branch information
janfuhrer authored Apr 11, 2024
2 parents 2f81382 + fb6f1a3 commit 722a9b2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ You can use the following flags to configure the exporter. All flags can also be
| `pbs.metrics-path` | `PBS_METRICS_PATH` | Path under which to expose metrics | `/metrics` |
| `pbs.web.listen-address` | `PBS_LISTEN_ADDRESS` | Address to listen on for web interface and telemetry | `:9101` |

### Docker secrets

If you are using [Docker secrets](https://docs.docker.com/engine/swarm/secrets/), you can use the following environment variables to set the path to the secrets:

| Environment Variable | Description |
| ------------------------- | ------------------------------- |
| `PBS_API_TOKEN_FILE` | Path to the API token file |
| `PBS_API_TOKEN_NAME_FILE` | Path to the API token name file |
| `PBS_USERNAME_FILE` | Path to the username file |

See an example of how to use Docker secrets with Docker Compose in the [docker-compose-secrets.yaml](docker-compose-secrets.yaml) file.

The variables `PBS_API_TOKEN`, `PBS_API_TOKEN_NAME`, and `PBS_USERNAME` take precedence over the secret files.

## Multiple Proxmox Backup Servers

If you want to monitor multiple Proxmox Backup Servers, you can use the `targets` parameter in the query string. Instead of setting the `pbs.endpoint` flag (or `PBS_ENDPOINT` env), you can use the `target` parameter in the query string to specify the Proxmox Backup Server to monitor. You would then use following URL to scrape metrics: `http://localhost:9101/metrics?target=http://10.10.10.10:8007`.
Expand Down
29 changes: 29 additions & 0 deletions docker-compose-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.8'
services:
pbs-exporter:
build: .
# image: ghcr.io/natrontech/pbs-exporter:latest
container_name: pbs-exporter
user: '65534'
restart: always
ports:
- "9101:9101"
environment:
- PBS_ENDPOINT=https://pbs-server:8007
- PBS_INSECURE=false
- PBS_USERNAME_FILE=/run/secrets/proxmoxbackup-username
- PBS_API_TOKEN_NAME_FILE=/run/secrets/proxmoxbackup-api-token-name
- PBS_API_TOKEN_FILE=/run/secrets/proxmoxbackup-api-token
secrets:
- proxmoxbackup-username
- proxmoxbackup-api-token-name
- proxmoxbackup-api-token

secrets:
# example with secret files in .secrets folder
proxmoxbackup-username:
file: "./.secrets/proxmoxbackup_username.secret"
proxmoxbackup-api-token-name:
file: "./.secrets/proxmoxbackup_api_token_name.secret"
proxmoxbackup-api-token:
file: "./.secrets/proxmoxbackup_api_token.secret"
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,14 +764,19 @@ func main() {

// debug
if *loglevel == "debug" {
log.Printf("DEBUG: ----Using connection endpoint %s", target)
log.Printf("DEBUG: Using connection endpoint %s", target)
}

exporter := NewExporter(target, *username, *apitoken, *apitokenname)
prometheus.MustRegister(exporter)

// catch if register of exporter fails
err := prometheus.Register(exporter)
if err != nil {
// if register fails, we log the error and return
log.Printf("ERROR: %s", err)
}
promhttp.Handler().ServeHTTP(w, r) // Serve the metrics
prometheus.Unregister(exporter) // Clean up after serving

})

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
Expand Down
8 changes: 6 additions & 2 deletions prometheus/static-config/multiple-targets.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Use Case: multiple Proxmox Backup Server, all have the same authentication user/token
# important: env PBS_ENDPOINT not set!
#
# important: env PBS_ENDPOINT NOT SET!
#
# Setup:
# - exporter instance: pbs-exporter:9101
# - first PBS target: https://10.10.10.10:8007
# - second PBS target: https://10.10.10.11:8007

scrape_configs:
- job_name: 'pbs-exporter'
honor_timestamps: true
Expand Down

0 comments on commit 722a9b2

Please sign in to comment.