Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Change format of metric naming in writeApi.writePoint
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
AlexGodbehere committed Aug 2, 2023
1 parent 908b143 commit cc7e883
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/mqttclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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":
Expand All @@ -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":
Expand All @@ -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;

}
Expand Down

0 comments on commit cc7e883

Please sign in to comment.