LOG IN SIGN UP
Documentation

The Fastly Historical Stats API (i.e., the Stats API) is a RESTful API that allows Fastly customers to query historical caching stats such as number of requests, hit ratio, and number of errors. The Stats API provides an advanced querying interface that allows for fine grained time period, regional, and sampling control. This document provides a basic overview of Stats and documents all available endpoints.

Endpoint

The base endpoint for the Stats API is https://api.fastly.com/stats/. All URLs are relative to that endpoint. All requests must be sent over HTTPS.

Authentication

To authenticate, use a Fastly-Key header containing your API token, API key, or a session cookie.

Here's an example using the command-line tool cURL:

curl -H "Fastly-Key: YOUR_API_KEY" https://api.fastly.com/stats/usage

Query Options (Time Range, Sampling Rate, and Regions)

There are four query parameters that you can use to specify what information is returned by the stats API. The from and to parameters control the window over which you want to fetch stats information. The by controls the sampling rate (day, hour, or minute). And the region parameter allows you to restrict the result set to a particular region.

Param: from and to

The from and to parameters are exact times that control the window over which to fetch historical statistics. By default you can use UNIX timestamps when specifying these parameters, but many forms of human readable inputs are also available, such as:

Date parsing is performed using the Chronic ruby library; for the most detailed information on exactly what formats are available please visit the gem's GitHub page (https://github.com/mojombo/chronic).

Let's see some examples:

/stats?from=10+days+ago
Returns stats for each of your services, by day, for the last ten days
/stats?from=10+days+ago
Stats from Tuesday 14th May 2013 @ 20:29:37pm UTC to Thursday 16th May 2013 @ 20:29:37pm UTC
/stats?from=1%2F1%2F2013&to=2%2F1%2F2013/
Daily stats from January 1st, 2013 (1/1/2013) to February 1st, 2013

It is important to note that the from parameter is "inclusive" and the to parameter is "exclusive". This means that we will return only rows with recorded times that match the following inequality:

from <= recorded < to

NOTE: We store historical stats information using UTC, and not local time zones. This means that we will use the UTC interpretations of your inputs when querying stats information.

Param: by

The by parameter allows you to control the sampling rate used to produce the result set from querying the Stats API. There are three values that can be set:

If you do not provide a by parameter in your query it will default to 'day'. Each sampling rate also specifies default to and from parameters if you omit them:

Each value for the by parameter has associated defaults for the to and from parameters if they are omitted, here's an overview:

/stats
Defaults to: By day, from 1 month ago, to now
/stats?by=hour
Defaults to: by hour, from 1 day ago, to now
/stats?by=minute
Defaults to: by minute, from 30 minutes ago, to now

It is important to remember the following conversions when performing queries:

When changing the sampling rate via the by parameter you can accidentally ask for very large data sets if you have defined to and from parameters. We will not process exceedingly large queries. Please refer to the Response Format section below for more details.

Param: region

The Stats API also allows you to limit the scope of your query by restricting it to a particular region. This is achieved via the use of the region parameter. Currently the following regions are supported:

Usage is exceedingly simple, let's look at some examples:

/stats
Returns stats for all regions
/stats?region=usa
Returns stats for only US POPs
/stats?region=europe
Returns stats for European POPs only

The list of regions will always contain the ones listed above but may grow as Fastly expands into new parts of the globe. Because the list is dynamic, please use the following endpoint to get a list of all available regions:

GET /stats/regions
See the API section below for example output

It is important to note that not all regions are available to all customers at this time. If you need support for a particular region please feel free to contact us via our helpdesk.

Response Format

To make it easier to understand how a query is being processed we use a specific JSON response format. Here is an example:

/stats?from=1+day+ago
{
"status": "success",
"meta": {
"to": "Thu May 16 20:08:35 UTC 2013",
"from": "Wed May 15 20:08:35 UTC 2013",
"by": "day",
"region": "all"
},
"msg": null,
"data": [ ... ]
}

Each of the fields denotes the following:

Availability of Data

The collection and processing of statistics information from a globally distributed CDN, such as Fastly, is not instantaneous. Thus there will be a notable delay as to when certain sampling range information will be up to date. Here are the general guidelines:

  1. Minutely data will be delayed by roughly 10 to 15 minutes from the current time
  2. Hourly data will be delayed by the same amount, and the current hour will return a partial result (because the hour has not finished but we are incrementally aggregating data)
  3. Daily data works similarly to hourly data and the current day will also represent a partial result

