MetricInfo - Scoped, Global
The MetricInfo API provides methods to check if a metric is in the MetricBase database, and if so, to report its retention policy. Retention policies are reported in minutes.
You can call this class in scoped and global server scripts. When using the MetricInfo class, use the sn_clotho namespace identifier.
This class is part of the MetricBase application.
MetricInfo – MetricInfo(String table, String metric)
Creates an instance of the MetricInfo class.
| Name | Type | Description |
|---|---|---|
| table | String | Metric table name listed in the Time Series Metrics [sys_metric] table. |
| metric | String | Metric field name listed in the Time Series Metrics [sys_metric] table. This field name must be mapped to the table name. |
The following example shows how to construct a MetricInfo object with the Altitude (mb_demo_mt_altitude) metric associated with the Drones [mb_demo_drone] table.
var metricInfo = new sn_clotho.MetricInfo('mb_demo_drone','mb_demo_mt_altitude');
MetricInfo – getRetentionSchedulesInMinutes()
Gets the retention policy schedules of the specified metric.
See also MetricBase retention policies.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Object | JSON object containing key-value pairs that represent the retention policy
schedules (in minutes) for the specified metric listed in the Retention Policies
[sys_metric_retention_policy] table. For each retention policy schedule belonging
to the metric, the object contains a corresponding key-value pair that maps the
retention duration to the sampling period.
|
The following example shows how to loop over the retention policy schedules and compile a log message. The message contains the retention durations converted from minutes to days with their corresponding sampling periods.
// Function to convert minutes to days
function toDays(minutes) {
return minutes / 60 / 24;
};
var metricInfo = new sn_clotho.MetricInfo('mb_demo_drone','mb_demo_mt_altitude');
var schedules = metricInfo.getRetentionSchedulesInMinutes();
var log = '';
// Compiles a log message with retention schedules
for (var duration in schedules) {
log += "Retention duration is: " + toDays(duration) +
" days, Sampling period is: " + schedules[duration] + " minutes\n";
}
gs.info(log);
Output:
Retention duration is: 8 days, Sampling period is: 1 minutes
Retention duration is: 94 days, Sampling period is: 10 minutes
Retention duration is: 397 days, Sampling period is: 60 minutes
MetricInfo – isValid()
Indicates whether the specified metric is mapped to the table defined in a MetricInfo object.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Boolean | Flag that indicates whether the metric specified in a MetricInfo object is mapped to the specified table. Valid values:
|
The following example shows how to check if the Altitude (mb_demo_mt_altitude) metric is in the Drones [mb_demo_drone] table, and return its retention schedule if it is. The example output reflects the policy duration in minutes mapped to its interval sampling period.
var metricInfo = new sn_clotho.MetricInfo('mb_demo_drone','mb_demo_mt_altitude');
if (metricInfo.isValid())
{
var retentionSchedules = metricInfo.getRetentionSchedulesInMinutes();
gs.info(JSON.stringify(retentionSchedules, null, 2));
}
else
{
gs.info("metricInfo is invalid");
}
Output:
{
"11520": 1,
"135360": 10,
"571680": 60
}