https://github.com/eidam/cf-workers-prometheus-push-gateway
A simple Prometheus (aggregated) push gateway allowing stateless/serverless workloads, ephemeral and batch jobs to easily expose their metrics.
https://github.com/eidam/cf-workers-prometheus-push-gateway
cloudflare-workers durable-objects prometheus prometheus-metrics prometheus-push-gateway push-gateway workers
Last synced: 2 months ago
JSON representation
A simple Prometheus (aggregated) push gateway allowing stateless/serverless workloads, ephemeral and batch jobs to easily expose their metrics.
- Host: GitHub
- URL: https://github.com/eidam/cf-workers-prometheus-push-gateway
- Owner: eidam
- License: mit
- Created: 2022-01-22T21:06:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-05-18T10:27:38.000Z (about 4 years ago)
- Last Synced: 2026-02-07T15:58:40.870Z (4 months ago)
- Topics: cloudflare-workers, durable-objects, prometheus, prometheus-metrics, prometheus-push-gateway, push-gateway, workers
- Language: JavaScript
- Homepage:
- Size: 1.4 MB
- Stars: 25
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Serverless Prometheus (aggregated) Push Gateway
A simple Prometheus _(aggregated)_ push gateway allowing stateless/serverless workloads, ephemeral and batch jobs to easily expose their metrics. Aggregated metrics are exposed via `/metrics` endpoint and optionally pushed to a remote Prometheus instance.
Powered by [Cloudflare Workers](https://workers.cloudflare.com/), [Durable Objects](https://developers.cloudflare.com/workers/learning/using-durable-objects), and [CRON Triggers](https://developers.cloudflare.com/workers/platform/cron-triggers).

## Features
- **Simple PATCH counter** - no need for a client libraries for a counter metric, just send `PATCH /metrics/:metricName?label1=value1&label2=value2` to increment its value.
- **Aggregated metrics** - received values are added up to the current (label matching) metrics. All metrics exposed on `GET /metrics`.
- **Automatic push to a remote prometheus server** - metrics are (optionally) pushed to a `remote_write` prometheus endpoint on each CRON Trigger execution. See [Grafana Cloud](https://grafana.com/products/cloud/features/#cloud-metrics) _(generous free tier)_ for a managed Prometheus with Grafana.
## Deployment
Cloudflare Account with Paid Workers is needed.
1. `yarn`
1. `yarn deploy`
1. `(optional)` add following secrets _(either via Cloudflare Dashboard or with `npx wrangler@beta secret put`)_
- `SECRET_PROM_ENDPOINT` (e.g. `https://prometheus-us-central1.grafana.net/api/prom/push`)
- `SECRET_PROM_USER` (e.g. 23333)
- `SECRET_PROM_TOKEN` (e.g. xxyy)
## Send metrics
There are a couple of easy ways to push your metrics, the `POST /metrics` endpoint is compatible with any prometheus client library configured to use it as a push gateway.
In case Cloudflare Workers are the only clients, its recommended to deploy this Workers with no routes attached to it and use Service bindings.
1. `POST /metrics` - accepts [prometheus text-based format](https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format).
2. `PATCH /metrics/:metricName?label1=value1&label2=value2` - simplified counter increments that works well with no libraries needed.
### Examples
**curl**
1. Send curl
```
curl -x PATCH https://worker.example.com/metrics/metric_name?foo=bar
```
1. Send `POST` request with body in [prometheus text-based format](https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format)
```bash
cat <