r/PrometheusMonitoring • • Jun 12 '26

promcap, cap metric cardinality in-process, before a runaway label OOMs your stack

13 Upvotes

A high-cardinality label is the classic way to take down a Prometheus stack: one metric accidentally labelled with a user ID, a full request path, or an attacker-controlled header quietly spawns hundreds of thousands of series until the scrape target, the TSDB, or both run out of memory.

The standard mitigations are all after-the-fact: metric_relabel_configs to drop labels, recording rules to collapse series, alerts on scrape_series_added or series growth. They work, but they fire once the cardinality is already being generated. You're reacting to a fire that's already lit.

I built promcap to enforce the ceiling at the other end, in-process, in the Go app emitting the metrics, at the moment the series would be created. It wraps the Prometheus CounterVec / GaugeVec / HistogramVec / SummaryVec types. Once a metric has emitted its configured number of distinct label combinations, every further combination collapses into a single __overflow__ series instead of minting a new one. The observations are still counted, just bucketed together, so dashboards keep working and the time-series count can't grow without bound.

What I think makes it useful for monitoring folks specifically:

  • It's observable. Every collapsed observation increments promcap_series_capped_total, labelled by metric name. So you get a direct signal of exactly which metric is shedding cardinality and how hard: rate(promcap_series_capped_total[5m]). That's effectively a "which of my metrics is misbehaving" alert built in.

  • Allowlists for closed sets. For labels whose valid values you know up front (status codes, a fixed set of regions, a handful of event kinds), Allow makes anything outside the list overflow the instant it appears, so a typo or an injected value never even starts filling the budget.

  • Overflow vs. eviction. Default behaviour freezes the admitted set once the cap is hit (the safe choice for adversarial or unbounded labels). For labels where the interesting set rotates over time, like active tenants or recently-seen hosts, Evict: true tracks the most-recent N combinations instead, using a clock/second-chance policy.

It's the cardinality equivalent of a rate limiter: a hard cap you set per metric so a single bad label can't blow up the registry, with a meta-metric telling you when and where it's kicking in.

Caveat for anyone evaluating it: CurryWith / Delete / DeleteLabelValues aren't wrapped yet, so it's not a full drop-in if your code relies on those.

Repo + docs: https://github.com/eben-vranken/promcap

Curious whether people would rather cap in-process like this, or keep all cardinality control at the relabel/recording-rule layer. Interested in how others are handling runaway labels today.


r/PrometheusMonitoring • • Mar 31 '25

Thanos or Mimir?

13 Upvotes

I know this might be a recurring question, but considering how fast applications evolve, a scenario today might have nothing to do with what it was three years ago.

I have a monitoring stack that receives remote-write metrics from about 30 clusters.
I've used both Thanos and Mimir, all running on Azure, and now I need to prepare a migration to Google Cloud...

What would you choose today?

Based on my experience, here’s what I’ve found:

  • Thanos has issues with the Compactor

  • Mimir has issues with the Ingester

Additionally, the goal is to optimize costs...


r/PrometheusMonitoring • • Jan 09 '25

kubezonnet: Monitor Cross-Zone Network Traffic in Kubernetes

Thumbnail
polarsignals.com
13 Upvotes

r/PrometheusMonitoring • • Jan 12 '23

Prometheus Weathermen - a weather data exporter

13 Upvotes

This could have been done with 20 lines of python, node exporter and a textfile but I finally found a good excuse to do some Rust for real so here it is, a weather data exporter written in Rust supporting a few APIs: https://github.com/lstrojny/prometheus-weathermen


r/PrometheusMonitoring • • Nov 23 '22

I wrote a program to monitor home routers and expose the metrics as a Prometheus endpoint. Maybe someone here can find this useful.

Thumbnail
gallery
13 Upvotes

r/PrometheusMonitoring • • Nov 07 '22

My Prometheus Day (KubeCon) talk is now online: Building a Runbook Automation System for Prometheus and Kubernetes

Thumbnail
youtube.com
13 Upvotes

r/PrometheusMonitoring • • Feb 24 '22

