diff --git a/docs/content/en/docs/reference/metrics.md b/docs/content/en/docs/reference/metrics.md index bec127bc64b..0314a205809 100644 --- a/docs/content/en/docs/reference/metrics.md +++ b/docs/content/en/docs/reference/metrics.md @@ -287,6 +287,14 @@ Process Loader event statistics. For internal use only. | ----- | ------ | | `count` | `LoaderReceived, LoaderResolvedImm, LoaderResolvedRetry` | +### `tetragon_tracingpolicy_kernel_memory_bytes` + +The amount of kernel memory in bytes used by policy's sensors non-shared BPF maps (memlock). + +| label | values | +| ----- | ------ | +| `policy` | `example-policy` | + ### `tetragon_tracingpolicy_loaded` The number of loaded tracing policy by state. diff --git a/pkg/metrics/policymetrics/policymetrics.go b/pkg/metrics/policymetrics/policymetrics.go index 961c3ca22b7..378c357bff0 100644 --- a/pkg/metrics/policymetrics/policymetrics.go +++ b/pkg/metrics/policymetrics/policymetrics.go @@ -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, @@ -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( @@ -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") }