Get Object’s N Last Metrics

Returns a specified amount of recent metrics for an object.

Request

HTTP Request

GET /node/api/objects/:id/last

Permissions

objectPermissions

Path parameters

Parameters Type Description

id

String
required

The ID or discovery ID of the object whose metrics should be retrieved.

Query parameters

Parameter Type Description

metrics

String
required

A comma-separated list of metrics to retrieve.

length

Integer

Amount of last metrics to retrieve. If not specified, the request will return the last data point.

Request body

The request body is empty.

Response

Returns an array of requested metrics. Each metric contains the following fields:

Field Type Description

metric

String

Metric name.

tags.entity

String

The ID of the entity prefixed by the type of the entity. The format is objectxxx for objects and linkxxx for links.

aggregateTags

Array

Work In Progress

dps

Array<DataPoint>

An array of data points. Each data point is represented by an array that contains two values. The first one is a timestamp, the second one is value.

If you specify a non-existent metric in the metrics parameter or request metrics out of timestamp bounds (from 1 hour to 1 year), this request will return an empty history for that metric:

 {
     "metric": "ICMP",
     "tags": {
         "entity": ""
     },
     "aggregateTags": [],
     "dps": []
 }
To get all available metrics for an object, use the Get Object Stat Metrics method.

Example

Request

  • Bash

  • JavaScript

  • NodeJS

  • Python

login=<...>
password=<...>
saymon_hostname=<...>
object_id=<...>
url=https://$saymon_hostname/node/api/objects/$object_id/last

curl -X GET $url -u $login:$password -G \
    --data-urlencode "metrics=percentageUsage.combined" \
    --data-urlencode "length=5"
let login = <...>
let password = <...>
let saymonHostname = <...>
let objectId = <...>

let queryParams =
    "metrics=percentageUsage.combined" + "&" +
    "length=5"

let path = "/node/api/objects/" + objectId + "/last" + "?" + 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));
const http = require("http");
const querystring = require("querystring");

let login = <...>
let password = <...>
let saymonHostname = <...>
let objectId = <...>

let queryParams = querystring.stringify({
    metrics : "percentageUsage.combined",
    length : "5"
});

let path = "/node/api/objects/" + objectId + "/last" + "?" + 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();
import requests

login = <...>
password = <...>
saymon_hostname = <...>
object_id = <...>
url = "https://" + saymon_hostname + "/node/api/objects/" + \
    object_id + "/last"

params = {
"metrics": "percentageUsage.combined",
    "length": "5"
}

response = requests.request("GET", url, auth=(login, password), params=params)
print(response.text)

Response

[
    {
        "metric": "percentageUsage.combined",
        "tags": {
            "entity": "obj5e7dc67bc50bdc08abbf16ac"
        },
        "aggregateTags": [],
        "dps": [
                [
                    1680787492525,
                    4
                ],
                [
                    1680787512535,
                    4
                ],
                [
                    1680787522525,
                    4
                ],
                [
                    1680787542533,
                    4
                ],
                [
                    1680787552553,
                    4
                ]
            ]
    }
]