Skip to content

Commit

Permalink
metrics: Replace tetragon_map_in_use_gauge{map="processLru"}
Browse files Browse the repository at this point in the history
Replace tetragon_map_in_use_gauge{map="processLru"} with
tetragon_process_cache_size. It's reporting the process cache size. Using the
map size metric for this purpose was confusing, as process cache is not a BPF
map.

Co-authored-by: sadath-12 <[email protected]>
Signed-off-by: sadath-12 <[email protected]>
Signed-off-by: Anna Kapuscinska <[email protected]>
  • Loading branch information
lambdanis and sadath-12 committed Mar 1, 2024
1 parent eb63488 commit e34fcec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
2 changes: 0 additions & 2 deletions pkg/metrics/metricsconfig/initmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/cilium/tetragon/pkg/metrics/syscallmetrics"
"github.com/cilium/tetragon/pkg/metrics/watchermetrics"
"github.com/cilium/tetragon/pkg/observer"
"github.com/cilium/tetragon/pkg/process"
"github.com/cilium/tetragon/pkg/version"
grpcmetrics "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -48,7 +47,6 @@ func InitAllMetrics(registry *prometheus.Registry) {
// register BPF collectors
registry.MustRegister(mapmetrics.NewBPFCollector(
observer.NewBPFCollector(),
process.NewBPFCollector(),
))
registry.MustRegister(eventmetrics.NewBPFCollector())

Expand Down
29 changes: 9 additions & 20 deletions pkg/process/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,17 @@
package process

import (
"fmt"

"github.com/cilium/tetragon/pkg/metrics/mapmetrics"
"github.com/cilium/tetragon/pkg/metrics/consts"
"github.com/prometheus/client_golang/prometheus"
)

// bpfCollector implements prometheus.Collector. It collects metrics directly from BPF maps.
type bpfCollector struct{}

func NewBPFCollector() prometheus.Collector {
return &bpfCollector{}
}

func (c *bpfCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- mapmetrics.MapSize.Desc()
}
var ProcessCacheTotal = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: consts.MetricsNamespace,
Name: "process_cache_size",
Help: "The size of the process cache",
ConstLabels: nil,
})

func (c *bpfCollector) Collect(ch chan<- prometheus.Metric) {
if procCache != nil {
ch <- mapmetrics.MapSize.MustMetric(
float64(procCache.len()),
"processLru", fmt.Sprint(procCache.size),
)
}
func InitMetrics(registry *prometheus.Registry) {
registry.MustRegister(ProcessCacheTotal)
}
3 changes: 3 additions & 0 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func InitCache(w watcher.K8sResourceWatcher, size int) error {
func FreeCache() {
procCache.Purge()
procCache = nil
ProcessCacheTotal.Set(0)
}

// GetProcessCopy() duplicates tetragon.Process and returns it
Expand Down Expand Up @@ -462,6 +463,7 @@ func AddExecEvent(event *tetragonAPI.MsgExecveEventUnix) *ProcessInternal {
}

procCache.add(proc)
ProcessCacheTotal.Inc()
return proc
}

Expand All @@ -485,6 +487,7 @@ func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) error {

parent.RefInc()
procCache.add(proc)
ProcessCacheTotal.Inc()
return nil
}

Expand Down

0 comments on commit e34fcec

Please sign in to comment.