Skip to content

Commit

Permalink
process: Add a metric for process cache capacity
Browse files Browse the repository at this point in the history
tetragon_process_cache_capacity exposes the capacity of the process cache. It's
useful to be used together with tetragon_process_cache_size to monitor the
process cache utilization.

Signed-off-by: Anna Kapuscinska <[email protected]>
  • Loading branch information
lambdanis committed Apr 11, 2024
1 parent 870f92c commit 2762272
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/content/en/docs/reference/metrics.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions pkg/process/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit 2762272

Please sign in to comment.