From cc7e883c2f62619b5e7853621a7a9c1617e2d874 Mon Sep 17 00:00:00 2001 From: Alex Godbehere Date: Wed, 2 Aug 2023 08:27:52 +0100 Subject: [PATCH] Change format of metric naming in writeApi.writePoint In the mqttclient.ts, the manner in which metrics were being named for writing points has been altered. Previously, an underscore was used to separate the core metric name and its associated type annotation (i.e `${metricName}_x`). This has been changed to use a colon instead (`${metricName}:x`. --- lib/mqttclient.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/mqttclient.ts b/lib/mqttclient.ts index 0eef6cb..783b655 100644 --- a/lib/mqttclient.ts +++ b/lib/mqttclient.ts @@ -296,6 +296,11 @@ export default class MQTTClient { // Get the path as everything behind the last / let path = birth.name.substring(0, birth.name.lastIndexOf("/")); + // Here we only currently store the InstanceUUID and SchemaUUID + // of the top-level birth certificate. It would be nice if we could + // also store the InstanceUUID and SchemaUUID of all nested schemas + // but unsure how to handle this in InfluxDB. + writeApi.useDefaultTags({ instance: birth.instance, schema: birth.schema, @@ -319,7 +324,7 @@ export default class MQTTClient { logger.warn(`${topic.address}/${path}/${metricName} should be a ${birth.type} but received ${numVal}. Not recording.`); return; } - writeApi.writePoint(new Point(`${metricName}_i`).intField('value', numVal)); + writeApi.writePoint(new Point(`${metricName}:i`).intField('value', numVal)); break; case "UInt8": case "UInt16": @@ -331,7 +336,7 @@ export default class MQTTClient { logger.warn(`${topic.address}/${path}/${metricName} should be a ${birth.type} but received ${numVal}. Not recording.`); return; } - writeApi.writePoint(new Point(`${metricName}_u`).uintField('value', numVal)); + writeApi.writePoint(new Point(`${metricName}:u`).uintField('value', numVal)); break; case "Float": case "Double": @@ -341,17 +346,17 @@ export default class MQTTClient { logger.warn(`${topic.address}/${path}/${metricName} should be a ${birth.type} but received ${numVal}. Not recording.`); return; } - writeApi.writePoint(new Point(`${metricName}_d`).floatField('value', numVal)); + writeApi.writePoint(new Point(`${metricName}:d`).floatField('value', numVal)); break; case "Boolean": if (typeof value != "boolean") { logger.warn(`${topic.address}/${path}/${metricName} should be a ${birth.type} but received ${value}. Not recording.`); return; } - writeApi.writePoint(new Point(`${metricName}_b`).booleanField('value', value)); + writeApi.writePoint(new Point(`${metricName}:b`).booleanField('value', value)); break; default: - writeApi.writePoint(new Point(`${metricName}_s`).stringField('value', value)); + writeApi.writePoint(new Point(`${metricName}:s`).stringField('value', value)); break; }