diff --git a/docs/content/en/docs/reference/metrics.md b/docs/content/en/docs/reference/metrics.md index 0b45f27fd27..732995830fa 100644 --- a/docs/content/en/docs/reference/metrics.md +++ b/docs/content/en/docs/reference/metrics.md @@ -195,6 +195,10 @@ Policy filter metrics. For internal use only. | `op ` | `add, add-container, delete, update` | | `subsys` | `pod-handlers, rthooks` | +### `tetragon_process_cache_capacity` + +The capacity of the process cache. Expected to be constant. + ### `tetragon_process_cache_size` The size of the process cache diff --git a/pkg/process/metrics.go b/pkg/process/metrics.go index 9dc24d4df42..61425a8c4f8 100644 --- a/pkg/process/metrics.go +++ b/pkg/process/metrics.go @@ -15,6 +15,37 @@ var ProcessCacheTotal = prometheus.NewGauge(prometheus.GaugeOpts{ ConstLabels: nil, }) +type cacheCapacityMetric struct { + desc *prometheus.Desc +} + +func (m *cacheCapacityMetric) Describe(ch chan<- *prometheus.Desc) { + ch <- m.desc +} + +func (m *cacheCapacityMetric) Collect(ch chan<- prometheus.Metric) { + capacity := 0 + if procCache != nil { + capacity = procCache.size + } + ch <- prometheus.MustNewConstMetric( + m.desc, + prometheus.GaugeValue, + float64(capacity), + ) +} + +func NewCacheCollector() prometheus.Collector { + return &cacheCapacityMetric{ + prometheus.NewDesc( + prometheus.BuildFQName(consts.MetricsNamespace, "", "process_cache_capacity"), + "The capacity of the process cache. Expected to be constant.", + nil, nil, + ), + } +} + func InitMetrics(registry *prometheus.Registry) { registry.MustRegister(ProcessCacheTotal) + registry.MustRegister(NewCacheCollector()) }