How to monitor Starlink with Prometheus

13 Upvotes

This was a fun project, Learn how to set up and monitor SpaceX Starlink using Prometheus!

https://sysdig.com/blog/monitor-starlink/


r/PrometheusMonitoring • • Oct 07 '21

Use Prometheus metrics to trigger a Kubernetes HPA

13 Upvotes

Our team just published this article on how easy it is to create a Kubernetes HPA with KEDA and use Prometheus metrics to trigger it.

Installing KEDA with Helm is pretty straight forward:

helm repo add kedacore https://kedacore.github.io/charts
helm repo update
kubectl create namespace keda
helm install keda kedacore/keda --namespace keda

KEDA will extend the Kubernetes API metrics endpoint for you, so creating a query to trigger the HPA is as easy as creating a ScaledObject like this:

    apiVersion: keda.sh/v1alpha1
    kind: ScaledObject
    metadata:
     name: nginx-scale
     namespace: keda-hpa
    spec:
     scaleTargetRef:
       kind: Deployment
       name: nginx-server
     minReplicaCount: 1
     maxReplicaCount: 5
     cooldownPeriod: 30
     pollingInterval: 1
     triggers:
     - type: prometheus
       metadata:
         serverAddress: https://prometheus_server/prometheus
         metricName: nginx_connections_waiting_keda
         query: |
           sum(nginx_connections_waiting{job="nginx"})
         threshold: "500"

You can read the whole story here. I hope you find this interesting!


r/PrometheusMonitoring • • Jul 25 '21

A series of articles on learning Prometheus and PromQL

Thumbnail
twitter.com
13 Upvotes

r/PrometheusMonitoring • • Jun 13 '21

Prometheus vector matching visualized

Thumbnail
twitter.com
13 Upvotes

r/PrometheusMonitoring • • Jun 11 '21

Learn How to Contribute to Prometheus with CoFounder Julius Volz

Thumbnail
m.twitch.tv
13 Upvotes

r/PrometheusMonitoring • • Apr 15 '21

Top 5 key metrics for monitoring AWS RDS - and download an already configured dashboard in just a few clicks

Thumbnail
sysdig.com
13 Upvotes

r/PrometheusMonitoring • • Mar 16 '21

Wrote an introductory guide to Prometheus. It clears concepts around Prometheus architecture, metrics, and it's most common use cases.

Thumbnail
infracloud.io
13 Upvotes

r/PrometheusMonitoring • • Nov 24 '20

Why Prometheus is better compared to other monitoring solutions like Zabbix or Nagios ?

13 Upvotes

r/PrometheusMonitoring • • Jun 29 '20

Using Letsencrypt with the node exporter

Thumbnail
robustperception.io
13 Upvotes

r/PrometheusMonitoring • • Jun 16 '20

GitHub Exporter with a focus on PR/Issue/Milestone metrics

Thumbnail
github.com
13 Upvotes

r/PrometheusMonitoring • • Jun 11 '20

Prometheus web exporter

Thumbnail
github.com
13 Upvotes

r/PrometheusMonitoring • • May 24 '20

Prometheus User Survey - May 2020

Thumbnail
docs.google.com
13 Upvotes

r/PrometheusMonitoring • • May 11 '20

New Features in Prometheus 2.18.0

Thumbnail
robustperception.io
13 Upvotes

r/PrometheusMonitoring • • Jan 19 '20

Prometheus Query Cli

Thumbnail
github.com
13 Upvotes

r/PrometheusMonitoring • • Nov 22 '19

Doing Things Prometheus Can’t Do with Prometheus [Slides]

Thumbnail static.sched.com
13 Upvotes

r/PrometheusMonitoring • • Jul 08 '19

Switching between Prometheus servers in Grafana using data source variables

Thumbnail
robustperception.io
13 Upvotes

r/PrometheusMonitoring • • May 28 '19

OpenMetrics

Thumbnail
medium.com
13 Upvotes

r/PrometheusMonitoring • • Apr 15 '19

New Features in Prometheus 2.9.0

Thumbnail
robustperception.io
13 Upvotes