@@ -47,6 +47,7 @@ func podMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
47
47
createPodContainerResourceRequestsFamilyGenerator (),
48
48
createPodContainerStateStartedFamilyGenerator (),
49
49
createPodContainerStatusLastTerminatedReasonFamilyGenerator (),
50
+ createPodContainerStatusLastTerminatedExitCodeFamilyGenerator (),
50
51
createPodContainerStatusReadyFamilyGenerator (),
51
52
createPodContainerStatusRestartsTotalFamilyGenerator (),
52
53
createPodContainerStatusRunningFamilyGenerator (),
@@ -321,12 +322,34 @@ func createPodContainerStatusLastTerminatedReasonFamilyGenerator() generator.Fam
321
322
for _ , cs := range p .Status .ContainerStatuses {
322
323
if cs .LastTerminationState .Terminated != nil {
323
324
ms = append (ms , & metric.Metric {
324
- LabelKeys : []string {"container" , "reason" , "exitcode" },
325
- LabelValues : []string {
326
- cs .Name ,
327
- cs .LastTerminationState .Terminated .Reason ,
328
- strconv .Itoa (int (cs .LastTerminationState .Terminated .ExitCode ))},
329
- Value : 1 ,
325
+ LabelKeys : []string {"container" , "reason" },
326
+ LabelValues : []string {cs .Name , cs .LastTerminationState .Terminated .Reason },
327
+ Value : 1 ,
328
+ })
329
+ }
330
+ }
331
+
332
+ return & metric.Family {
333
+ Metrics : ms ,
334
+ }
335
+ }),
336
+ )
337
+ }
338
+
339
+ func createPodContainerStatusLastTerminatedExitCodeFamilyGenerator () generator.FamilyGenerator {
340
+ return * generator .NewFamilyGenerator (
341
+ "kube_pod_container_status_last_terminated_exitcode" ,
342
+ "Describes the exit code for the last container in terminated state." ,
343
+ metric .Gauge ,
344
+ "" ,
345
+ wrapPodFunc (func (p * v1.Pod ) * metric.Family {
346
+ ms := make ([]* metric.Metric , 0 , len (p .Status .ContainerStatuses ))
347
+ for _ , cs := range p .Status .ContainerStatuses {
348
+ if cs .LastTerminationState .Terminated != nil {
349
+ ms = append (ms , & metric.Metric {
350
+ LabelKeys : []string {"container" , "reason" },
351
+ LabelValues : []string {cs .Name , cs .LastTerminationState .Terminated .Reason },
352
+ Value : float64 (cs .LastTerminationState .Terminated .ExitCode ),
330
353
})
331
354
}
332
355
}
0 commit comments