DROP examples

The basis of each example of using the DROP rule is the mutually exclusive fields include and exclude.

It is recommended to extend the data table with all of the metrics with the first action. Otherwise the metrics which are not specified in the rules, will not be updated in the data table:

[
  {
    "actions": [
      {
        "type": "extend"
      }
    ]
  }
...
]

Example 1: Drop the specified metrics

Purpose: not to display static metrics in the Data table until the data are changed.

How to:

Step 1: In the section Monitoring configure the probe Program / script execution

In this example three metrics are displayed in the data table during the monitoring process: exitCode, stdout, stderr. The metric exitCode most of the time is "0" (the script execution completed). To make tracking changes of other metrics more convenient, the metric exitCode is hidden. But as soon as its value becomes different from "0", the metric should be displayed in the data table with the current value.

Step 2: Extend the data table with the metrics and drop the metric exitCode

[
  {
    "actions": [
      {
        "type": "extend"
      },
      {
        "type": "drop",
        "include": [
          "exitCode"
        ]
      }
    ]
  },
...
]

Step 3: Configure the conditions and the actions in the section Data forming rules

If exitCode is not equal to 0, then overwrite the metric with the current value in the table.

[
...
  {
    "conditions": [
      {
        "_field": {
          "name": "new.exitCode",
          "value": {
            "_neq": "0"
          }
        }
      }
    ],
    "actions": [
      {
        "type": "extend",
        "include": [
          "exitCode"
        ]
      }
    ]
  }
]

Example 2: Drop all metrics except those specified.

Purpose: to rename metric and update its value.

This is especially useful for visualizing values on a widget:

image

How to:

Step 1: In the Monitoring section configure the MQTT sensor

Monitoring of air temperature in a room is set up using the MQTT sensor. The data table displays metrics: topic and stdout.message, stdout.message is the temperature value. In the data table only this metric should be displayed with the current value and the name temperature.

Step 2: Extend the data table with all of the metrics

[
  {
    "actions": [
      {
        "type": "extend"
      }
    ]
  },
...
]

Step 3: Create the metric temperature and set its value from stdout.message

[
...
  {
    "actions": [
      {
        "type": "set",
        "field": "temperature",
        "value": "{{current.stdout.message}}"
      }
    ]
  },
...
]

Step 4: Drop all metrics except temperature

[
...
  {
    "actions": [
      {
        "type": "drop",
        "exclude": [
          "temperature"
        ]
      }
    ]
  }
]
image