API Reference

Historical Stats

Fields

field type description
requests integer Number of requests processed
hits integer Number of cache hits
hits_time float Amount of time spent processing cache hits (in seconds)
miss integer Number of cache misses
miss_time float Amount of time spent processing cache misses (in seconds)
pass integer Number of requests that passed through the CDN without being cached
errors integer Number of cache errors
hit_ratio float Ratio of cache hits to cache misses (between 0 and 1)
bandwidth integer Total bytes delivered (body_size + header_size)
body_size integer Total body bytes delivered
header_size integer Total header bytes delivered
uncacheable integer Number of requests that were denoted uncachable.
pipe integer Optional. Pipe operations performed (legacy feature)
status_200 integer Number of responses sent with status code 200 (Success)
status_204 integer Number of responses sent with status code 204 (No Content)
status_301 integer Number of responses sent with status code 301 (Moved Permanently)
status_302 integer Number of responses sent with status code 302 (Found)
status_304 integer Number of responses sent with status code 304 (Not Modified)
status_503 integer Number of responses sent with status code 503 (Service Unavailable)
status_1xx integer Number of "Informational" category status codes delivered
status_2xx integer "Success" status codes delivered
status_3xx integer "Redirection" codes delivered
status_4xx integer "Client Error" codes delivered
status_5xx integer "Server Error" codes delivered

Actions

GET /stats

Fetches historical stats for each of your fastly services and groups the results by service id.

Authentication

API key or session cookie.

Request Example
GET /stats?from=1+day+ago
Fastly-Key: d3cafb4dde4dbeef
Accept: application/json
Response Example
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"meta": {
"to": "Thu May 16 20:08:35 UTC 2013",
"from": "Wed May 15 20:08:35 UTC 2013",
"by": "day",
"region": "all"
},
"msg": null,
"data": {
"6ElZZvtumbwtLBDJvFwepx": [
{
"requests": "1925645",
"miss_time": "55.153864891000005",
"start_time": "1368662400",
"service_id": "6ElZZvtumbwtLBDJvFwepx",
"bandwidth": "176544526854",
"hits": "1902348",
"hits_time": "520.0779119150006",
"miss": "8354",
"body_size": "175900019026",
"pass": "4212",
"header_size": "644507828",
"status_200": "1208426",
"status_204": "0",
"status_301": "0",
"status_302": "0",
"status_304": "0",
"errors": "8418",
"hit_ratio": "0.9956",
"status_1xx": "0",
"status_2xx": "1208426",
"status_3xx": "0",
"status_4xx": "708801",
"status_503": "8418",
"pipe": "0",
"status_5xx": "8418",
"uncacheable": "0"
}
],
"5oYej0l0heMydtjaVPOq4z": [
{
"requests": "751",
"miss_time": "1.198163271",
"start_time": "1368662400",
"service_id": "5oYej0l0heMydtjaVPOq4z",
"bandwidth": "1159652",
"hits": "743",
"hits_time": "0.07059622299999999",
"miss": "8",
"body_size": "721082",
"pass": "0",
"header_size": "438570",
"status_200": "580",
"status_204": "0",
"status_301": "2",
"status_302": "0",
"status_304": "169",
"errors": "0",
"hit_ratio": "0.9893",
"status_1xx": "0",
"status_2xx": "580",
"status_3xx": "171",
"status_4xx": "0",
"status_503": "0",
"pipe": "0",
"status_5xx": "0",
"uncacheable": "0"
}
],
}
}

GET /stats/field/field

Fetches the specified field from the historical stats for each of your services and groups the results by service id.

Authentication

API key or session cookie.

