Skip to main content

Prometheus exporter for Github rate-limits API

Project description

github-rate-limits-exporter

Charts CI PyPI version Python version license

Prometheus exporter to monitor the Github API rate-limits.

Github API Rate Limits - Grafana dashboard

Introduction

If you have ever tried using Github's API, you have probably already run into Github's rate limiting errors.
Without authorization, Github only allows 60 requests per hour (!!), and after creating and using your
own personal access token, you are upgraded to 5000 requests per hour.

That rate limit can be easily reached in just a few minutes by calling the API to list basic information from a medium
sized repository and you would have to wait 50+ minutes for the rate limit to reset in order to continue or try again.
You can up the rate limit to 15,000 with an enterprise account but the problem remains the same:

If your service/program needs to make consistent and/or sustained requests to Github's APIs,
you will have to work around and make the most of Github's rate limits.

So, the Prometheus Github rate-limits exporter was introduced to expose the remaining, used, limit
(quotas) and reset (rate-limit window resets in UTC seconds) information per Github API as metrics in order
to create alerting events and (Grafana) monitoring dashboards.

For the exporter to fetch and expose the Github API rate-limits, you need to supply:

As standalone Python command line tool (pypi)

Install the tool through pypi:

pip3 install github-rate-limits-exporter
./github-rate-limits-exporter --help

Tox (wrapper)

Clone the repository and install tox:

pip install --user tox

Run as PAT Github authentication type

tox -e run-exporter -- \
  --github-auth-type pat \
  --github-account my_account_name \
  --github-token my_token

Run as APP (Github App) Github authentication type

tox -e run-exporter -- \
  --github-auth-type app \
  --github-account my_account_name \
  --github-app-id my_app_id \
  --github-app-installation-id my_installation_id \
  --github-app-private-key-path /path/to/private_key.pem

Docker

Clone the repositroy and build the docker container image:

docker build -t prometheus-gh-rate-limit-exporter:latest .

or pull directly from Docker Hub:

docker pull theodore86/prometheus-gh-rate-limit-exporter:latest

Run as PAT Github authentication type

docker run -p 10050:10050 -d \
  --name gh-rl-exporter \
  --restart on-failure \
  -e GITHUB_ACCOUNT=my_account_name \
  -e GITHUB_AUTH_TYPE=pat \
  -e GITHUB_TOKEN=my_token \
  -e EXPORTER_LOG_LEVEL=4 \
  prometheus-gh-rate-limit-exporter:latest

Run as APP (Github App) Github authentication type

docker run -p 10050:10050 -d \
  --name gh-rl-exporter \
  --restart on-failure \
  -e GITHUB_AUTH_TYPE=app \
  -e GITHUB_ACCOUNT=my_account_name \
  -e GITHUB_APP_ID=111111 \
  -e GITHUB_APP_INSTALLATION_ID=22222222 \
  -e GITHUB_APP_PRIVATE_KEY_PATH=/app/key.pem \
  -e EXPORTER_LOG_LEVEL=4 \
  --mount type=bind,source=/ws/key.pem,target=/app/key.pem,readonly \
  prometheus-gh-rate-limit-exporter:latest

Docker-Compose

Another way to test and observe the exporter is through the Prometheus/Grafana/AlertManager
stack on top of the docker-compose:

Clone the repository and install tox tool:

pip install --user tox

Run as PAT Github authentication type

export GITHUB_AUTH_TYPE=pat
export GITHUB_TOKEN=your_token
export GITHUB_ACCOUNT=your_account
export EXPORTER_LOG_LEVEL=4
export GF_SECURITY_ADMIN_USER=username
export GF_SECURITY_PASSWORD=password
tox -e dc-run

Run as APP (Github App) authentication type

export GITHUB_ACCOUNT=your_account
export GITHUB_AUTH_TYPE=app
export GITHUB_APP_ID=12345
export GITHUB_APP_INSTALLATION_ID=123456
export GITHUB_APP_SRC_PRIVATE_KEY_PATH=/ws/private_key.pem
export GITHUB_APP_PRIVATE_KEY_PATH=/tmp/private_key.pem
export EXPORTER_LOG_LEVEL=4
export GF_SECURITY_ADMIN_USER=username
export GF_SECURITY_PASSWORD=password
tox -e dc-run

Connect to Portainer management UI

  • Portainer (credentials: admin/adminpassword)

Connect to Prometheus, Grafana and AlertManager

See also the existing examples:

Cleanup/teardown the composed services

tox -e dc-clean

Kubernetes - Helm chart

This helm chart helps to install and configure github-rate-limits exporter on Kubernetes clusters.

In order to try out (locally) the charts

curl -fsSL https://get.jetify.com/devbox | bash
  • Create the cluster:
cd kubernetes; devbox run start-cluster
  • Adjust the environment file (.env):
vim .env
  • Bring up the github-rate-limits exporter and the Kubernetes Prometheus stack:
devbox run --env-file .env start-monitor

Cleanup/teardown the workloads

devbox run --env-file .env stop-monitor
devbox run stop-cluster

Other Projects

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

github_rate_limits_exporter-0.7.6-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file github_rate_limits_exporter-0.7.6-py3-none-any.whl.

File metadata

File hashes

Hashes for github_rate_limits_exporter-0.7.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e762b3404d8bd7c3cd017c6706dd122e6a3216c0d5d347b12baeb36b2e004f0c
MD5 c417b1e41f0fd92ecc21430193e57489
BLAKE2b-256 c5440179cc140baaeecbab7087926a583f84ef0a927f4ebb8f9fb8c19bbedc4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page