A lightweight, bash-based Prometheus exporter for GitHub repository release download statistics. This exporter uses only bash, curl, jq, and socat to provide comprehensive download metrics for monitoring with Prometheus and Grafana.
- Pure Bash Implementation: No external dependencies except
socat,curl, andjq - Repository-Level Metrics: Exports GitHub download statistics including:
- Total download counts per repository
- Repository release and asset counts
- GitHub API rate limit status
- Regex-Based Asset Filtering: Filter assets using regular expressions
- Multi-Repository Monitoring: Monitor multiple specified repositories simultaneously
- HTTP Server: Built-in HTTP server using socat for serving metrics
- Rate Limiting: Configurable delays between API calls to avoid rate limits
- Systemd Integration: Ready-to-use systemd service file
- GitHub Enterprise Support: Works with GitHub Enterprise instances
- GitHub account or organization to monitor
socatpackage installedcurlandjqpackages installed- GitHub API token (optional but recommended for higher rate limits)
- Prometheus server for scraping metrics
- Clone the repository:
git clone https://github.com/itefixnet/prometheus-github-downloads-exporter.git
cd prometheus-github-downloads-exporter- Configure the exporter:
# Edit config.sh or set environment variables
export GITHUB_REPOS="account/repo1,account/repo2" # Comma-separated list
export GITHUB_TOKEN="your-github-token" # Optional but recommended- Test the exporter:
./github-downloads-exporter.sh test- Start the HTTP server:
./http-server.sh start- Access metrics at
http://localhost:9168/metrics
For production deployment, install as a system service:
# Create user and directories
sudo useradd -r -s /bin/false github-downloads-exporter
sudo mkdir -p /opt/github-downloads-exporter
# Copy files
sudo cp *.sh /opt/github-downloads-exporter/
sudo cp config.sh /opt/github-downloads-exporter/
sudo cp github-downloads-exporter.conf /opt/github-downloads-exporter/
sudo cp github-downloads-exporter.service /etc/systemd/system/
# Set permissions
sudo chown -R github-downloads-exporter:github-downloads-exporter /opt/github-downloads-exporter
sudo chmod +x /opt/github-downloads-exporter/*.sh
# Enable and start service
sudo systemctl daemon-reload
sudo systemctl enable github-downloads-exporter
sudo systemctl start github-downloads-exporterThe exporter can be configured using environment variables or configuration files:
| Variable | Default | Description |
|---|---|---|
GITHUB_TOKEN |
(none) | GitHub API token (strongly recommended) |
GITHUB_REPOS |
(required) | Comma-separated list of repositories (format: account/repo) |
GITHUB_API_URL |
https://api.github.com |
GitHub API URL (for Enterprise) |
RELEASE_REGEX |
.* |
Regex to filter releases |
ASSET_REGEX |
.* |
Regex to filter assets |
LISTEN_PORT |
9168 |
HTTP server port |
LISTEN_ADDRESS |
0.0.0.0 |
HTTP server bind address |
METRICS_PREFIX |
github_downloads |
Prometheus metrics prefix |
RATE_LIMIT_DELAY |
0.2 |
Delay between API calls in seconds |
MAX_PROCESSING_TIME |
60 |
Maximum processing time in seconds |
config.sh: Shell configuration file (sourced by scripts)github-downloads-exporter.conf: Systemd environment file
While not required, using a GitHub token is strongly recommended to increase API rate limits:
- Go to GitHub Settings → Developer settings → Personal access tokens
- Generate a new token with
public_reposcope (orrepofor private repositories) - Set the token:
export GITHUB_TOKEN="your-token-here"
The exporter provides the following Prometheus metrics:
github_downloads_repository_downloads_total{repository="account/repo"}- Total downloads per repository (counter)github_downloads_repository_releases_count{repository="account/repo"}- Number of releases per repository (gauge)github_downloads_repository_assets_count{repository="account/repo"}- Number of assets per repository (gauge)
github_downloads_total_downloads- Total downloads across all monitored repositories (counter)github_downloads_total_releases- Total number of releases across all repositories (gauge)github_downloads_total_assets- Total number of assets across all repositories (gauge)
github_downloads_api_rate_limit- GitHub API rate limit (gauge)github_downloads_api_rate_remaining- Remaining API calls (gauge)github_downloads_api_rate_reset_timestamp- Rate limit reset timestamp (gauge)
github_downloads_scrape_duration_seconds- Time spent scraping GitHub API (gauge)github_downloads_scrape_timestamp- Timestamp of last successful scrape (gauge)
export GITHUB_REPOS="prometheus/prometheus"
./github-downloads-exporter.sh collectexport GITHUB_REPOS="prometheus/prometheus,grafana/grafana,kubernetes/kubernetes"
./github-downloads-exporter.sh collect# Monitor specific repositories with release filtering
export GITHUB_REPOS="prometheus/prometheus,grafana/grafana"
# Monitor only stable releases (no pre-releases)
export RELEASE_REGEX="^v?[0-9]+\.[0-9]+\.[0-9]+$"
# Monitor only binary assets
export ASSET_REGEX="\.(tar\.gz|zip|deb|rpm|exe)$"
./github-downloads-exporter.sh collect# Test connection
./github-downloads-exporter.sh test
# Collect metrics once
./github-downloads-exporter.sh collect
# Start HTTP server manually
./http-server.sh start
# Test HTTP endpoints
curl http://localhost:9168/metrics
curl http://localhost:9168/health
curl http://localhost:9168/Add to your prometheus.yml:
scrape_configs:
- job_name: 'github-downloads-exporter'
static_configs:
- targets: ['localhost:9168']
scrape_interval: 5m # GitHub data doesn't change frequently
scrape_timeout: 60s # API calls can take time
metrics_path: /metrics
# Multiple instances
- job_name: 'github-downloads'
static_configs:
- targets: ['server1:9168', 'server2:9168']
labels:
environment: 'production'
scrape_interval: 5mThe repository includes a Grafana dashboard (grafana-dashboard.json) with the following features:
Core Visualizations:
- Total Downloads: Overall download trends across all repositories
- Top Repositories: Bar chart showing most popular repositories by downloads
- Repository Statistics: Complete overview table with download counts, releases, and assets
Monitoring & Health:
- GitHub API Rate Limits: Current usage and remaining quota
- Scrape Performance: Exporter performance metrics (duration and timestamp)
- Download Trends: Time-series graphs showing download growth
Interactive Features:
- Instance Filter: Monitor multiple exporter instances
- Repository Filter: Focus on specific repositories
- Time Range Selection: Analyze trends over different periods
Installation:
- Import
grafana-dashboard.jsoninto your Grafana instance - Configure the Prometheus datasource
- Use the template variables to filter data as needed
-
Rate Limit Exceeded:
- Add a GitHub token:
export GITHUB_TOKEN="your-token" - Increase
RATE_LIMIT_DELAYorCACHE_TTL - Monitor rate limit metrics
- Add a GitHub token:
-
API Connection Failed:
- Check internet connectivity
- Verify GitHub account exists
- Test manually:
curl https://api.github.com/users/ACCOUNT
-
No Data Returned:
- Verify repositories exist and have releases
- Check that
GITHUB_REPOSis correctly formatted (account/repo) - Check regex patterns aren't too restrictive
- Ensure repositories are public (or token has access to private repos)
-
Missing Dependencies:
# Install on Ubuntu/Debian sudo apt-get install socat curl jq # Install on CentOS/RHEL sudo yum install socat curl jq
- Service logs:
journalctl -u github-downloads-exporter -f - Manual logs: Scripts output to stderr
- Enable debug:
LOG_LEVEL=debug
For high-frequency monitoring:
- Adjust
RATE_LIMIT_DELAYbased on your rate limits (default: 0.2 seconds) - Set
MAX_PROCESSING_TIMEappropriately for your number of repositories - Monitor fewer repositories per instance if experiencing timeouts
- Consider running multiple exporter instances for different repository sets
- Use longer Prometheus scrape intervals (5-15 minutes) since GitHub data doesn't change frequently
# Run basic tests
./github-downloads-exporter.sh test
./http-server.sh test
# Test with different configurations
GITHUB_ACCOUNT=prometheus ./github-downloads-exporter.sh test- Fork the repository
- Create a feature branch
- Test thoroughly with different GitHub accounts/repositories
- Submit a pull request
This project is licensed under the BSD 2-Clause License - see the LICENSE file for details.
- GitHub Issues: https://github.com/itefixnet/prometheus-github-downloads-exporter/issues
- Documentation: This README and inline script comments
This exporter is particularly useful for:
- Open Source Projects: Track adoption through download metrics
- Release Management: Monitor which versions are most popular
- Asset Performance: Understand which package formats are preferred
- Growth Tracking: Measure project growth over time
- Release Strategy: Optimize release cadence based on download patterns
For more advanced features or different languages, consider:
- GitHub API directly with custom scripts
- Grafana GitHub datasource plugin
- Custom Prometheus collectors in Go/Python
