I’ve been asked a few times regarding retrieving the availability metrics for Agents and Targets in order to report them in third-party dashboards. Here’s how we calculate these metrics and how the get them through the API:
- Agent availability is the percentage of time the agent weas able to keep a steady connection to its BeezKeeper™ server.
- Target availability can be the reverse of packet loss from a Ping test that was running from multiple agents towards the target’s host.
Both of these are available through the Legacy API (v1 aka. Swagger) at the moment. It’s in our roadmap to switch that over this year, but it wouldn’t be difficult to implement this with Legacy and then refactor to transition to the new one.
For example, to get the availability of an agent through the legacy API you would use:
curl -X GET --header 'Accept: application/json' --header 'Authorization: XXXXXXXXXXXXXXXXXXXXXXXXXXX' --header 'API-VERSION: v1' 'https://demo1.netbeezcloud.net/nb_agent_statistics.json?agent_id=17&from=1735312346330&to=1735917146330&window_size=10800&last=1'
Response
{
"agent_stats": [
{
"timestamp": 1735880400002,
"window_size": 10800,
"interval": 594180477,
"uptime": 100,
"agent_id": 17,
"id": null
}
]
}
For Target availability we will use the “packet loss” metric from a Ping test template on that target and reverse that to represent Target availability.
Here’s how you get the packet loss for a specific Ping test from the Target’s perspective, i.e. the average packet loss from ALL agents for a given time window:
curl -X GET --header 'Accept: application/json' --header 'Authorization: XXXXXXXXXXXXXXXXXXXXX' --header 'API-VERSION: v1' 'https://demo1.netbeezcloud.net/nb_test_statistics.json?nb_test_template_id=133&window_size=10800&from=1735312346330&to=1735917146330&metric_type=mean'
Result:
{
"nbTestStatistics": [
{
"timestamp": 1735916400000,
"datapoint_count": 505441,
"error_count": 1790,
"window_size": 648000,
"nb_test_id": 642506,
"nb_test_template_id": 133,
"value": 29.775613733942226,
"metric_type": "mean",
"id": null
}
]
}
Then you can get the Target availability by dividing
505441/(505441 + 1790) = 0.9964 ← 99.64% availability
If you find this useful please drop a line in the comments, as well as if you have any questions about this!
Thank your for reading!