Skip to content

Commit

Permalink
eventmetrics: 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 f927ca7 commit 50016fd
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/metrics/eventmetrics/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
package eventmetrics

import (
"fmt"
"path/filepath"
"strconv"

"github.com/cilium/ebpf"
"github.com/cilium/tetragon/pkg/api/ops"
"github.com/cilium/tetragon/pkg/api/processapi"
"github.com/cilium/tetragon/pkg/option"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -50,3 +52,28 @@ func (c *bpfCollector) Collect(ch chan<- prometheus.Metric) {
}
}
}

// 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) {
for opcode := range ops.OpCodeStrings {
if opcode != ops.MsgOpUndef && opcode != ops.MsgOpTest {
ch <- MissedEvents.MustMetric(0, fmt.Sprint(int32(opcode)))
}
}
}

0 comments on commit 50016fd

Please sign in to comment.