18
18
Help : "Total number of API requests to the scheduler" ,
19
19
}, []string {"cluster" , "namespace" , "user" , "verb" , "resource" , "code" })
20
20
21
+ podDeletedTotal = prometheus .NewCounterVec (prometheus.CounterOpts {
22
+ Name : "pod_deleted_total" ,
23
+ Help : "Total number of pods deleted" ,
24
+ }, []string {"cluster" , "namespace" , "user" , "phase" })
25
+
21
26
podSchedulingLatency = prometheus .NewHistogramVec (prometheus.HistogramOpts {
22
27
Name : "pod_scheduling_latency_seconds" ,
23
28
Help : "Duration from pod creation to scheduled on node in seconds" ,
@@ -35,6 +40,7 @@ func init() {
35
40
registry .MustRegister (
36
41
apiRequests ,
37
42
podSchedulingLatency ,
43
+ podDeletedTotal ,
38
44
batchJobCompleteLatency ,
39
45
)
40
46
}
@@ -107,6 +113,22 @@ func (p *Exporter) updateMetrics(clusterLabel string, event auditv1.Event) {
107
113
}
108
114
} else if event .Verb == "delete" {
109
115
delete (p .podCreationTimes , buildTarget (event .ObjectRef ))
116
+
117
+ if event .ResponseObject != nil {
118
+ var pod Pod
119
+ if err := json .Unmarshal (event .ResponseObject .Raw , & pod ); err != nil {
120
+ slog .Error ("failed to unmarshal pod during delete" , "err" , err )
121
+ return
122
+ }
123
+
124
+ user := extractUserAgent (event .UserAgent )
125
+ podDeletedTotal .WithLabelValues (
126
+ clusterLabel ,
127
+ ns ,
128
+ user ,
129
+ pod .Status .Phase ,
130
+ ).Inc ()
131
+ }
110
132
}
111
133
}
112
134
0 commit comments