Unable to convert timestamp from Epoch to readable format in Infinity plugin from API

Hi,
I’m looking to convert the epoch timestamp from Dynatrace API to human readable format. Tried multiple ways and it is not working.


Below is the json
[
{
“data”: [
{
“dimensionMap”: {
“dt.entity.host”: “HOST-XXX”
},
“dimensions”: [
“HOST-XXX”
],
“timestamps”: [
1738368000000
],
“values”: [
99.62907695770264
]
},
{
“dimensionMap”: {
“dt.entity.host”: “HOST-YYY”
},
“dimensions”: [
“HOST-YYY”
],
“timestamps”: [
1738368000000
],
“values”: [
96.59589695930481
]
}
],

}
]

How to convert this to timestamp format? Can someone assist?

API used is the below one
https://XXXX.abc.com/api/v2/metrics/query?metricSelector=builtin:host.cpu.usage:filter(in(“dt.entity.host”,entitySelector(“type(HOST),entityName.in(A,B,C,D)”))):splitBy("dt.entity.host"):max:sort(value(max,descending)):limit(20)&from=${__from:YYYY-MM-DDTHH:mm:ssZ}&to=${__to:YYYY-MM-DDTHH:mm:ssZ}&resolution=1h

you might to look into using jsonata feature of infinity plugin with UQL

1 Like

Thank you so much. Jsonata expression worked - parse-json
|jsonata “result[0].data[*].{‘host’: dimensionMap.‘dt.entity.host’,‘dimensions’:dimensions[0],‘timestamps’:$fromMillis(timestamps[0]),‘values’:values[0]}”

I have a follow up question please - How to represent multiple timestamp values? I have tried using Map as below. Is there a better way to do this? As I see continuous values in your graph, I could not project the same.
When I tested, I could see only one timestamp value from array (since it is timestamps[0])
Using Map -
parse-json
|jsonata “result[0].data[*].{‘host’: dimensionMap.‘dt.entity.host’,‘dimensions’:dimensions[0],‘timestamps’:$map(timestamps,function($ts) { $ts {‘timestampAct’:$fromMillis($ts)}}),‘CPU Usage’:values}”

This is working. But I have extra fields which I’m not able to flatten. Kindly assist @yosiasz
How did you get the straight line graph across multiple time intervals? I’m looking for the same. Can you please share the jsonata that you tried. It would be very helpful.

1 Like