4

I am running a kubernetes cluster with heapster and prometheus service. I want to measure each container and pods start and end time but i could not find such statistics in prometheus.

I want to get these statistics through some api.

Does anyone know how can I get it ?

Anshul Jindal
  • 368
  • 2
  • 17

3 Answers3

4

The kube-state-metrics job exports various Kubernetes API relates stats for Prometheus, including in kube_pod_info the Pod start time:

https://github.com/kubernetes/kube-state-metrics/blob/master/Documentation/pod-metrics.md

tom.wilkie
  • 2,846
  • 20
  • 16
  • I did that but I couldnot find start_time in the promethus data of kube_pod_info.. I don't know why ` {"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"kube_pod_info","app":"kube-state-metrics","created_by":"ReplicaSet/prometheus-core-549408679","host_ip":"10.155.208.227","instance":"10.32.0.9:8080","job":"kubernetes-endpoints","kubernetes_name":"kube-state-metrics","kubernetes_namespace":"monitoring","namespace":"monitoring","node":"vm-10-155-208-227","pod":"prometheus-core-549408679-r0g6q","pod_ip":"10.32.0.13"},"value":[1498922287.642,"1"]} ` – Anshul Jindal Jul 01 '17 at 15:19
  • 1
    Strange, I don't see `start_time` in the code at all: https://github.com/kubernetes/kube-state-metrics/search?utf8=%E2%9C%93&q=start_time&type=. I would expect it to be at https://github.com/kubernetes/kube-state-metrics/blob/3bf74507e082607d9ce6d5c935efe6459d67099d/collectors/pod.go#L43. Maybe the docs were written with the idea that this would be a metric and didn't make it's way in yet? – Andy Shinn Jul 01 '17 at 17:41
  • @tom.wilkie is `start_time` useful enough as a label - can I plot a graph from label value? It also seems like not a great use of labels, isn't it...? – errordeveloper Jul 05 '17 at 14:59
  • @AndyShinn yes, looks like code isn't there indeed... filed https://github.com/kubernetes/kube-state-metrics/issues/163. – errordeveloper Jul 05 '17 at 15:04
0

Actually I was able to measure up the container start time using the heapster events for a pod. For each container, inside the pod heapster captures the events, from this I was able to at least get containerCreated and ContainerStart timestamp.

Anshul Jindal
  • 368
  • 2
  • 17
0

If you are looking to calculate the completion time using start and end time then you can use the prometheus metric kube_pod_completion_time.

Surya
  • 88
  • 9