import os
from gcore import Gcore
client = Gcore(
api_key=os.environ.get("GCORE_API_KEY"), # This is the default and can be omitted
)
cdn_metrics = client.cdn.metrics.list(
from_="2021-06-14T00:00:00Z",
metrics=["edge_status_2xx", "edge_status_3xx", "edge_status_4xx", "edge_status_5xx"],
to="2021-06-15T00:00:00Z",
)
print(cdn_metrics.data)package main
import (
"context"
"fmt"
"github.com/G-Core/gcore-go"
"github.com/G-Core/gcore-go/cdn"
"github.com/G-Core/gcore-go/option"
)
func main() {
client := gcore.NewClient(
option.WithAPIKey("My API Key"),
)
cdnMetrics, err := client.CDN.Metrics.List(context.TODO(), cdn.MetricListParams{
From: "2021-06-14T00:00:00Z",
Metrics: []string{"edge_status_2xx", "edge_status_3xx", "edge_status_4xx", "edge_status_5xx"},
To: "2021-06-15T00:00:00Z",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", cdnMetrics.Data)
}
curl --request POST \
--url https://api.gcore.com/cdn/advanced/v1/metrics \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"metrics": [
"edge_status_2xx",
"edge_status_3xx",
"edge_status_4xx",
"edge_status_5xx"
],
"from": "2021-06-14T00:00:00Z",
"to": "2021-06-15T00:00:00Z",
"group_by": [
"cname"
],
"granularity": "P1D",
"filter_by": [
{
"field": "resource",
"op": "eq",
"values": [
1234
]
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
metrics: ['edge_status_2xx', 'edge_status_3xx', 'edge_status_4xx', 'edge_status_5xx'],
from: '2021-06-14T00:00:00Z',
to: '2021-06-15T00:00:00Z',
group_by: ['cname'],
granularity: 'P1D',
filter_by: [{field: 'resource', op: 'eq', values: [1234]}]
})
};
fetch('https://api.gcore.com/cdn/advanced/v1/metrics', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.gcore.com/cdn/advanced/v1/metrics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'metrics' => [
'edge_status_2xx',
'edge_status_3xx',
'edge_status_4xx',
'edge_status_5xx'
],
'from' => '2021-06-14T00:00:00Z',
'to' => '2021-06-15T00:00:00Z',
'group_by' => [
'cname'
],
'granularity' => 'P1D',
'filter_by' => [
[
'field' => 'resource',
'op' => 'eq',
'values' => [
1234
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.gcore.com/cdn/advanced/v1/metrics")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"metrics\": [\n \"edge_status_2xx\",\n \"edge_status_3xx\",\n \"edge_status_4xx\",\n \"edge_status_5xx\"\n ],\n \"from\": \"2021-06-14T00:00:00Z\",\n \"to\": \"2021-06-15T00:00:00Z\",\n \"group_by\": [\n \"cname\"\n ],\n \"granularity\": \"P1D\",\n \"filter_by\": [\n {\n \"field\": \"resource\",\n \"op\": \"eq\",\n \"values\": [\n 1234\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gcore.com/cdn/advanced/v1/metrics")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"metrics\": [\n \"edge_status_2xx\",\n \"edge_status_3xx\",\n \"edge_status_4xx\",\n \"edge_status_5xx\"\n ],\n \"from\": \"2021-06-14T00:00:00Z\",\n \"to\": \"2021-06-15T00:00:00Z\",\n \"group_by\": [\n \"cname\"\n ],\n \"granularity\": \"P1D\",\n \"filter_by\": [\n {\n \"field\": \"resource\",\n \"op\": \"eq\",\n \"values\": [\n 1234\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"edge_status_2xx": 21095299,
"timestamp": 1623159320
},
{
"edge_download_speed": {
"0_250k": "0",
"250k_500k": "0",
"500k_750k": "0",
"750k_1M": "0",
"1M_2M": "0.09091",
"2M_3M": "0.1818",
"3M_4M": "0.1818",
"4M+": "0.5455"
},
"timestamp": 1623159380
}
]
}{
"status": 400,
"message": "validation failure list:\\ngroup_by.0 in body should be one of [resource cname]"
}{
"status": 500,
"message": "Internal Server Error"
}Get CDN metrics
import os
from gcore import Gcore
client = Gcore(
api_key=os.environ.get("GCORE_API_KEY"), # This is the default and can be omitted
)
cdn_metrics = client.cdn.metrics.list(
from_="2021-06-14T00:00:00Z",
metrics=["edge_status_2xx", "edge_status_3xx", "edge_status_4xx", "edge_status_5xx"],
to="2021-06-15T00:00:00Z",
)
print(cdn_metrics.data)package main
import (
"context"
"fmt"
"github.com/G-Core/gcore-go"
"github.com/G-Core/gcore-go/cdn"
"github.com/G-Core/gcore-go/option"
)
func main() {
client := gcore.NewClient(
option.WithAPIKey("My API Key"),
)
cdnMetrics, err := client.CDN.Metrics.List(context.TODO(), cdn.MetricListParams{
From: "2021-06-14T00:00:00Z",
Metrics: []string{"edge_status_2xx", "edge_status_3xx", "edge_status_4xx", "edge_status_5xx"},
To: "2021-06-15T00:00:00Z",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", cdnMetrics.Data)
}
curl --request POST \
--url https://api.gcore.com/cdn/advanced/v1/metrics \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"metrics": [
"edge_status_2xx",
"edge_status_3xx",
"edge_status_4xx",
"edge_status_5xx"
],
"from": "2021-06-14T00:00:00Z",
"to": "2021-06-15T00:00:00Z",
"group_by": [
"cname"
],
"granularity": "P1D",
"filter_by": [
{
"field": "resource",
"op": "eq",
"values": [
1234
]
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
metrics: ['edge_status_2xx', 'edge_status_3xx', 'edge_status_4xx', 'edge_status_5xx'],
from: '2021-06-14T00:00:00Z',
to: '2021-06-15T00:00:00Z',
group_by: ['cname'],
granularity: 'P1D',
filter_by: [{field: 'resource', op: 'eq', values: [1234]}]
})
};
fetch('https://api.gcore.com/cdn/advanced/v1/metrics', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.gcore.com/cdn/advanced/v1/metrics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'metrics' => [
'edge_status_2xx',
'edge_status_3xx',
'edge_status_4xx',
'edge_status_5xx'
],
'from' => '2021-06-14T00:00:00Z',
'to' => '2021-06-15T00:00:00Z',
'group_by' => [
'cname'
],
'granularity' => 'P1D',
'filter_by' => [
[
'field' => 'resource',
'op' => 'eq',
'values' => [
1234
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.gcore.com/cdn/advanced/v1/metrics")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"metrics\": [\n \"edge_status_2xx\",\n \"edge_status_3xx\",\n \"edge_status_4xx\",\n \"edge_status_5xx\"\n ],\n \"from\": \"2021-06-14T00:00:00Z\",\n \"to\": \"2021-06-15T00:00:00Z\",\n \"group_by\": [\n \"cname\"\n ],\n \"granularity\": \"P1D\",\n \"filter_by\": [\n {\n \"field\": \"resource\",\n \"op\": \"eq\",\n \"values\": [\n 1234\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gcore.com/cdn/advanced/v1/metrics")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"metrics\": [\n \"edge_status_2xx\",\n \"edge_status_3xx\",\n \"edge_status_4xx\",\n \"edge_status_5xx\"\n ],\n \"from\": \"2021-06-14T00:00:00Z\",\n \"to\": \"2021-06-15T00:00:00Z\",\n \"group_by\": [\n \"cname\"\n ],\n \"granularity\": \"P1D\",\n \"filter_by\": [\n {\n \"field\": \"resource\",\n \"op\": \"eq\",\n \"values\": [\n 1234\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"edge_status_2xx": 21095299,
"timestamp": 1623159320
},
{
"edge_download_speed": {
"0_250k": "0",
"250k_500k": "0",
"500k_750k": "0",
"750k_1M": "0",
"1M_2M": "0.09091",
"2M_3M": "0.1818",
"3M_4M": "0.1818",
"4M+": "0.5455"
},
"timestamp": 1623159380
}
]
}{
"status": 400,
"message": "validation failure list:\\ngroup_by.0 in body should be one of [resource cname]"
}{
"status": 500,
"message": "Internal Server Error"
}Authorizations
API key for authentication. Make sure to include the word apikey, followed by a single space and then your token.
Example: apikey 1234_abcdef
Body
Possible values:
edge_bandwidth- Bandwidth from client to CDN (bit/s.)edge_requests- Number of requests per interval (requests/s.)edge_requests_total- Total number of requests per interval.edge_status_1xx- Number of 1xx status codes from edge.edge_status_200- Number of 200 status codes from edge.edge_status_204- Number of 204 status codes from edge.edge_status_206- Number of 206 status codes from edge.edge_status_2xx- Number of 2xx status codes from edge.edge_status_301- Number of 301 status codes from edge.edge_status_302- Number of 302 status codes from edge.edge_status_304- Number of 304 status codes from edge.edge_status_3xx- Number of 3xx status codes from edge.edge_status_400- Number of 400 status codes from edge.edge_status_401- Number of 401 status codes from edge.edge_status_403- Number of 403 status codes from edge.edge_status_404- Number of 404 status codes from edge.edge_status_416- Number of 416 status codes from edge.edge_status_429- Number of 429 status codes from edge.edge_status_4xx- Number of 4xx status codes from edge.edge_status_500- Number of 500 status codes from edge.edge_status_501- Number of 501 status codes from edge.edge_status_502- Number of 502 status codes from edge.edge_status_503- Number of 503 status codes from edge.edge_status_504- Number of 504 status codes from edge.edge_status_505- Number of 505 status codes from edge.edge_status_5xx- Number of 5xx status codes from edge.edge_hit_ratio- Percent of cache hits (0.0 - 1.0).edge_hit_bytes- Number of bytes sent back when cache hits.origin_bandwidth- Bandwidth from CDN to Origin (bit/s.)origin_requests- Number of requests per interval (requests/s.)origin_status_1xx- Number of 1xx status from origin.origin_status_200- Number of 200 status from origin.origin_status_204- Number of 204 status from origin.origin_status_206- Number of 206 status from origin.origin_status_2xx- Number of 2xx status from origin.origin_status_301- Number of 301 status from origin.origin_status_302- Number of 302 status from origin.origin_status_304- Number of 304 status from origin.origin_status_3xx- Number of 3xx status from origin.origin_status_400- Number of 400 status from origin.origin_status_401- Number of 401 status from origin.origin_status_403- Number of 403 status from origin.origin_status_404- Number of 404 status from origin.origin_status_416- Number of 416 status from origin.origin_status_429- Number of 426 status from origin.origin_status_4xx- Number of 4xx status from origin.origin_status_500- Number of 500 status from origin.origin_status_501- Number of 501 status from origin.origin_status_502- Number of 502 status from origin.origin_status_503- Number of 503 status from origin.origin_status_504- Number of 504 status from origin.origin_status_505- Number of 505 status from origin.origin_status_5xx- Number of 5xx status from origin.edge_download_speed- Download speed from edge in KB/s (includes only requests that status was in the range [200, 300].)origin_download_speed- Download speed from origin in KB/s (includes only requests that status was in the range [200, 300].)
[
"edge_status_2xx",
"edge_status_3xx",
"edge_status_4xx",
"edge_status_5xx"
]
Beginning period to fetch metrics (ISO 8601/RFC 3339 format, UTC.)
Examples:
- 2021-06-14T00:00:00Z
- 2021-06-14T00:00:00.000Z
The total number of points, which is determined as the difference between "from" and "to" divided by "granularity", cannot exceed 1440. Exception: "speed" metrics are limited to 72 points.
"2021-06-14T00:00:00Z"
Specifies ending period to fetch metrics (ISO 8601/RFC 3339 format, UTC)
Examples:
- 2021-06-15T00:00:00Z
- 2021-06-15T00:00:00.000Z
The total number of points, which is determined as the difference between "from" and "to" divided by "granularity", cannot exceed 1440. Exception: "speed" metrics are limited to 72 points.
"2021-06-15T00:00:00Z"
Output data grouping.
Possible values:
- resource - Data is grouped by CDN resource.
- cname - Data is grouped by common names.
- region – Data is grouped by regions (continents.) Available for "speed" metrics only.
- isp - Data is grouped by ISP names. Available for "speed" metrics only.
["cname"]
Duration of the time blocks into which the data is divided. The value must correspond to the ISO 8601 period format.
Examples:
- P1D
- PT5M
Notes:
- The total number of points, which is determined as the difference between "from" and "to" divided by "granularity", cannot exceed 1440. Exception: "speed" metrics are limited to 72 points.
- For "speed" metrics the value must be a multiple of 5.
"P1D"
Each item represents one filter statement.
Show child attributes
Show child attributes
Response
Successful.
- object[]
- object
Show child attributes
Show child attributes
Was this page helpful?