PromCache is a caching proxy for Prometheus that reduces load on your Prometheus servers by caching query results. It sits between clients and Prometheus, serving cached responses when available and proxying requests to the upstream Prometheus server when needed.
While PromCache could be used to cache any HTTP API, it is specifically designed for Prometheus API endpoints. It intelligently normalizes query parameters to improve cache hit rates and provides configurable TTL-based caching.
PromCache works best with GET requests, as it caches the full response based on the URL and query parameters. It is not designed for caching POST requests or other HTTP methods.
- Transparent HTTP proxy for Prometheus API endpoints
- Configurable TTL-based caching for query results
- Cache hit/miss metrics
- Intelligent query parameter normalization for better cache hit rates
- Docker support with health checks
- Low memory footprint
go install github.com/f0o/promcache/cmd/promcached@latestdocker build -t promcache .
docker run -p 9091:9091 -e PROMCACHE_UPSTREAM_URL=http://prometheus:9090 promcachePromCache can be configured using command-line flags or environment variables:
| Flag | Environment Variable | Default | Description |
|---|---|---|---|
-listen |
PROMCACHE_LISTEN_ADDR |
:9091 |
Address to listen on |
-upstream |
PROMCACHE_UPSTREAM_URL |
http://localhost:9090 |
Prometheus upstream URL |
-ttl |
PROMCACHE_TTL |
5m |
Cache TTL duration |
-log-level |
PROMCACHE_LOG_LEVEL |
info |
Log level (debug, info, warn, error) |
/api/*- Proxied Prometheus API endpoints with caching/metrics- Prometheus metrics about the cache performance/health- Health check endpoint/debug/cache- Cache inspection endpoint (for debugging)
The following metrics are exposed at the /metrics endpoint:
promcache_cache_hits_total- Total number of cache hitspromcache_cache_misses_total- Total number of cache missespromcache_upstream_request_duration_seconds- Histogram of upstream request latenciespromcache_cache_size- Current number of items in the cache
- Go 1.23 or later
- Docker (optional)
git clone https://github.com/f0o/promcache.git
cd promcache
go build -o promcached ./cmd/promcachedgo test ./...This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) - see the LICENSE file for details.