diff --git a/docs/content/en/docs/reference/metrics.md b/docs/content/en/docs/reference/metrics.md index b3b750fc593..067247b0ec5 100644 --- a/docs/content/en/docs/reference/metrics.md +++ b/docs/content/en/docs/reference/metrics.md @@ -275,6 +275,10 @@ The number of loaded tracing policy by state. | ----- | ------ | | `state` | `disabled, enabled, error, load_error` | +### `tetragon_watcher_delete_pod_cache_hits` + +The total hits for pod information in the deleted pod cache. + ### `tetragon_watcher_errors_total` The total number of errors for a given watcher type. diff --git a/pkg/metrics/watchermetrics/watchermetrics.go b/pkg/metrics/watchermetrics/watchermetrics.go index b5745a97410..e2be6b1c796 100644 --- a/pkg/metrics/watchermetrics/watchermetrics.go +++ b/pkg/metrics/watchermetrics/watchermetrics.go @@ -44,17 +44,26 @@ var ( Help: "The total number of events for a given watcher type.", ConstLabels: nil, }, []string{"watcher"}) + + WatcherDeletedPodCacheHits = prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: consts.MetricsNamespace, + Name: "watcher_delete_pod_cache_hits", + Help: "The total hits for pod information in the deleted pod cache.", + ConstLabels: nil, + }) ) func RegisterMetrics(group metrics.Group) { group.MustRegister(WatcherErrors) group.MustRegister(WatcherEvents) + group.MustRegister(WatcherDeletedPodCacheHits) } func InitMetrics() { // Initialize metrics with labels GetWatcherEvents(K8sWatcher).Add(0) GetWatcherErrors(K8sWatcher, FailedToGetPodError).Add(0) + GetWatcherDeletedPodCacheHits().Add(0) } // Get a new handle on an WatcherEvents metric for a watcher type @@ -66,3 +75,7 @@ func GetWatcherEvents(watcherType Watcher) prometheus.Counter { func GetWatcherErrors(watcherType Watcher, watcherError ErrorType) prometheus.Counter { return WatcherErrors.WithLabelValues(watcherType.String(), string(watcherError)) } + +func GetWatcherDeletedPodCacheHits() prometheus.Counter { + return WatcherDeletedPodCacheHits +} diff --git a/pkg/watcher/deleted_pod_cache.go b/pkg/watcher/deleted_pod_cache.go index 8b3527f2f41..5c41cf36dc4 100644 --- a/pkg/watcher/deleted_pod_cache.go +++ b/pkg/watcher/deleted_pod_cache.go @@ -5,6 +5,7 @@ package watcher import ( "github.com/cilium/tetragon/pkg/logger" + "github.com/cilium/tetragon/pkg/metrics/watchermetrics" lru "github.com/hashicorp/golang-lru/v2" corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1" @@ -81,5 +82,6 @@ func (c *deletedPodCache) findContainer(containerID string) (*corev1.Pod, *corev return nil, nil, false } + watchermetrics.GetWatcherDeletedPodCacheHits().Inc() return v.pod, v.contStatus, true }