---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# MetricInfo - Scoped, Global

# MetricInfo - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read

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](https://www.servicenow.com/docs/access?context=metricbase&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US)
application.

## MetricInfo -- MetricInfo(String table, String metric) {#ariaid-title2}

Creates an instance of the MetricInfo class.
{#MI-metricInfo__table_nff_zl3_fsb__entry__3}

| 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. |
[Table 1. Parameters]

{#MI-metricInfo__table_nff_zl3_fsb}  
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() {#ariaid-title3}

Gets the retention policy schedules of the specified metric.
See also [MetricBase retention
policies](https://www.servicenow.com/docs/access?context=metricbase-retention-policies&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US).
{#MI-getRetentionSchedulesInMinutes__table_qjl_vk3_fsb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 2. Parameters]

{#MI-getRetentionSchedulesInMinutes__table_qjl_vk3_fsb} {#MI-getRetentionSchedulesInMinutes__table_rjl_vk3_fsb__entry__2}

| 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. * Key -- Retention duration of the retention policy schedule in minutes.Data type: String * Value -- Sampling period of the retention policy schedule in minutes.Data type: Number {#MI-getRetentionSchedulesInMinutes__ul_fzj_br4_vsb} "<retentionDuration>": <samplingPeriod> |
[Table 3. Returns]

{#MI-getRetentionSchedulesInMinutes__table_rjl_vk3_fsb}  
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() {#ariaid-title4}

Indicates whether the specified metric is mapped to the table defined in a
MetricInfo object.
{#MI-isValid__table_xqf_xk3_fsb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 4. Parameters]

{#MI-isValid__table_xqf_xk3_fsb} {#MI-isValid__table_yqf_xk3_fsb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the metric specified in a MetricInfo object is mapped to the specified table. Valid values: * true: Specified metric is valid. * false: Specified metric or table either does not exist or the metric is not mapped to the table. {#MI-isValid__ul_rm4_qn3_fsb} |
[Table 5. Returns]

{#MI-isValid__table_yqf_xk3_fsb}  
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
    }


