A lightweight Go service that periodically scrapes metrics from an HTTP endpoint and pushes them to a Prometheus Pushgateway.
Supports:
- HTTP(S) targets
- Basic Authentication for Pushgateway
- Custom metric injection
- Config via environment variables only
- Configurable timeouts for both scraping and pushing
| Variable | Description | Default |
|---|---|---|
SOURCE_URL |
URL of the source metrics endpoint to scrape | http://app:8080/metrics |
PUSHGATEWAY_URL |
URL of the target Pushgateway endpoint (e.g. http://pushgateway:9091/metrics/job/example) |
http://pushgateway:9091/metrics/job/example |
PUSHGATEWAY_USER |
Optional username for HTTP Basic Auth | (empty) |
PUSHGATEWAY_PASS |
Optional password for HTTP Basic Auth | (empty) |
INTERVAL |
Scrape and push interval in seconds | 15 |
SCRAPE_TIMEOUT |
Timeout for scraping operation (seconds) | 5 |
PUSH_TIMEOUT |
Timeout for pushing to Pushgateway (seconds) | 5 |
CUSTOM_METRICS_FILE |
Optional path to file metric for join data on every push | /etc/custom-metrics.txt |
version: "3.8"
services:
app:
image: prom/prometheus-example-app
ports:
- "8080:8080"
pushgateway:
image: prom/pushgateway
ports:
- "9091:9091"
scraper:
build: .
environment:
SOURCE_URL: "http://app:8080/metrics"
PUSHGATEWAY_URL: "http://pushgateway:9091/metrics/job/example"
INTERVAL: "10"
SCRAPE_TIMEOUT: "3"
PUSH_TIMEOUT: "3"go mod init scraper
go mod tidy
go build -o scraper .or via Docker:
docker build -t scraper:latest .docker run --rm \
-e SOURCE_URL=http://app:8080/metrics \
-e PUSHGATEWAY_URL=http://user:pass@pushgateway:9091/metrics/job/test \
-e INTERVAL=10 \
-e SCRAPE_TIMEOUT=3 \
-e PUSH_TIMEOUT=3 \
scraper:latest[2025-11-03T15:22:11Z] pushed → http://pushgateway:9091/metrics/job/example (auth=true custom=my_custom_value=42.5)
- Basic Auth credentials can be set via URL or environment variables.
- Both HTTPS and plain HTTP are supported.
- On each cycle:
- The app scrapes metrics from
SOURCE_URL - Optionally adds a custom metric line
- Pushes the result to
PUSHGATEWAY_URL
- The app scrapes metrics from
- Logs are printed to stdout only.
GNU GENERAL PUBLIC LICENSE