Request Example
GET /stats/field/hit_ratio?from=6+hours+ago&to=3+hours+ago&by=hour
Fastly-Key: d3cafb4dde4dbeef
Accept: application/json
Response Example
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"meta": {
"to": "Thu May 16 17:13:03 UTC 2013",
"from": "Thu May 16 14:13:03 UTC 2013",
"by": "hour",
"region": "all"
},
"msg": null,
"data": {
"6ElZZvtumbwtLBDJvFwepx": [
{
"service_id": "6ElZZvtumbwtLBDJvFwepx",
"start_time": "1368716400",
"hit_ratio": "0.0000"
},
{
"service_id": "6ElZZvtumbwtLBDJvFwepx",
"start_time": "1368720000",
"hit_ratio": "0.9769"
},
{
"service_id": "6ElZZvtumbwtLBDJvFwepx",
"start_time": "1368723600",
"hit_ratio": "0.9944"
}
],
"5oYej0l0heMydtjaVPOq4z": [
{
"service_id": "5oYej0l0heMydtjaVPOq4z",
"start_time": "1368716400",
"hit_ratio": "0.9857"
},
{
"service_id": "5oYej0l0heMydtjaVPOq4z",
"start_time": "1368720000",
"hit_ratio": "1.0000"
},
{
"service_id": "5oYej0l0heMydtjaVPOq4z",
"start_time": "1368723600",
"hit_ratio": "1.0000"
}
]
}
}

GET /stats/aggregate

Fetches historical stats information aggregated across all of your Fastly services.

Authentication

API key or session cookie.

Request Example
GET /stats/aggregate?from=1368563377&to=1368736177
Fastly-Key: d3cafb4dde4dbeef
Accept: application/json
Response Example
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"meta": {
"to": "Thu May 16 20:29:37 UTC 2013",
"from": "Tue May 14 20:29:37 UTC 2013",
"by": "day",
"region": "all"
},
"msg": null,
"data": [
{
"requests": "7022557",
"miss_time": "43342.54711368301",
"start_time": "1368576000",
"bandwidth": "33656143431",
"hits": "1851903",
"hits_time": "284.90881923000006",
"miss": "74773",
"body_size": "31118762171",
"pass": "5076669",
"header_size": "2537381260",
"status_200": "6959769",
"status_204": "0",
"status_301": "3093",
"status_302": "60",
"status_304": "14135",
"errors": "21642",
"hit_ratio": "0.9612",
"status_1xx": "0",
"status_2xx": "6959769",
"status_3xx": "17288",
"status_4xx": "23855",
"status_503": "21631",
"pipe": "0",
"status_5xx": "21642",
"uncacheable": "0"
},
{
"requests": "7908607",
"miss_time": "31645.078110511986",
"start_time": "1368662400",
"bandwidth": "201478840738",
"hits": "3455867",
"hits_time": "751.2703607920007",
"miss": "114580",
"body_size": "198672905955",
"pass": "4310192",
"header_size": "2805934783",
"status_200": "7128395",
"status_204": "0",
"status_301": "2649",
"status_302": "30",
"status_304": "9920",
"errors": "41389",
"hit_ratio": "0.9679",
"status_1xx": "0",
"status_2xx": "7128395",
"status_3xx": "12599",
"status_4xx": "726224",
"status_503": "41246",
"pipe": "0",
"status_5xx": "41389",
"uncacheable": "0"
}
]
}

GET /stats/service/service_id

Fetches historical stats for a given service.

Authentication

API key or session cookie.

Request Example
GET /stats/service/1jlmtMz1ncwA0KC3TBGD0X?from=40+minutes+ago&to=38+minutes+ago&by=minute
Fastly-Key: d3cafb4dde4dbeef
Accept: application/json
Response Example
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"meta": {
"to": "Thu May 16 19:57:24 UTC 2013",
"from": "Thu May 16 19:55:24 UTC 2013",
"by": "minute",
"region": "all"
},
"msg": null,
"data": [
{
"requests": "21",
"miss_time": "0",
"start_time": "1368734160",
"service_id": "1jlmtMz1ncwA0KC3TBGD0X",
"bandwidth": "160238",
"hits": "0",
"hits_time": "0",
"miss": "0",
"body_size": "150948",
"pass": "19",
"header_size": "9290",
"status_200": "14",
"status_204": "0",
"status_301": "2",
"status_302": "0",
"status_304": "0",
"errors": "0",
"hit_ratio": null,
"status_1xx": "0",
"status_2xx": "14",
"status_3xx": "2",
"status_4xx": "5",
"status_503": "0",
"pipe": "0",
"status_5xx": "0",
"uncacheable": "0"
},
{
"requests": "20",
"miss_time": "0",
"start_time": "1368734220",
"service_id": "1jlmtMz1ncwA0KC3TBGD0X",
"bandwidth": "156504",
"hits": "0",
"hits_time": "0",
"miss": "0",
"body_size": "147806",
"pass": "17",
"header_size": "8698",
"status_200": "12",
"status_204": "0",
"status_301": "3",
"status_302": "0",
"status_304": "0",
"errors": "0",
"hit_ratio": null,
"status_1xx": "0",
"status_2xx": "12",
"status_3xx": "3",
"status_4xx": "5",
"status_503": "0",
"pipe": "0",
"status_5xx": "0",
"uncacheable": "0"
}
]
}

