16 Oct 2023 02:40 PM
I would like to query the API with the id of a specific synthetic monitor and get the availability for the current day, for the last 7 days, for the last 30 days and for the last 90 days.
The API documentation indicates that general information about a monitor is available, but I can't find any documenation on how to get the availability numbers.
Is this possible through the API?
16 Oct 2023 03:22 PM - edited 16 Oct 2023 03:31 PM
Hi @DuaneRoelands , you can achieve this with the Get metric data points API: https://www.dynatrace.com/support/help/dynatrace-api/environment-api/metric-v2/get-data-points
And use the builtin metrics for Synthetic Monitors, https://www.dynatrace.com/support/help/observe-and-explore/metrics/built-in-metrics#synthetic-monito...
Example, querying an HTTP monitor ID from last 30 days:
curl --location 'https://tenant.live.dynatrace.com/api/v2/metrics/query?from=now-30d&resolution=30d&metricSelector=builtin%3Asynthetic.http.availability.location.total%3Afilter(and(or(in(%22dt.entity.http_check%22%2CentitySelector(%22type(http_check)%2CentityId(~%22HTTP_CHECK-B97FBA280E3DC655~%22)%22)))))%3AsplitBy(%22dt.entity.http_check%22%2C%22dt.entity.synthetic_location%22)%3Asort(value(auto%2Cdescending))' \ --header 'Authorization: Api-token dt0c01.4OHVEPBHJGFYCVRCPHAI4FU4.tokenwithrightscope'
result:
{
"totalCount": 1,
"nextPageKey": null,
"resolution": "30d",
"result": [
{
"metricId": "builtin:synthetic.http.availability.location.total:filter(and(or(in(\"dt.entity.http_check\",entitySelector(\"type(http_check),entityId(~\"HTTP_CHECK-B97FBA280E3DC655~\")\"))))):splitBy(\"dt.entity.http_check\",\"dt.entity.synthetic_location\"):sort(value(auto,descending))",
"dataPointCountRatio": 0.0,
"dimensionCountRatio": 1.0E-5,
"data": [
{
"dimensions": [
"HTTP_CHECK-B97FBA280E3DC655",
"SYNTHETIC_LOCATION-27E967621146D2EC"
],
"dimensionMap": {
"dt.entity.synthetic_location": "SYNTHETIC_LOCATION-27E967621146D2EC",
"dt.entity.http_check": "HTTP_CHECK-B97FBA280E3DC655"
},
"timestamps": [
1697500800000
],
"values": [
99.71761587744338
]
}
]
}
]
}
where:
Try and let us know.
18 Oct 2023 03:17 PM
Can't get data using this method. Steps:
Browsed through the Dynatrace UI to a synthetic at this URL:
https://{environmentid}.live.dynatrace.com/ui/browser-monitor/SYNTHETIC_TEST-6F96250FB9911AAC?gtf=-2h&gf=all
Took the "SYNTHETIC_TEST-6F96250FB9911AAC" value from that URL and plugged into the URL described above:
https://{environmentid}.live.dynatrace.com/api/v2/metrics/query?from=now-30d&resolution=30d&metricSelector=builtin:synthetic.http.availability.location.total:filter(and(or(in("dt.entity.http_check",entitySelector("type(http_check),entityId(~"SYNTHETIC_TEST-6F96250FB9911AAC~")"))))):splitBy("dt.entity.http_check","dt.entity.synthetic_location"):sort(value(auto,descending))
Got the following JSON response:
{
"totalCount": 0,
"nextPageKey": null,
"resolution": "30d",
"result": [
{
"metricId": "builtin:synthetic.http.availability.location.total:filter(and(or(in(\"dt.entity.http_check\",entitySelector(\"type(http_check),entityId(~\"SYNTHETIC_TEST-6F96250FB9911AAC~\")\"))))):splitBy(\"dt.entity.http_check\",\"dt.entity.synthetic_location\"):sort(value(auto,descending))",
"dataPointCountRatio": 0.0,
"dimensionCountRatio": 0.0,
"data": []
}
]
}
What am I missing?
18 Oct 2023 06:16 PM - edited 18 Oct 2023 06:18 PM
Hi @DuaneRoelands , since you want to retrieve data from a Browser Monitor, you need to replace the metric to its respective entity.
from: builtin:synthetic.http.availability.location.total
to: builtin:synthetic.browser.availability.location.total
https://{environmentid}.live.dynatrace.com/api/v2/metrics/query?from=now-30d&resolution=30d&metricSelector=builtin:synthetic.browser.availability.location.total:filter(and(or(in("dt.entity.synthetic_test",entitySelector("type(synthetic_test),entityId(~"SYNTHETIC_TEST-6F96250FB9911AAC~")"))))):splitBy("dt.entity.synthetic_test","dt.entity.synthetic_location"):sort(value(auto,descending))
Try and let us know.
18 Oct 2023 06:23 PM
{
"totalCount": 0,
"nextPageKey": null,
"resolution": "30d",
"warnings": [
"The dimension key `dt.entity.synthetic_location` has been referenced, but the metric has no such key."
],
"result": [
{
"metricId": "builtin:synthetic.browser.availability.location.total:filter(and(or(in(\"dt.entity.synthetic_test\",entitySelector(\"type(synthetic_test),entityId(~\"SYNTHETIC_TEST-6F96250FB9911AAC~\")\"))))):splitBy(\"dt.entity.synthetic_test\",\"dt.entity.synthetic_location\"):sort(value(auto,descending))",
"dataPointCountRatio": 0.0,
"dimensionCountRatio": 2.0E-5,
"data": [],
"warnings": [
"The dimension key `dt.entity.synthetic_location` has been referenced, but the metric has no such key."
]
}
]
}
18 Oct 2023 06:29 PM
Sorry, @DuaneRoelands my mistake.
try this:
https://{environmentid}.live.dynatrace.com/api/v2/metrics/query?from=now-30d&resolution=30d&metricSelector=builtin:synthetic.browser.availability.location.total:filter(and(or(in("dt.entity.synthetic_test",entitySelector("type(synthetic_test),entityId(~"SYNTHETIC_TEST-6F96250FB9911AAC~")"))))):splitBy("dt.entity.synthetic_test","dt.entity.geolocation"):sort(value(auto,descending))
18 Oct 2023 06:39 PM
Almost there. How can I get ONLY the dimension that includes the availability without the GEOLOCATION value?
18 Oct 2023 07:29 PM
Just remove it from the splitby condition
https://{environmentid}.live.dynatrace.com/api/v2/metrics/query?from=now-30d&resolution=30d&metricSelector=builtin:synthetic.browser.availability.location.total:filter(and(or(in("dt.entity.synthetic_test",entitySelector("type(synthetic_test),entityId(~"SYNTHETIC_TEST-6F96250FB9911AAC~")"))))):splitBy("dt.entity.synthetic_test"):sort(value(auto,descending))
18 Oct 2023 07:36 PM
Why are there two values in the result?
{
"totalCount": 1,
"nextPageKey": null,
"resolution": "30d",
"result": [
{
"metricId": "builtin:synthetic.browser.availability.location.total:filter(and(or(in(\"dt.entity.synthetic_test\",entitySelector(\"type(synthetic_test),entityId(~\"SYNTHETIC_TEST-6F96250FB9911AAC~\")\"))))):splitBy(\"dt.entity.synthetic_test\"):sort(value(auto,descending))",
"dataPointCountRatio": 0.0,
"dimensionCountRatio": 2.0E-5,
"data": [
{
"dimensions": [
"SYNTHETIC_TEST-6F96250FB9911AAC"
],
"dimensionMap": {
"dt.entity.synthetic_test": "SYNTHETIC_TEST-6F96250FB9911AAC"
},
"timestamps": [
1695081600000,
1697673600000
],
"values": [
99.65797381270639,
100
]
}
]
}
]
}
18 Oct 2023 08:18 PM
That's due to the timestamp from and the resolution. Try do use a higher resolution , like resolution=31d
18 Oct 2023 08:27 PM
I'm not sure I understand. If the from is now-30 and the resolution is 30, I would expect to only get one value back.
What's the right way to get a single value for the past 30 days (or any specific time period like 7 days or 90 days?).
18 Oct 2023 08:34 PM - edited 18 Oct 2023 08:35 PM
That's because now-30d is more than 30d, (30 days and few hours), and when you set the resolution to 30d you still have some extra points to be captured, so you get two values.
Setting the resolution to a higher number than the from will get you one single data point then.
from=now-30d, resolution=31d
from=now-7d, resolution=8d
from=now-90d, resolution=91d
18 Oct 2023 08:42 PM
from=now-90d, resolution=91d returns multiple values.
/api/v2/metrics/query?from=now-90d&resolution=91d&metricSelector=builtin:synthetic.browser.availability.location.total:filter(and(or(in("dt.entity.synthetic_test",entitySelector("type(synthetic_test),entityId(~"SYNTHETIC_TEST-6F96250FB9911AAC~")"))))):splitBy("dt.entity.synthetic_test"):sort(value(auto,descending))
{
"totalCount": 1,
"nextPageKey": null,
"resolution": "91d",
"result": [
{
"metricId": "builtin:synthetic.browser.availability.location.total:filter(and(or(in(\"dt.entity.synthetic_test\",entitySelector(\"type(synthetic_test),entityId(~\"SYNTHETIC_TEST-6F96250FB9911AAC~\")\"))))):splitBy(\"dt.entity.synthetic_test\"):sort(value(auto,descending))",
"dataPointCountRatio": 0.0,
"dimensionCountRatio": 2.0E-5,
"data": [
{
"dimensions": [
"SYNTHETIC_TEST-6F96250FB9911AAC"
],
"dimensionMap": {
"dt.entity.synthetic_test": "SYNTHETIC_TEST-6F96250FB9911AAC"
},
"timestamps": [
1690156800000,
1698019200000
],
"values": [
100,
99.88410972041746
]
}
]
}
]
}
18 Oct 2023 09:54 PM
Try a higher resolution then. resolution=95d.