Skip to content

Commit

Permalink
create new metric
Browse files Browse the repository at this point in the history
  • Loading branch information
ssabo committed Aug 24, 2022
1 parent 1851bfa commit e31b035
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions internal/store/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func podMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
createPodContainerResourceRequestsFamilyGenerator(),
createPodContainerStateStartedFamilyGenerator(),
createPodContainerStatusLastTerminatedReasonFamilyGenerator(),
createPodContainerStatusLastTerminatedExitCodeFamilyGenerator(),
createPodContainerStatusReadyFamilyGenerator(),
createPodContainerStatusRestartsTotalFamilyGenerator(),
createPodContainerStatusRunningFamilyGenerator(),
Expand Down Expand Up @@ -321,12 +322,34 @@ func createPodContainerStatusLastTerminatedReasonFamilyGenerator() generator.Fam
for _, cs := range p.Status.ContainerStatuses {
if cs.LastTerminationState.Terminated != nil {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"container", "reason", "exitcode"},
LabelValues: []string{
cs.Name,
cs.LastTerminationState.Terminated.Reason,
strconv.Itoa(int(cs.LastTerminationState.Terminated.ExitCode))},
Value: 1,
LabelKeys: []string{"container", "reason"},
LabelValues: []string{cs.Name, cs.LastTerminationState.Terminated.Reason},
Value: 1,
})
}
}

return &metric.Family{
Metrics: ms,
}
}),
)
}

func createPodContainerStatusLastTerminatedExitCodeFamilyGenerator() generator.FamilyGenerator {
return *generator.NewFamilyGenerator(
"kube_pod_container_status_last_terminated_exitcode",
"Describes the exit code for the last container in terminated state.",
metric.Gauge,
"",
wrapPodFunc(func(p *v1.Pod) *metric.Family {
ms := make([]*metric.Metric, 0, len(p.Status.ContainerStatuses))
for _, cs := range p.Status.ContainerStatuses {
if cs.LastTerminationState.Terminated != nil {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"container", "reason"},
LabelValues: []string{cs.Name, cs.LastTerminationState.Terminated.Reason},
Value: float64(cs.LastTerminationState.Terminated.ExitCode),
})
}
}
Expand Down

0 comments on commit e31b035

Please sign in to comment.