An example template:

{
    "sensors": [
        {
            "name": "opcua_node_aa",
            "monitoringService": "python /usr/local/teamviewer-iot-agent/monitoring/opc-ua/opc_ua_connect.py",
            "monitoringParams": "--url opc.tcp://myopcuahost:26543 --nodeId "opcua_node_id" --frequency 2",
            "metrics": [
                {
                    "name": "opcua_node_id",
                    "key": "opcua_node_id",
                    "valueType": "double",
                    "valueAnnotation": ""
                }
            ]
        },
        ...
    ]
}

JSON Schema for sensor objects

JSON Schema for monitoringParams objects

JSON Schema for metric objects

Monitoring configuration file

After the sensor/metric is registered by the agent, the agent auto-generates the parameters sensorId and metricId and adds them as properties to the configuration file.

📌Notes:

  • To avoid data loss. Before editing the configuration file, create a backup.
  • Avoid historical data loss. Do not change any sensorId or metricId after they are added to the configuration file.

Monitoring frequency

Monitoring frequency can be controlled either by the agent’s Monitoring Configuration File (parameterfrequency) or by your custom script. In the JSON Sensor (see example below), the frequency is specified by the configuration property, causing the agent to run your script every 10 seconds.

{
   "sensors": [{
        "name": "temperature_humidity_sensor1",
        "monitoringService": "/usr/local/teamvieweriot/sensors/temperature_humidity/monitor.sh",
        "monitoringParams": "sensor1 sdkCredential",
                "frequency": 10,
           "metrics": [{
              "name": "Temperature",
              "key": "temperature",
              "valueType": "double",
              "valueAnnotation": "C"
            }, {
                  "name": "Humidity",
              "key": "humidity",
                  "valueType": "double",
              "valueAnnotation": ""
            }]
        },
        ...
    ]
}

There may be scenarios where the frequency of the data collection should be set by your script rather than specified in the agent’s Monitoring Configuration File. In these scenarios, the parameter frequency in the configuration file should be left blank.

Use case: You want to monitor discrete events which don’t have a defined frequency (event-based metrics)

  • e.g. monitoring when a door is opened or closed
  • within your custom script, you subscribe to a message queue to get door movement events and print them to stdout.

Generic example:

var queue = new Queue();
queue.openConnection();
queue.createSubscription(callback);
 
function callback(value) {
     print {"key":value};
}

Use case: You want to set up high-frequency monitoring (e.g. 1 second)

Although this can be done by configuring the parameter frequency in the agent’s Monitoring Configuration File, an optimal solution may be to use a loop in your script to print new metric values every second.

Generic example:

var networkObject = new NetworkObject();
networkObject.openConnection();
 
try {
    while (true) {
    var value = networkObject.getValue();
    print {"key":value};
    sleep(1000);
    }
}
finally
{
  connection.close()
}