@@ -41,42 +41,53 @@ var (
4141)
4242
4343var (
44- EventsProcessed = metrics .MustNewGranularCounter [metrics.ProcessLabels ](prometheus.CounterOpts {
45- Namespace : consts .MetricsNamespace ,
46- Name : "events_total" ,
47- Help : "The total number of Tetragon events" ,
48- ConstLabels : nil ,
49- }, []string {"type" })
44+ // Preserve label name "type" while using constrained values from EventTypeLabel.
45+ eventTypeLabel = metrics.ConstrainedLabel {
46+ Name : "type" ,
47+ Values : append (slices .Clone (metrics .EventTypeLabel .Values ), "unknown" ),
48+ }
49+
50+ EventsProcessed = metrics .MustNewGranularCounterWithInit [metrics.ProcessLabels ](
51+ metrics .NewOpts (
52+ consts .MetricsNamespace , "" , "events_total" ,
53+ "The total number of Tetragon events" ,
54+ nil , []metrics.ConstrainedLabel {eventTypeLabel }, nil ,
55+ ),
56+ nil ,
57+ )
5058 MissedEvents = metrics .MustNewCustomCounter (metrics .NewOpts (
5159 consts .MetricsNamespace , "bpf" , "missed_events_total" ,
5260 "Number of Tetragon perf events that are failed to be sent from the kernel." ,
5361 nil , []metrics.ConstrainedLabel {metrics .OpCodeLabel , perfEventErrorLabel }, nil ,
5462 ))
55- FlagCount = prometheus .NewCounterVec (prometheus.CounterOpts {
56- Namespace : consts .MetricsNamespace ,
57- Name : "flags_total" ,
58- Help : "The total number of Tetragon flags. For internal use only." ,
59- ConstLabels : nil ,
60- }, []string {"type" })
61- NotifyOverflowedEvents = prometheus .NewCounter (prometheus.CounterOpts {
62- Namespace : consts .MetricsNamespace ,
63- Name : "notify_overflowed_events_total" ,
64- Help : "The total number of events dropped because listener buffer was full" ,
65- ConstLabels : nil ,
66- })
67-
68- policyStats = metrics .MustNewGranularCounter [metrics.ProcessLabels ](prometheus.CounterOpts {
69- Namespace : consts .MetricsNamespace ,
70- Name : "policy_events_total" ,
71- Help : "Policy events calls observed." ,
72- ConstLabels : nil ,
73- }, []string {"policy" , "hook" })
74-
75- missingProcessInfo = prometheus .NewCounter (prometheus.CounterOpts {
76- Namespace : consts .MetricsNamespace ,
77- Name : "events_missing_process_info_total" ,
78- Help : "Number of events missing process info." ,
79- })
63+ FlagCount = metrics .MustNewCounter (
64+ metrics .NewOpts (
65+ consts .MetricsNamespace , "" , "flags_total" ,
66+ "The total number of Tetragon flags. For internal use only." ,
67+ nil , nil , []metrics.UnconstrainedLabel {{Name : "type" , ExampleValue : "unknown" }},
68+ ),
69+ nil ,
70+ )
71+ NotifyOverflowedEvents = metrics .MustNewCounter (metrics .NewOpts (
72+ consts .MetricsNamespace , "" , "notify_overflowed_events_total" ,
73+ "The total number of events dropped because listener buffer was full" ,
74+ nil , nil , nil ,
75+ ), nil )
76+
77+ policyStats = metrics .MustNewGranularCounterWithInit [metrics.ProcessLabels ](
78+ metrics .NewOpts (
79+ consts .MetricsNamespace , "" , "policy_events_total" ,
80+ "Policy events calls observed." ,
81+ nil , nil , []metrics.UnconstrainedLabel {{Name : "policy" , ExampleValue : consts .ExamplePolicyLabel }, {Name : "hook" , ExampleValue : consts .ExampleKprobeLabel }},
82+ ),
83+ nil ,
84+ )
85+
86+ missingProcessInfo = metrics .MustNewCounter (metrics .NewOpts (
87+ consts .MetricsNamespace , "" , "events_missing_process_info_total" ,
88+ "Number of events missing process info." ,
89+ nil , nil , nil ,
90+ ), nil )
8091)
8192
8293func RegisterHealthMetrics (group metrics.Group ) {
@@ -122,7 +133,7 @@ func GetProcessInfo(process *tetragon.Process) (binary, pod, workload, namespace
122133 pod = process .Pod .Name
123134 }
124135 } else {
125- missingProcessInfo .Inc ()
136+ missingProcessInfo .WithLabelValues (). Inc ()
126137 }
127138 return binary , pod , workload , namespace
128139}
0 commit comments