mc-tracker/src/influx/influx.ts

35 lines
751 B
TypeScript
Raw Normal View History

2024-01-03 07:25:17 +00:00
import { InfluxDB, Point, WriteApi } from "@influxdata/influxdb-client";
import Config from "../../data/config.json";
import { logger } from "../utils/logger";
export default class Influx {
private influx: InfluxDB;
private writeApi: WriteApi;
constructor() {
logger.info("Loading influx database");
this.influx = new InfluxDB({
url: Config.influx.url,
token: Config.influx.token,
});
this.writeApi = this.influx.getWriteApi(
Config.influx.org,
Config.influx.bucket,
"ms"
);
2024-01-03 09:46:46 +00:00
logger.info("InfluxDB initialized");
2024-01-03 07:25:17 +00:00
}
/**
* Write a point to the database.
*
* @param point the point to write
*/
2024-01-03 09:46:46 +00:00
public writePoint(point: Point) {
2024-01-03 07:25:17 +00:00
this.writeApi.writePoint(point);
}
}