Get analytics by time
Retrieves a list of aggregate metrics grouped by time interval.
Security
API Token
The preferred authorization scheme for interacting with the Cloudflare API. Create a token.
API Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
Accepted Permissions (at least one required)
Parameters
Used to filter rows by one or more dimensions. Filters can be combined using OR and AND boolean logic. AND takes precedence over OR in all the expressions. The OR operator is defined using a comma (,) or OR keyword surrounded by whitespace. The AND operator is defined using a semicolon (;) or AND keyword surrounded by whitespace. Note that the semicolon is a reserved character in URLs (rfc1738) and needs to be percent-encoded as %3B. Comparison options are:
| Operator | Name | URL Encoded |
|---|---|---|
| == | Equals | %3D%3D |
| != | Does not equals | !%3D |
| > | Greater Than | %3E |
| < | Less Than | %3C |
| >= | Greater than or equal to | %3E%3D |
| <= | Less than or equal to | %3C%3D |
Start of time interval to query, defaults to until - 6 hours. Timestamp must be in RFC3339 format and uses UTC unless otherwise specified.
Get analytics by time
import os
from cloudflare import Cloudflare
client = Cloudflare(
api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted
)
bytime = client.spectrum.analytics.events.bytimes.get(
zone_id="023e105f4ecef8ad9ca31a8372d0c353",
time_delta="minute",
)
print(bytime.data){
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"success": true,
"result": {
"data": [
{
"dimensions": [
"string"
],
"metrics": [
0
]
}
],
"data_lag": 3,
"max": {
"bytesEgress": 100,
"bytesIngress": 50
},
"min": {
"bytesEgress": 100,
"bytesIngress": 50
},
"query": {
"dimensions": [
"event",
"appID"
],
"filters": "event==disconnect%20AND%20coloName!=SFO",
"limit": 0,
"metrics": [
"count",
"bytesIngress"
],
"since": "2014-01-01T05:20:00.12345Z",
"sort": [
"+count",
"-bytesIngress"
],
"until": "2014-01-01T05:20:00.12345Z"
},
"rows": 5,
"totals": {
"bytesEgress": 100,
"bytesIngress": 50
},
"time_intervals": [
[
"2014-01-01T05:20:00.12345Z"
]
]
}
}Returns Examples
{
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"success": true,
"result": {
"data": [
{
"dimensions": [
"string"
],
"metrics": [
0
]
}
],
"data_lag": 3,
"max": {
"bytesEgress": 100,
"bytesIngress": 50
},
"min": {
"bytesEgress": 100,
"bytesIngress": 50
},
"query": {
"dimensions": [
"event",
"appID"
],
"filters": "event==disconnect%20AND%20coloName!=SFO",
"limit": 0,
"metrics": [
"count",
"bytesIngress"
],
"since": "2014-01-01T05:20:00.12345Z",
"sort": [
"+count",
"-bytesIngress"
],
"until": "2014-01-01T05:20:00.12345Z"
},
"rows": 5,
"totals": {
"bytesEgress": 100,
"bytesIngress": 50
},
"time_intervals": [
[
"2014-01-01T05:20:00.12345Z"
]
]
}
}