How to calculate time difference between min & max data points

  • What Grafana version and what operating system are you using?
    I’m on AWS grafana. Not sure what version but most likely the latest.

  • What are you trying to achieve?
    Given any time series, for example the one below, kube_pod_container_resource_requests (I need to do this for many metrics but they’re all TS),

  1. I need to create two sister charts (ie, not inside this chart) that shows the start and end time of this metric’s time series. E.g., this case, first sister chart would show 2023-01-15 10:17:00 (as shown in the png below) and the second would show 2023-01-15 10:24:45 .
  2. A third chart showing the elapsed time. In this case 07:45.

All three sister charts would be of type “Stat”.

Since I’m learning promQL, please provide me the link to the docs where prospective solution is documented (preferably a link in grafana.com)

  • How are you trying to achieve it?
    I couldn’t find documentation to show the timestamp rather than value. I’ve tried
    ** increase(kube_pod_container_resource_requests{container=“spark-kubernetes-driver”,pod=“$driver_id”,resource=“cpu”,prometheus_replica=“prometheus-k8s-1”}[1m])
    ** avg_over_time(kube_pod_container_resource_requests{container=“spark-kubernetes-driver”,pod=“$driver_id”,resource=“cpu”,prometheus_replica=“prometheus-k8s-1”}[1m])
    ** time((kube_pod_container_resource_requests{container=“spark-kubernetes-driver”,pod=“$driver_id”,resource=“cpu”,prometheus_replica=“prometheus-k8s-1”}))

  • What happened?
    All attempts to display the timestamp failed

  • What did you expect to happen?
    I expected to see the initial timestamp, the final timestamp and the elapsed duration of the given metric

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No

  • Did you follow any online instructions? If so, what is the URL?
    I couldn’t find any links pointing to calculating the time difference between two specific time series data points.

Did you solve the issue?


This is in AMG (Amazon Managed Grafana). Grafana could be different.
To get the start time Stat panel to work, in the value options, select First and the field Time. Similarly, for Last (not shown here).

Unfortunately, the difference/range function is not operating as expected:


It is calculating the difference correctly: 07:45 minutes, but it’s displaying the time as ISO instead of simply time portion. I tried many possible options under Standard Options->Unit to no avail.

Can you suggest something else?