Skip to content

Commit

Permalink
observer: Define bpfZeroCollector
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Kapuscinska <[email protected]>
  • Loading branch information
lambdanis committed Feb 28, 2024
1 parent 14a8cc9 commit f927ca7
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/observer/observer_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,40 @@ func updateMapErrors(ch chan<- prometheus.Metric, mapLinkStats *ebpf.Map, name s
name,
)
}

// bpfZeroCollector implements prometheus.Collector. It collects "zero" metrics.
// It's intended to be used when BPF metrics are not collected, but we still want
// Prometheus metrics to be exposed.
type bpfZeroCollector struct {
bpfCollector
}

func NewBPFZeroCollector() prometheus.Collector {
return &bpfZeroCollector{
bpfCollector: bpfCollector{},
}
}

func (c *bpfZeroCollector) Describe(ch chan<- *prometheus.Desc) {
c.bpfCollector.Describe(ch)
}

func (c *bpfZeroCollector) Collect(ch chan<- prometheus.Metric) {
// This list should contain all monitored maps.
// These are not maps from which metrics are read in the "real" collector -
// the metrics are stored in separate maps suffixed with "_stats".
monitoredMaps := []string{
"execve_map",
"tg_execve_joined_info_map",
}
for _, m := range monitoredMaps {
ch <- mapmetrics.MapSize.MustMetric(
0,
m, fmt.Sprint(0),
)
ch <- mapmetrics.MapErrors.MustMetric(
0,
m,
)
}
}

0 comments on commit f927ca7

Please sign in to comment.