GET /stats/service/service_id/field/field

Fetches the specified field from the historical stats for a given service.

Authentication

API key or session cookie.

Request Example
GET /stats/service/1jlmtMz1ncwA0KC3TBGD0X/field/bandwidth?from=2+days+ago
Fastly-Key: d3cafb4dde4dbeef
Accept: application/json
Response Example
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"meta": {
"to": "Thu May 16 20:39:09 UTC 2013",
"from": "Tue May 14 20:39:09 UTC 2013",
"by": "day",
"region": "all"
},
"msg": null,
"data": [
{
"service_id": "1jlmtMz1ncwA0KC3TBGD0X",
"start_time": "1368576000",
"bandwidth": "376983356"
},
{
"service_id": "1jlmtMz1ncwA0KC3TBGD0X",
"start_time": "1368662400",
"bandwidth": "322029360"
}
]
}

GET /stats/usage

Returns usage information aggregated across all Fastly services and grouped by region.

Authentication

API key or session cookie.

Request Example
GET /stats/usage?from=1%2F1%2F2013&to=2%2F1%2F2013
Fastly-Key: d3cafb4dde4dbeef
Accept: application/json
Response Example
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"meta": {
"to": "Fri Feb 01 12:00:00 UTC 2013",
"from": "Tue Jan 01 12:00:00 UTC 2013",
"by": "day",
"region": "all"
},
"msg": null,
"data": {
"apac": {
"requests": "163546563",
"bandwidth": "10735282284"
},
"ausnz": {
"requests": "2888860",
"bandwidth": "173220202333"
},
"usa": {
"requests": "163546563",
"bandwidth": "153220202333"
},
"europe": {
"requests": "2888860",
"bandwidth": "10735282284"
}
}
}

GET /stats/usage_by_service

Returns usage information aggregated by service and grouped by service & region.

Authentication

API key or session cookie.

Request Example
GET /stats/usage_by_service?from=2%2F1%2F2013&to=3%2F1%2F2013
Fastly-Key: d3cafb4dde4dbeef
Accept: application/json
Response Example
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"meta": {
"to": "Fri Mar 01 12:00:00 UTC 2013",
"from": "Fri Feb 01 12:00:00 UTC 2013",
"by": "day",
"region": "all"
},
"msg": null,
"data": {
"apac": {
"1iPMGAF44YgzB7sINv4KTF": {
"requests": "60524",
"bandwidth": "6004223792"
},
"7mai6mbwRz0JXxhAY8ZSN2": {
"requests": "3",
"bandwidth": "1305"
}
},
"ausnz": {
"1iPMGAF44YgzB7sINv4KTF": {
"requests": "101120",
"bandwidth": "1735577606"
},
"7mai6mbwRz0JXxhAY8ZSN2": {
"requests": "93294",
"bandwidth": "38109995"
}
},
"usa": {
"1iPMGAF44YgzB7sINv4KTF": {
"requests": "1109033",
"bandwidth": "21642401706"
},
"7mai6mbwRz0JXxhAY8ZSN2": {
"requests": "348175",
"bandwidth": "173135847"
}
},
"europe": {
"1iPMGAF44YgzB7sINv4KTF": {
"requests": "567583",
"bandwidth": "14813592344"
},
"7mai6mbwRz0JXxhAY8ZSN2": {
"requests": "260025",
"bandwidth": "110928988"
}
}
}
}

GET /stats/regions

Fetches the list of codes for regions that are covered by the Fastly CDN service.

Authentication

API key or session cookie.

Request Example
GET /stats/regions
Fastly-Key: d3cafb4dde4dbeef
Accept: application/json
Response Example
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"meta": {
"to": "Thu May 16 19:52:15 UTC 2013",
"from": "Tue Apr 16 19:52:15 UTC 2013",
"by": "day",
"region": "all"
},
"msg": null,
"data": [
"apac",
"ausnz",
"usa",
"europe"
]
}