How to get minimum, maximum, and average values of metrics
You can get minimum, maximum, and average values of a given metric with the downsample
query parameter of the Get Object’s Metrics History or Get Link’s Metrics History requests.
Read OpenTSDB Available Aggregators article for more options.
import requests
# SAYMON settings
saymon_hostname = <...>
login = <...>
password = <...>
object_id = <...>
metric_name = <...>
from_timestamp = <...>
to_timestamp = <...>
options = {
'all-max': 'Maximum', # Selects the largest data point / Linear Interpolation
'all-avg': 'Average', # Averages the data points / Linear Interpolation
'all-min': 'Minimum', # Selects the smallest data point / Linear Interpolation
}
# Request URL
url = 'https://' + saymon_hostname + '/node/api/objects/' + object_id + '/history'
# Requesting data and printing results
for k, v in options.items():
params = {
'metrics': metric_name,
'from': from_timestamp,
'to': to_timestamp,
'downsample': k,
}
response = requests.request('GET', url, auth=(login, password), params=params).json()
print(v, ':', response[0]['dps'][0][1])
Output:
Maximum : 96.257
Average : 14.77778717734117
Minimum : 13.114