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.

```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.0-arm64
docker pull khaliq/drl-exporter:v2.1.0-arm64

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

curl localhost:2121/metrics
```
### 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"}
```


To build the image in your local environment

```bash
git clone https://github.com/kha7iq/drl-exporter.git
cd drl-exporter
make docker
```

## 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 |

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"
}
}
}
```
## 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


## Helm Chart

1. `git clone https://github.com/kha7iq/drl-exporter.git`
2. `cd drl-exporter`
3. `helm install deploy/chart --namespace=`

### Installing chart with username and password
You can tweak the options for chart by setting values at run time or `values.yaml` file.
If you intend to use the exporter with a username and password do remember to set the `enableUserAuth=true` as well.

```bash
helm install my-release deploy/chart --set config.dockerhubUsername=,
config.dockerhubPassword=,config.enableUserAuth=true --namespace=
```
## Chart Configuration

| Parameter | Description | Default |
|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------|---------------------------|
| `config.exporterPort` | Port the deployment exposes | `2121` |
| `config.enableUserAuth` | Enable metrics for specific dockerhub account | `false` |
| `config.dockerhubUsername` | Dockerhub Username | `""` |
| `config.dockerhubPassword` | Dockerhub Password | `nil` |
| `config.enableFileAuth` | Enable authentication through k8s secret, type `kubernetes.io/dockerconfigjson`. Only effective if enableUserAuth is false. | `false` |
| `config.fileAuthDir` | Path to mount the config.json in the pod. Only effective if enableFileAuth is true. | `/config` |
| `config.fileAuthSecretName` | Name of existing k8s `kubernetes.io/dockerconfigjson` secret to use. Only effective if enableFileAuth is true. | `dockerhub` |
| `serviceMonitor.enabled` | If true, creates a ServiceMonitor instance | `false` |
| `serviceMonitor.additionalLabels` | Configure additional labels for the servicemonitor | `{}` |
| `serviceMonitor.namespace` | The namespace into which the servicemonitor is deployed. | `same as chart namespace` |
| `serviceMonitor.interval` | The interval with which prometheus will scrape | `30s` |
| `serviceMonitor.scrapeTimeout` | The timeout for the scrape request | `10s` |

## 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.

Helm chart is based on [viadee's](https://github.com/viadee/docker-hub-rate-limit-exporter) helm chart.