SLA and uptime tracking helps you check if a service is working well and meeting promises. It shows how often a service is available and reliable.
0
0
SLA and uptime tracking in Rest API
Introduction
You want to know if a website is online most of the time.
You need to check if a cloud service meets its promised availability.
You want to alert your team when a service goes down.
You want to report service reliability to customers.
You want to improve your system by tracking downtime.
Syntax
Rest API
GET /uptime
Response:
{
"service": "ServiceName",
"uptime_percentage": 99.95,
"downtime_minutes": 10,
"period": "last_30_days"
}This is a simple REST API call to get uptime data.
The response usually includes uptime percentage, downtime, and the time period checked.
Examples
Check uptime for a website in the last 7 days.
Rest API
GET /uptime?service=website&period=last_7_days
Response:
{
"service": "website",
"uptime_percentage": 99.9,
"downtime_minutes": 10,
"period": "last_7_days"
}Check if the database service meets its SLA target.
Rest API
GET /sla?service=database
Response:
{
"service": "database",
"sla_target": 99.99,
"actual_uptime": 99.95,
"status": "Below SLA"
}Sample Program
This program calls a REST API to get uptime data for a website over the last 30 days. It then prints the service name, uptime percentage, downtime in minutes, and the period checked.
Rest API
import requests # URL of the uptime API url = 'https://api.example.com/uptime' # Parameters to check uptime for a service params = {'service': 'website', 'period': 'last_30_days'} # Make the GET request response = requests.get(url, params=params) # Parse JSON response data = response.json() # Print uptime info print(f"Service: {data['service']}") print(f"Uptime: {data['uptime_percentage']}%") print(f"Downtime: {data['downtime_minutes']} minutes") print(f"Period: {data['period']}")
OutputSuccess
Important Notes
Uptime is usually shown as a percentage of time the service was available.
Downtime is the total minutes the service was not available during the period.
SLA targets are goals set for uptime, like 99.9% or 99.99%.
Summary
SLA and uptime tracking helps measure service reliability.
Use REST API calls to get uptime and downtime data.
Compare actual uptime to SLA targets to check service health.