Skip to content

Instantly share code, notes, and snippets.

@labajo
Created July 4, 2020 11:24
Show Gist options
  • Save labajo/727846d2327a2e26b638ca92832e6f3c to your computer and use it in GitHub Desktop.
Save labajo/727846d2327a2e26b638ca92832e6f3c to your computer and use it in GitHub Desktop.
DockerStation Metrics
var sensors = require("snsr");
const Influx = require('influxdb-nodejs');
const client = new Influx('http://localhost:8086/physicalHost');
var tempSensors = [
'Package id 0',
'Core 0',
'Core 1',
'Core 2',
'Core 3'
];
var inSensors = [
'Vcore',
'+3.3V',
'3VSB',
'Vbat'
];
const fieldSchema = {
c0: 'f',
c1: 'f',
c2: 'f',
c3: 'f',
p0: 'f',
vcore: 'f',
volt33: 'f',
vsb3: 'f',
vbat: 'f'
};
const tagSchema = {
state: ['ok', 'critical']
};
sensors(function(err, data){
var measurements = {
temp: {},
voltages: {}
};
data.forEach(sensor => {
var sensorName = sensor['_sensor'];
if (sensor['_type'] === 'temp' && tempSensors.includes(sensorName)) {
measurements.temp[sensorName] = sensor.input;
} else if (sensor['_type'] === 'in' && inSensors.includes(sensorName)) {
measurements.voltages[sensorName] = sensor.input;
}
});
client.schema('sensor', fieldSchema, tagSchema, {
// default is false
stripUnknown: true,
});
client.write('sensor').tag({
state: 'ok',
}).field({
c0: measurements.temp['Core 0'],
c1: measurements.temp['Core 1'],
c2: measurements.temp['Core 2'],
c3: measurements.temp['Core 3'],
p0: measurements.temp['Package id 0'],
vcore: measurements.voltages['Vcore'],
volt33: measurements.voltages['+3.3V'],
vsb3: measurements.voltages['3VSB'],
vbat: measurements.voltages['Vbat']
}).then(() => {
console.info('write point success');
}).catch(console.error);
// console.log(measurements);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment