cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do get synthetic monitor availabililty from API?

DuaneRoelands
Contributor

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?

13 REPLIES 13

dannemca
DynaMight Guru
DynaMight Guru

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:

  • from=now-30d
    • query last 30 days
  • resolution=30d
    • get the resolution of one single value with the average of last 30 days
  • metricSelector=builtin:synthetic.http.availability.location.total
    • that's the metric selector where you can filter by a specific Monitor ID, work on the split by locations, if requried, etc, you can go crazy here.

Try and let us know.

Site Reliability Engineer @ Kyndryl

DuaneRoelands
Contributor

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?

 

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.

Site Reliability Engineer @ Kyndryl

DuaneRoelands
Contributor
{
    "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."
            ]
        }
    ]
}

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))
Site Reliability Engineer @ Kyndryl

DuaneRoelands
Contributor

Almost there.  How can I get ONLY the dimension that includes the availability without the GEOLOCATION value?

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))
Site Reliability Engineer @ Kyndryl

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
                    ]
                }
            ]
        }
    ]
}

That's due to the timestamp from and the resolution. Try do use a higher resolution , like resolution=31d

 

Site Reliability Engineer @ Kyndryl

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?).

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

Site Reliability Engineer @ Kyndryl

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
                    ]
                }
            ]
        }
    ]
}

 

Try a higher resolution then. resolution=95d.

Site Reliability Engineer @ Kyndryl

Featured Posts