-
Notifications
You must be signed in to change notification settings - Fork 97
restful_api
You can find avaiable API endpoints supported by flask-profiler in this page. The endpoints are developed in the purpose of creating flask-profiler's web interface in which you can monitor measurements.
- End-point:
/api/measurements/
- Request Type:
HTTP GET
- Auth Required: No
In this example, you can find a http request which is supposed to fetch all measurements. Since you do not provide a date range filter, only the measurements recorded withing past 7 days will be sent.
GET /api/measurements/ HTTP/1.1
Host: domain.com
HTTP/1.1 200 OK
Date: Mon, 09 Dec 2013 14:18:47 GMT
{
"measurements": [
{
"args": [],
"context": {
"args": {},
"body": "",
"form": {},
"func": "listProducts",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, sdch",
"Accept-Language": "en-US,en;q=0.8,tr;q=0.6",
"Connection": "keep-alive",
"Content-Length": "",
"Content-Type": "",
"Host": "127.0.0.1:5000",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"
},
"url": "http://127.0.0.1:5000/products"
},
"elapsed": 3e-06,
"endedAt": 1444991539.945816,
"id": 95,
"kwargs": {},
"method": "GET",
"name": "/products",
"startedAt": 1444991539.945813
},
{
"args": [],
"context": {
"args": {},
"body": "",
"form": {},
"func": "listProducts",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, sdch",
"Accept-Language": "en-US,en;q=0.8,tr;q=0.6",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Content-Length": "",
"Content-Type": "",
"Host": "127.0.0.1:5000",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"
},
"url": "http://127.0.0.1:5000/products"
},
"elapsed": 2e-06,
"endedAt": 1444990084.131159,
"id": 94,
"kwargs": {},
"method": "GET",
"name": "/products",
"startedAt": 1444990084.131157
}
]
}
- End-point:
/api/measurements/
- Request Type:
HTTP GET
- Auth Required: No
You can get filtered list of measurements. Below the table presents possible filter keys. Using only one of them or combination keys is accepted.
Filter key | Description | Default |
---|---|---|
startedAt | unixtime: start date of measurements. | 7243600 (past 7 days) |
endedAt | unixtime: end date of measurements. e.g. 1444382227 | now |
method | string: method of measurements. e.g. POST | |
name | string: name of measurements. e.g. /api/products | |
elapsed | float: elapsed seconds of measurements. e.g. 0.5 | 0 |
To get measurements which took more than 3.5 or equal 3.5 seconds to be executed:
GET /api/measurements/filter/?elapsed=3.5 HTTP/1.1
To get measurements which took more than 3.5 or equal 3.5 seconds, and were executed through PUT or POST requests.
GET /api/measurements/filter/?elapsed=3.5&method=PUT,POST HTTP/1.1
To get measurements whose name is '/api/products', and which executed between 2015-10-14 00:00:00 (unixtime: 1444780800) and 2015-10-16 00:00:00 (unixtime: 1444953600):
GET /api/measurements/filter/?name=/api/products&startedAt=1444780800&endedAt=1444953600 HTTP/1.1
The response data format will be the same as in Get all.
- End-point:
/api/v1/measurements/grouped/
- Request Type:
HTTP GET
- Auth Required: No
Whereas filtering APIs returns a list of individual measurements , this grouped list contains measurement records grouped by their name+method values. The grouped API also provides count, average elapsed time, minimum elapsed time, maximum elapsed time for each grouped measurement.
Filtering on grouped measurements is also supported. The following filter keys ara availabile on grouped list: startedAt
, endedAt
, method
You can sort the list of grouped measurements by count
, avgElapsed
, minElapsed
, maxElapsed
The following request filters grouped measurements by date range, and sort the list ascending by avgElapsed
.
GET /api/v1/measurements/grouped/?startedAt=1444780800&endedAt=1444953600&sort=avgElapsed,asc HTTP/1.1
Host: domain.com
HTTP/1.1 200 OK
Date: Mon, 09 Dec 2013 14:18:47 GMT
{
"measurements": [
{
"method": "GET",
"name": "/api/products",
"count": 214,
"avgElapsed": 1.203,
"maxElapsed": 2.075,
"minElapsed": 0.807,
}, {
"method": "POST",
"count": 851,
"name": "/api/products",
"avgElapsed": 1.82,
"maxElapsed": 3.41,
"minElapsed": 1.33,
}, {
"method": "GET",
"name": "/api/products/promoted",
"count": 346,
"avgElapsed": 1.12,
"maxElapsed": 1.85,
"minElapsed": 0.52,
}
]
}
Another example:
measurements/grouped/?sort=count%2Cdesc&skip=0&limit=-1&startedAt=1444813906&endedAt=1445332306
api/measurements/grouped/?sort=maxElapsed%2Casc&skip=0&limit=-1&startedAt=1444813906&endedAt=1445332306
- End-point:
/api/v1/measurements/<id>
- Request Type:
HTTP GET
- Auth Required: No
To get all detailed of a specific measurement whose id value is known, you can use the following example:
The following request gets measurement whose id is "56168da96bb200684f92c117"
GET /api/v1/measurements/56168da96bb200684f92c117 HTTP/1.1
Host: domain.com
HTTP/1.1 200 OK
Date: Mon, 09 Dec 2013 14:18:47 GMT
{
"measurement": {
"method": "PUT",
"name": "/api/product/<productId>/comments",
"args": [],
"kwargs": {"productId": 412},
"elapsed": "0.051",
"endedAt": "1444318633.24",
"id": "56168da96bb200684f92c117",
"startedAt": "1444318633.24",
"context": {
"args": {},
"body": "",
"form": {"comment": "this is a value from a html form field"},
"func": "insertComment",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, sdch",
"Accept-Language": "en-US,en;q=0.8,tr;q=0.6",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Content-Length": "",
"Content-Type": "",
"Host": "127.0.0.1:5000",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"
},
"url": "http://127.0.0.1:5000/api/product/412/comments"
}
}
- End-point:
/api/v1/methodDistribution/
- Request Type:
HTTP GET
- Auth Required: No
To get the frequency distribution of methods in a specified time period, you can use the following example:
The following request gets distribution between 1444814238(timestamp) and 1445332638(timestamp).
GET /api/measurements/methodDistribution/?startedAt=1444814238&endedAt=1445332638 HTTP/1.1
Host: domain.com
HTTP/1.1 200 OK
Date: Mon, 09 Dec 2013 14:18:47 GMT
{
"distribution": {
"GET": 1558,
"PUT": 453,
"POST": 1213,
"DELETE": 389
}
}
- End-point:
/api/v1/timeseries/
- Request Type:
HTTP GET
- Auth Required: No
To get the time series of requests(measurements) over a specified time period, you can use the following example:
The following request gets time series of requests between 1444814238(timestamp) and 1445332638(timestamp).
GET /api/measurements/timeseries/?interval=daily&startedAt=1444814238&endedAt=1445332638
Host: domain.com
HTTP/1.1 200 OK
Date: Mon, 09 Dec 2013 14:18:47 GMT
{
"serie": {
"2015-10-14": 0,
"2015-10-15": 62,
"2015-10-16": 3,
"2015-10-17": 0,
"2015-10-18": 0,
"2015-10-19": 0,
"2015-10-20": 0
}
}
Another http get request example:
GET /api/measurements/timeseries/?interval=hourly&startedAt=1444814238&endedAt=1445332638
Host: domain.com