InfluxDB-Client library
Library to send metrics to InfluxDB
To allow javascript developers to send metrics in a easy way without worring about how to connect and how to build the metrics in the influxdb format, also the library has middleware for the developers that use expressjs, this middlewares will generate metrics default metrics that will allow us to collect data about the request like, latency, number of request, error, etc.
How to use it
To use the library you just need to follow the following steps
Install the library with npm
npm install @autobits/influxdb-client
Import the library
const influxdb_client = require('@autobits/influxdb-client');
Init client
influxdbClient.init({
influxdbToken: `9as7XXX==`,
influxdbOrg: `autobits.XXX`,
influxdbBucket: `autobits.systems's Bucket`,
influxdbURL: `https://XXX`,
appname: `MyAPP`,
debugMode: true
});
Collect default metrics
influxdbClient.trackServerHealth();
app.use(influxdbClient.requestMiddleware());
app.use(influxdbClient.errorMiddleware());
Collect custom metrics
fields = [
{ name: 'field1', value: 'OK', datatype: influxdbClient.FIELD_DATA_TYPES.STRING },
{ name: 'field2', value: 1234, datatype: influxdbClient.FIELD_DATA_TYPES.INT },
{ name: 'field3', value: '123.987', datatype: influxdbClient.FIELD_DATA_TYPES.FLOAT },
{ name: 'field4', value: true, datatype: influxdbClient.FIELD_DATA_TYPES.BOOLEAN }
];
tags = [
{ name: 'tag1', value: 'OK' },
{ name: 'tag2', value: 'THIS_IS_FINE' }
];
influxdbClient.writePoint('MyCustomPoint', fields, tags);
Close conection (should be invoked in the SIGTERM, SIGINT, SHUTDOWN handlers)
await influxdbClient.close();
});
Contributors
The original author and current lead maintainer of this module is the @autobits development team.
License
MIT