Skip to content

Commit 6bc6e60

Browse files
committed
tetragon: Add map_errors_update_total/map_errors_delete_total metrics
Signed-off-by: Jiri Olsa <[email protected]>
1 parent b3a0a83 commit 6bc6e60

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

docs/content/en/docs/reference/metrics.md

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/metrics/mapmetrics/mapmetrics.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ var (
2626
"Capacity of a BPF map. Expected to be constant.",
2727
nil, []metrics.ConstrainedLabel{MapLabel}, nil,
2828
))
29-
MapErrors = metrics.MustNewCustomGauge(metrics.NewOpts(
30-
consts.MetricsNamespace, "", "map_errors_total",
31-
"The number of errors per map.",
29+
MapErrorsUpdate = metrics.MustNewCustomGauge(metrics.NewOpts(
30+
consts.MetricsNamespace, "", "map_errors_update_total",
31+
"The number of failed updates per map.",
32+
nil, []metrics.ConstrainedLabel{MapLabel}, nil,
33+
))
34+
MapErrorsDelete = metrics.MustNewCustomGauge(metrics.NewOpts(
35+
consts.MetricsNamespace, "", "map_errors_delete_total",
36+
"The number of failed deletes per map.",
3237
nil, []metrics.ConstrainedLabel{MapLabel}, nil,
3338
))
3439
)

pkg/observer/observer_stats.go

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func NewBPFCollector() metrics.CollectorWithInit {
2222
metrics.CustomMetrics{
2323
mapmetrics.MapSize,
2424
mapmetrics.MapCapacity,
25-
mapmetrics.MapErrors,
25+
mapmetrics.MapErrorsUpdate,
26+
mapmetrics.MapErrorsDelete,
2627
},
2728
collect,
2829
collectForDocs,
@@ -72,51 +73,40 @@ func collect(ch chan<- prometheus.Metric) {
7273
}
7374
defer mapLink.Close()
7475

75-
updateMapSize(ch, mapLinkStats, name)
7676
ch <- mapmetrics.MapCapacity.MustMetric(
7777
float64(mapLink.MaxEntries()),
7878
name,
7979
)
80-
updateMapErrors(ch, mapLinkStats, name)
80+
update(mapLinkStats, 0, func(sum float64) {
81+
ch <- mapmetrics.MapSize.MustMetric(sum, name)
82+
})
83+
update(mapLinkStats, 1, func(sum float64) {
84+
ch <- mapmetrics.MapErrorsUpdate.MustMetric(sum, name)
85+
})
86+
update(mapLinkStats, 2, func(sum float64) {
87+
ch <- mapmetrics.MapErrorsDelete.MustMetric(sum, name)
88+
})
8189
}
8290
}
8391

84-
func updateMapSize(ch chan<- prometheus.Metric, mapLinkStats *ebpf.Map, name string) {
92+
func update(mapLinkStats *ebpf.Map, key int32, update func(sum float64)) {
8593
var values []int64
86-
if err := mapLinkStats.Lookup(int32(0), &values); err != nil {
94+
if err := mapLinkStats.Lookup(key, &values); err != nil {
8795
return
8896
}
8997

9098
sum := int64(0)
9199
for _, n := range values {
92100
sum += n
93101
}
94-
ch <- mapmetrics.MapSize.MustMetric(
95-
float64(sum),
96-
name,
97-
)
98-
}
99-
100-
func updateMapErrors(ch chan<- prometheus.Metric, mapLinkStats *ebpf.Map, name string) {
101-
var values []int64
102-
if err := mapLinkStats.Lookup(int32(1), &values); err != nil {
103-
return
104-
}
105-
106-
sum := int64(0)
107-
for _, n := range values {
108-
sum += n
109-
}
110-
ch <- mapmetrics.MapErrors.MustMetric(
111-
float64(sum),
112-
name,
113-
)
102+
update(float64(sum))
114103
}
115104

116105
func collectForDocs(ch chan<- prometheus.Metric) {
117106
for _, m := range mapmetrics.MapLabel.Values {
118107
ch <- mapmetrics.MapSize.MustMetric(0, m)
119108
ch <- mapmetrics.MapCapacity.MustMetric(0, m)
120-
ch <- mapmetrics.MapErrors.MustMetric(0, m)
109+
ch <- mapmetrics.MapErrorsUpdate.MustMetric(0, m)
110+
ch <- mapmetrics.MapErrorsDelete.MustMetric(0, m)
121111
}
122112
}

0 commit comments

Comments
 (0)