-
Notifications
You must be signed in to change notification settings - Fork 0
/
metric.js
33 lines (29 loc) · 927 Bytes
/
metric.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const METRICS_PREFIX = 'teleinfo_';
const monitoredMetricTypes = {
ISOUSC: 'amperes', // "Intensité souscrite" : A
BASE: 'wattshour', // "Index option Base" : Wh
IINST: 'amperes', // "Intensité Instantanée" : A
IMAX: 'amperes', // "Intensité maximale appelée" : A
PAPP: 'voltsamperes', // "Puissance apparente" : VA
};
module.exports = class Metric {
constructor(name, value) {
this.name = name;
this.value = value;
}
get monitored() {
return Object.keys(monitoredMetricTypes).includes(this.name);
}
static fromEURIDISLine(line) {
const match = /^(?<name>\S*) (?<value>\S*).*$/.exec(line);
if (!match) {
return undefined;
}
const { name, value } = match.groups;
return new Metric(name, value);
}
toPrometheusMetric() {
const unit = monitoredMetricTypes[this.name];
return `${METRICS_PREFIX}${this.name.toLowerCase()}_${unit} ${this.value}`;
}
};