Skip to content

Commit

Permalink
pkg/metrics: add metrics for policy kernel memory use
Browse files Browse the repository at this point in the history
Similarly to TracingPolicy state, you can retrieve this information
through the gRPC API by listing the policies or using the metrics
interface.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
  • Loading branch information
mtardy committed Oct 8, 2024
1 parent 4db64e5 commit 30c69ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/content/en/docs/reference/metrics.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pkg/metrics/policymetrics/policymetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ var policyState = metrics.MustNewCustomGauge(metrics.NewOpts(
nil, []metrics.ConstrainedLabel{stateLabel}, nil,
))

var policyKernelMemory = metrics.MustNewCustomGauge(metrics.NewOpts(
consts.MetricsNamespace, "", "tracingpolicy_kernel_memory_bytes",
"The amount of kernel memory in bytes used by policy's sensors non-shared BPF maps (memlock).",
nil, nil, []metrics.UnconstrainedLabel{{Name: "policy", ExampleValue: "example-policy"}},
))

// This metric collector converts the output of ListTracingPolicies into a few
// gauges metrics on collection. Thus, it needs a sensor manager to query.
func NewPolicyCollector() metrics.CollectorWithInit {
return metrics.NewCustomCollector(
metrics.CustomMetrics{
policyState,
policyKernelMemory,
},
collect,
collectForDocs,
Expand All @@ -63,6 +70,7 @@ func collect(ch chan<- prometheus.Metric) {
for _, policy := range list.Policies {
state := policy.State
counters[state]++
ch <- policyKernelMemory.MustMetric(float64(policy.KernelMemoryBytes), policy.Name)
}

ch <- policyState.MustMetric(
Expand All @@ -87,4 +95,5 @@ func collectForDocs(ch chan<- prometheus.Metric) {
for _, state := range stateLabel.Values {
ch <- policyState.MustMetric(0, state)
}
ch <- policyKernelMemory.MustMetric(0, "example-policy")
}

0 comments on commit 30c69ba

Please sign in to comment.