/
metrics.go
51 lines (43 loc) · 1.18 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Tetragon
package process
import (
"github.com/cilium/tetragon/pkg/metrics/consts"
"github.com/prometheus/client_golang/prometheus"
)
var ProcessCacheTotal = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: consts.MetricsNamespace,
Name: "process_cache_size",
Help: "The size of the process cache",
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())
}