isomorphic-influx
A library for writing stats to InfluxDB 2.0. Metrics can fire from either a Node server backend or from a browser.
Key concepts
Be sure to review the key concepts from the Influx documentation (fields, tags). Be aware that this library only supports InfluxDB 2.0 metrics, and not InfluxDB 1.0.
Usage
import { writeMetric } from "isomorphic-influx";
writeMetric(
metricName,
(fieldSet = {}),
(tagSet = {}),
(INFLUXDB_ORG_ID = process.env.INFLUXDB_ORG_ID),
(INFLUXDB_BUCKET_ID = process.env.INFLUXDB_BUCKET_ID),
(INFLUXDB_SERVER_URL = process.env.INFLUXDB_SERVER_URL),
(INFLUXDB_TOKEN = process.env.INFLUXDB_TOKEN)
);
Under the hood, writeMetric
is simply a fetch
request, so you can chain a then
handler for the success case, or a catch
handler for request errors.
writeMetric(
"temperature_updates",
{
temperature: 72.0,
humidity: 50.0,
isFanOn: true
},
{
device_id: "raspberry-pi"
}
)
.then(() => {
console.log("Success!");
})
.catch(err => {
console.error("Error updating metric", err);
});