diff --git a/docs/metrics/workload/pod-metrics.md b/docs/metrics/workload/pod-metrics.md index 8b8ed9116..05a2dd3a6 100644 --- a/docs/metrics/workload/pod-metrics.md +++ b/docs/metrics/workload/pod-metrics.md @@ -48,6 +48,8 @@ | kube_pod_init_container_status_restarts_total | Counter | The number of restarts for the init container | integer | `container`=<container-name>
`namespace`=<pod-namespace>
`pod`=<pod-name>
`uid`=<pod-uid> | STABLE | - | | kube_pod_init_container_resource_limits | Gauge | The number of CPU cores requested limit by an init container | `cpu`=<core>
`memory`=<bytes> | `resource`=<resource-name>
`unit`=<resource-unit>
`container`=<container-name>
`pod`=<pod-name>
`namespace`=<pod-namespace>
`node`=< node-name>
`uid`=<pod-uid> | EXPERIMENTAL | - | | kube_pod_init_container_resource_requests | Gauge | The number of CPU cores requested by an init container | `cpu`=<core>
`memory`=<bytes> | `resource`=<resource-name>
`unit`=<resource-unit>
`container`=<container-name>
`pod`=<pod-name>
`namespace`=<pod-namespace>
`node`=< node-name>
`uid`=<pod-uid> | EXPERIMENTAL | - | +| kube_pod_init_container_state_started | Gauge | Start time in unix timestamp for a pod init container | seconds | `container`=<container-name>
`pod`=<pod-name>
`namespace`=<pod-namespace>
`uid`=<pod-uid> | EXPERIMENTAL | - | +| kube_pod_init_container_status_last_terminated_timestamp | Gauge | Last terminated time for a pod init container in unix timestamp. | | `container`=<container-name>
`pod`=<pod-name>
`namespace`=<pod-namespace>
`uid`=<pod-uid> | EXPERIMENTAL | - | | kube_pod_spec_volumes_persistentvolumeclaims_info | Gauge | Information about persistentvolumeclaim volumes in a pod | | `pod`=<pod-name>
`namespace`=<pod-namespace>
`volume`=<volume-name>
`persistentvolumeclaim`=<persistentvolumeclaim-claimname>
`uid`=<pod-uid> | STABLE | - | | kube_pod_spec_volumes_persistentvolumeclaims_readonly | Gauge | Describes whether a persistentvolumeclaim is mounted read only | bool | `pod`=<pod-name>
`namespace`=<pod-namespace>
`volume`=<volume-name>
`persistentvolumeclaim`=<persistentvolumeclaim-claimname>
`uid`=<pod-uid> | STABLE | - | | kube_pod_status_reason | Gauge | The pod status reasons | | `pod`=<pod-name>
`namespace`=<pod-namespace>
`reason`=<Evicted\|NodeAffinity\|NodeLost\|Shutdown\|UnexpectedAdmissionError>
`uid`=<pod-uid> | EXPERIMENTAL | - | diff --git a/internal/store/pod.go b/internal/store/pod.go index d9ad4afa6..2bf87a8fa 100644 --- a/internal/store/pod.go +++ b/internal/store/pod.go @@ -64,7 +64,9 @@ func podMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat createPodInitContainerInfoFamilyGenerator(), createPodInitContainerResourceLimitsFamilyGenerator(), createPodInitContainerResourceRequestsFamilyGenerator(), + createPodInitContainerStateStartedFamilyGenerator(), createPodInitContainerStatusLastTerminatedReasonFamilyGenerator(), + createPodInitContainerStatusLastTerminatedTimestampFamilyGenerator(), createPodInitContainerStatusReadyFamilyGenerator(), createPodInitContainerStatusRestartsTotalFamilyGenerator(), createPodInitContainerStatusRunningFamilyGenerator(), @@ -858,6 +860,39 @@ func createPodInitContainerResourceRequestsFamilyGenerator() generator.FamilyGen ) } +func createPodInitContainerStateStartedFamilyGenerator() generator.FamilyGenerator { + return *generator.NewFamilyGeneratorWithStability( + "kube_pod_init_container_state_started", + "Start time in unix timestamp for a pod init container.", + metric.Gauge, + basemetrics.ALPHA, + "", + wrapPodFunc(func(p *v1.Pod) *metric.Family { + ms := []*metric.Metric{} + + for _, cs := range p.Status.InitContainerStatuses { + if cs.State.Running != nil { + ms = append(ms, &metric.Metric{ + LabelKeys: []string{"container"}, + LabelValues: []string{cs.Name}, + Value: float64((cs.State.Running.StartedAt).Unix()), + }) + } else if cs.State.Terminated != nil { + ms = append(ms, &metric.Metric{ + LabelKeys: []string{"container"}, + LabelValues: []string{cs.Name}, + Value: float64((cs.State.Terminated.StartedAt).Unix()), + }) + } + } + + return &metric.Family{ + Metrics: ms, + } + }), + ) +} + func createPodInitContainerStatusLastTerminatedReasonFamilyGenerator() generator.FamilyGenerator { return *generator.NewFamilyGeneratorWithStability( "kube_pod_init_container_status_last_terminated_reason", @@ -883,6 +918,32 @@ func createPodInitContainerStatusLastTerminatedReasonFamilyGenerator() generator ) } +func createPodInitContainerStatusLastTerminatedTimestampFamilyGenerator() generator.FamilyGenerator { + return *generator.NewFamilyGeneratorWithStability( + "kube_pod_init_container_status_last_terminated_timestamp", + "Last terminated time for a pod init container in unix timestamp.", + metric.Gauge, + basemetrics.ALPHA, + "", + wrapPodFunc(func(p *v1.Pod) *metric.Family { + ms := make([]*metric.Metric, 0, len(p.Status.ContainerStatuses)) + for _, cs := range p.Status.InitContainerStatuses { + if cs.LastTerminationState.Terminated != nil { + ms = append(ms, &metric.Metric{ + LabelKeys: []string{"container"}, + LabelValues: []string{cs.Name}, + Value: float64(cs.LastTerminationState.Terminated.FinishedAt.Unix()), + }) + } + } + + return &metric.Family{ + Metrics: ms, + } + }), + ) +} + func createPodInitContainerStatusReadyFamilyGenerator() generator.FamilyGenerator { return *generator.NewFamilyGeneratorWithStability( "kube_pod_init_container_status_ready",