Age based on timestamp

Hello, need to monitor long running pods in kubernetes using new relic alerts. Therefore need to convert timestamp of pod creation to a number representing age in hours or minutes or seconds. Unfortunately cannot find useful function to achieve that. There is timestamp of each record and createdAt in K8sPodSample event:

SELECT timestamp, createdAt  FROM K8sPodSample  limit 5

Any idea?

@vbartos Have you tried changing the format using the Data Formatter? https://docs.newrelic.com/docs/insights/use-insights-ui/manage-account-data/data-formatter-set-default-formats-numeric-values

This is what I did

FROM K8sPodSample SELECT latest(createdAt), latest((timestamp/1000 - createdAt)/60) as 'Minutes Running' where namespaceName='appNamespace' AND status='Running' AND createdAt < timestamp/1000 - 7200 FACET podName,deploymentName LIMIT MAX

The trick here was timestamp was in ms and createdAt was in seconds. Also I only wanted to view pods that were longer than 2 hours or 7200 seconds

1 Like

Let us know how these suggestions working out for you @vbartos!