Get Object's Metrics History

GET /node/api/objects/:id/history

Returns object's history of metrics.

Permissions: objectPermissions.

Request parameters

Path parameters

Parameters

Type

Description

id

string

required

The ID of an object whose history should be retrieved.

Query parameters

Parameter

Type

Description

metrics

string

required

A comma-separated list of metrics to be retrieved.

from

string required

A lower-bound timestamp of metrics' values.

to

string optional

An upper-bound timestamp of metrics' values. If not specified, considered equal to your current local time.

timezone

string optional

A timezone of metrics' values. For example, Europe/Moscow. Use this parameter if a server's timezone doesn't match your local one and you need to get metrics without time shift.

downsample

string optional

A down-sampling parameter. For example, 1m-avg or 1h-avg denote "one minute average" and "one hour average" accordingly.

Response description

...

To get metrics available for an objects, use the Get Object Stat Metrics method.

Examples

Request examples

Provided that object_id is an ID of CPU, its average 1-hour load for 24 hours (26.01.20 12.00 PM - 27.01.20 12.00 PM) can be retrieved as follows:

Bash
JavaScript
NodeJS
Python
Bash
login=<...>
password=<...>
saymon_hostname=<...>
object_id=<...>
url=https://$saymon_hostname/node/api/objects/$object_id/history
curl -X GET $url -u $login:$password -G \
--data-urlencode "metrics=percentageUsage.combined" \
--data-urlencode "from=1580029200000" \
--data-urlencode "to=1580115600000" \
--data-urlencode "downsample=1h-avg"
JavaScript
let login = <...>
let password = <...>
let saymonHostname = <...>
let objectId = <...>
let queryParams =
"metrics=percentageUsage.combined" + "&" +
"from=1580029200000" + "&" +
"to=1580115600000" + "&" +
"downsample=1h-avg";
let path = "/node/api/objects/" + objectId + "/history" + "?" + queryParams;
let auth = "Basic " + btoa(login + ":" + password);
let headers = new Headers();
headers.append("Authorization", auth);
let requestOptions = {
method: "GET",
headers: headers
};
fetch(saymonHostname + path, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log("error", error));
NodeJS
const http = require("http");
const querystring = require("querystring");
let login = <...>
let password = <...>
let saymonHostname = <...>
let objectId = <...>
let queryParams = querystring.stringify({
metrics : "percentageUsage.combined",
from : "1580029200000",
to : "1580115600000",
downsample: "1h-avg"
});
let path = "/node/api/objects/" + objectId + "/history" + "?" + queryParams;
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let options = {
"method": "GET",
"hostname": saymonHostname,
"headers": {
"Authorization": auth
},
"path": path
};
let req = http.request(options, function (res) {
let chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
let body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
req.end();
Python
import requests
login = <...>
password = <...>
saymon_hostname = <...>
object_id = <...>
url = "https://" + saymon_hostname + "/node/api/objects/" + \
object_id + "/history"
params = {
"metrics": "percentageUsage.combined",
"from": "1580029200000",
"to": "1580115600000",
"downsample": "1h-avg"
}
response = requests.request("GET", url, auth=(login, password), params=params)
print(response.text)

Response example

[
{
"metric": "percentageUsage.combined",
"tags": {
"entity": "obj5e7dc67bc50bdc08abbf16ac"
},
"aggregateTags": [],
"dps": [
[
1585301160000,
6.626150080189077
],
[
1585301280000,
2.9540481400437635
],
...
]
}
]