Retrieving Bandwidth Metrics
You can use this guide to learn how to use the StackPath API system to monitor the ingress and egress bandwidth of a workload.
Review Available Metrics
Bandwidth metrics can be pulled for an entire Stack or for an individual workload. Bandwidth is always divided by StackPath PoP locations and will have to be summed for total use.
Retrieve usage metrics for all workloads in your Stack, a specific workload, or a specific instance in a workload by making a GET request to the Get metrics endpoint.
Query Parameters
type (String)
(Required)
Set the value as "BANDWIDTH" to pull bandwidth metrics
start_date (Datetime)
(Required)
Start Date specified the beginning of the reporting period over which the call pulls metrics from. If this period is before the date of workload creation, all values will be set to zero.
The datetime string should be in the standard datetime format YYYY-MM-DDTHH:MM:ss.sssZ
end_date (Datetime)
(Required)
End Date specified the end of the reporting period over which the call pulls metrics from. If this period is after the current time, a JSON response with 'message': 'Unable to get metrics at this time'. will be returned.
The datetime string should be in the standard datetime format YYYY-MM-DDTHH:MM:ss.sssZ
workload_id (String)
(Optional, Default: All Workloads)
Workload ID can be pulled from the URL in the StackPath Control Panel or from the Compute API GET workloads endpoint.
granularity (String)
(Optional, Default: PT5M)
The summation period of metrics between the start_date and end_date.
- PT5M - 5 minutes
- PT1H - 1 hour
- P1D - 1 Day
PoP (String)
(Optional, Default: ALL)
Filter traffic metrics by StackPath Point of Presence. Pull the possible location identifiers via the StackPath API Endpoint GET Locations.
Below are a few examples of API requests where we are modifying the query parameters of the URL in order to obtain the information we need.
Obtain Daily Metrics by Workload
curl --request GET \
--url 'https://gateway.stackpath.com/workload/v1/stacks/STACK_ID/metrics?start_date=2019-03-23T14%3A54%3A18.442Z&end_date=2019-03-24T14%3A54%3A18.442Z&type=BANDWIDTH&granularity=P1D®ion=ALL&group_by=NONE' \
--header 'accept: application/json' \
--header 'authorization: Bearer BEARER_TOKEN'
Obtain Hourly Metrics by Instance
curl --request GET \
--url 'https://gateway.stackpath.com/workload/v1/stacks/STACK_ID/metrics?workload_id=WORKLOAD_ID&start_date=2019-03-23T14%3A54%3A18.442Z&end_date=2019-03-24T14%3A54%3A18.442Z&type=BANDWIDTH&granularity=PT1H&instance_name=INSTANCE_NAME®ion=ALL&group_by=NONE' \
--header 'accept: application/json' \
--header 'authorization: Bearer BEARER_TOKEN'
Obtain filtered metrics by PoP
curl --request GET \
--url 'https://gateway.stackpath.com/workload/v1/stacks/STACK_ID/metrics?workload_id=WORKLOAD_ID&start_date=2019-03-23T14%3A54%3A18.442Z&end_date=2019-03-24T14%3A54%3A18.442Z&type=BANDWIDTH&granularity=PT1H&instance_name=INSTANCE_NAME&pop=lhr02®ion=ALL&group_by=NONE' \
--header 'accept: application/json' \
--header 'authorization: Bearer BEARER_TOKEN'
Review response
The API calls above will produce a successful 200 response similar to the one below:
{
"status":"success",
"data":{
"resultType":"matrix",
"result":[{
"metric":{
"__name__":"ingress_bandwidth",
"pop":"lhr02",
"traffic_region":"INTERNET"},
"values":[[1553385600,"2569901"]]},{
"metric":{
"__name__":"egress_bandwidth",
"pop":"lhr02",
"traffic_region":"INTERNET"},
"values":[[1553385600,"4442578"]]
}
]}
}
Each polling time period contains two types of results, ingress and egress. Ingress measures the inbound traffic to the compute instance, while egress measures outbound traffic from your instance. For each traffic region, the values list contains an epoch timestamp and the total amount of data in bytes.
Examining the response above, the epoch time "1553385600" translates to Sunday, March 24, 2019 12:00:00 AM and the public ingress of "2569901" bytes converts to 2.6MB.
Updated 5 months ago