-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mapmetrics: Define size and errors metrics as custom collectors
This commit reimplements two metrics: tetragon_map_in_use_gauge and tetragon_map_errors_total, so that they are exposed by custom Prometheus collectors. This means that metric values are read from BPF maps at the scrape time, without a need for a userland tickers. From the user perspective, the metrics are more accurate. Additionally, the errors metric is exposed as a counter instead of a gauge. Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
- Loading branch information
Showing
8 changed files
with
159 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Tetragon | ||
|
||
package eventcache | ||
|
||
import ( | ||
"github.com/cilium/tetragon/pkg/metrics/mapmetrics" | ||
"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() | ||
} | ||
|
||
func (c *bpfCollector) Collect(ch chan<- prometheus.Metric) { | ||
ec := Get() | ||
if ec != nil { | ||
ch <- mapmetrics.MapSize.MustMetric( | ||
float64(ec.len()), | ||
"eventcache", "0", | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Tetragon | ||
|
||
package process | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cilium/tetragon/pkg/metrics/mapmetrics" | ||
"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() | ||
} | ||
|
||
func (c *bpfCollector) Collect(ch chan<- prometheus.Metric) { | ||
if procCache != nil { | ||
ch <- mapmetrics.MapSize.MustMetric( | ||
float64(procCache.len()), | ||
"processLru", fmt.Sprint(procCache.size), | ||
) | ||
} | ||
} |