Move InfluxDB to if-block

f_influxdb-line-protocol
Ruakij 3 years ago
parent 1012001312
commit c09c6c29fb

@ -14,6 +14,7 @@ const { RegexBlockStream } = require("./streamHandler/RegexBlockStream.js");
const { PacketStreamFactory } = require("./streamHandler/PacketStreamFactory.js"); const { PacketStreamFactory } = require("./streamHandler/PacketStreamFactory.js");
const { PacketInfluxPointFactory } = require("./streamHandler/PacketInfluxPointFactory.js"); const { PacketInfluxPointFactory } = require("./streamHandler/PacketInfluxPointFactory.js");
const { InfluxPointWriter } = require("./streamHandler/InfluxPointWriter.js"); const { InfluxPointWriter } = require("./streamHandler/InfluxPointWriter.js");
const { InfluxDbLineProtocolWriter } = require("./streamHandler/InfluxDbLineProtocolWriter.js");
const userHelper = require("./helper/userHelper.js"); const userHelper = require("./helper/userHelper.js");
@ -42,31 +43,41 @@ if(errorMsg){
} }
(async function() { (async function() {
logger.info("Setup Influx.."); let pointWriter;
const influxDb = new InfluxDB({url: env.INFLUX_URL, token: env.INFLUX_TOKEN}); if(!env.USE_INFLUXDB_LINEPROTOCOL){
logger.info("Setup Influx..");
await InfluxChecks.checkHealth(influxDb) const influxDb = new InfluxDB({url: env.INFLUX_URL, token: env.INFLUX_TOKEN});
.then((res) => {return InfluxChecks.checkBucket(influxDb, {
org: env.INFLUX_ORG, await InfluxChecks.checkHealth(influxDb)
name: env.INFLUX_BUCKET .then((res) => {return InfluxChecks.checkBucket(influxDb, {
});}) org: env.INFLUX_ORG,
.then((res) => {return InfluxChecks.checkWriteApi(influxDb, { name: env.INFLUX_BUCKET
org: env.INFLUX_ORG, });})
bucket: env.INFLUX_BUCKET .then((res) => {return InfluxChecks.checkWriteApi(influxDb, {
});}) org: env.INFLUX_ORG,
.catch((err) => { bucket: env.INFLUX_BUCKET
if(err) { });})
logger.error("Error whilst checking influx:"); .catch((err) => {
logger.error(err); if(err) {
} logger.error("Error whilst checking influx:");
logger.fatal("Setup influx failed!"); logger.error(err);
exit(1); }
}); logger.fatal("Setup influx failed!");
exit(1);
});
logger.debug("Get WriteApi & set default-hostname to", `'${env.HOSTNAME}'`);
const influxWriteApi = influxDb.getWriteApi(env.INFLUX_ORG, env.INFLUX_BUCKET, "us");
//influxWriteApi.useDefaultTags({"hostname": env.HOSTNAME});
logger.debug("Get WriteApi & set default-hostname to", `'${env.HOSTNAME}'`); pointWriter = new InfluxPointWriter(influxWriteApi);
const influxWriteApi = influxDb.getWriteApi(env.INFLUX_ORG, env.INFLUX_BUCKET, "us");
//influxWriteApi.useDefaultTags({"hostname": env.HOSTNAME}); logger.info("Influx ok");
logger.info("Influx ok"); }
else {
logger.info("Setup Influxdb-LineProtocol..");
}
logger.info("Starting tcpdump.."); logger.info("Starting tcpdump..");
const TCPDUMP_BASECMD = "tcpdump -vvv -e -n -X -s0 -i"; const TCPDUMP_BASECMD = "tcpdump -vvv -e -n -X -s0 -i";

Loading…
Cancel
Save