Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kha7iq/drl-exporter

Prometheus exporter for dockerhub rate limits
https://github.com/kha7iq/drl-exporter

docker dockerhub-rate-limit golang grafana helm-chart helm-charts prometheus prometheus-exporter

Last synced: about 2 months ago
JSON representation

Prometheus exporter for dockerhub rate limits

Awesome Lists containing this project

README

        




Dockerhub rate limit prometheus metrics exporter



Docker Image Size (latest by date)

Docker Image Version (latest by date)

Docker Pulls

License

GitHub issues


About
Usage
Image Configuration
Local Demo
Helm Chart
Todo
Issues
Acknowledgment

---

## About

This exporter allows to retrieve the DockerHub rate limit counts as scrape target for Prometheus.
The exporter obtains an auth token and then queries the Docker Hub registry with a HEAD request to parse RateLimit-Limit,
RateLimit-Remaining and RateLimit-Reset into a Gauge metric.
You can use your Docker Hub credentials to authenticate, otherwise an anonymous token is used.

## Screenshot

## Usage
Multi Arch docker images are available (arm64/amd64) you can pull it from dockerhub/github and run in your environment.

## Docker

```bash
#
docker pull khaliq/drl-exporter:latest
docker pull ghcr.io/kha7iq/drl-exporter:latest

# ARM
docker pull ghcr.io/kha7iq/drl-exporter:v2.1.3-arm64
docker pull khaliq/drl-exporter:v2.1.3-arm64

docker run -d -p 2121:2121 khaliq/drl-exporter:latest

curl localhost:2121/metrics
```

## Kubernetes

1. Add chart repository
```
helm repo add tektonops http://charts.tektonops.com
helm repo update
```
2. Install the chart
```
helm install drl-exporter tektonops/drl-exporter
```

### Installing the Chart with Username and Password
Customize the chart by setting values at runtime or in the `values.yaml` file.

To use the exporter with a username and password, ensure `enableUserAuth=true` is set.

Refer to the [chart repository](https://github.com/kha7iq/charts/tree/main/charts/drl-exporter) for all configuration options.

```bash
helm install drl-exporter tektonops/drl-exporter \
--set exporter.auth.enabled=true \
--set exporter.auth.dockerHubUsername= \
--set exporter.auth.dockerHubPassword=
```

### Output
```text
# HELP dockerhub_limit_max_requests_time Dockerhub rate limit maximum requests total time seconds
# TYPE dockerhub_limit_max_requests_time gauge
dockerhub_limit_max_requests_time 21600{reqsource="10.50.00.0"}
# HELP dockerhub_limit_max_requests_total Dockerhub rate limit maximum requests in given time
# TYPE dockerhub_limit_max_requests_total gauge
dockerhub_limit_max_requests_total 100{reqsource="10.50.00.0"}
# HELP dockerhub_limit_remaining_requests_time Dockerhub rate limit remaining requests time seconds
# TYPE dockerhub_limit_remaining_requests_time gauge
dockerhub_limit_remaining_requests_time 21600{reqsource="10.50.00.0"}
# HELP dockerhub_limit_remaining_requests_total Dockerhub rate limit remaining requests in given time
# TYPE dockerhub_limit_remaining_requests_total gauge
dockerhub_limit_remaining_requests_total 99{reqsource="10.50.00.0"}
```

## Configuration Variables

| Variables | Default Value | Description |
| -------------------------- | :----------------: | :-------------: |
| EXPORTER_PORT | 2121 | Server listening port |
| ENABLE_USER_AUTH | false️ | **Must** be set to **true** if providing username |
| DOCKERHUB_USER | "" | Dockerhub account |
| DOCKERHUB_PASSWORD | "" | Account password |
| DOCKERHUB_REPO_IMAGE | ratelimitpreview/test | custom repository/image |
| ENABLE_FILE_AUTH | false | Load auth credentials from docker config file
at /$FILE_AUTH_DIR/config.json
Must leave auth through ENV empty. |
| FILE_AUTH_DIR | /config | Directory where config.json resides |
| ENABLE_IPV6 | false | Use IPv6 instead of IPv4 when fetching rate limits |
| REQUEST_INTERVAL | 15 | Specify the interval in seconds at which requests should be sent to Dockerhub |

Example docker configuration config.json file below.

Note that a more extensive configuration can be handled, as long as at least an 'auths' exists for `https://index.docker.io/v1/`, with a username and password.
```
{
"auths": {
"https://index.docker.io/v1/": {
"username": "MyUsername",
"password": "MyPasswordOrToken"
}
}
}
```

- To build the image in your local environment
```bash
git clone https://github.com/kha7iq/drl-exporter.git
cd drl-exporter
make docker
```

## Local Demo
You can find the complete docker-compose file along with a dashboard under deploy folder to test it out.

```bash
cd deploy/docker-compose
docker-compose up -d
```

## Web UI
Web | URL
-------------|-------------
Grafana | http://localhost:3000
Prometheus | http://localhost:9090
Exporter | http://localhost:8881


## TODO
- [x] Tests
- [x] Helm Chart

## Issues
Please open an issue if you are facing any problems.

## Acknowledgments
This project is inspired by [Michael Friedrich's](https://gitlab.com/dnsmichi) amazing work.