VictoriaMetrics als zusätzliche Datenbank-Option für Messwerte ergänzt (STORE/DBASE=victoria)
Dritte, zu mongo/influx exklusive Auswahl für die laufenden Messwerte. Schreibpfad nutzt das bestehende Influx-Line-Protocol unverändert (common/victoria_post.js); Lesepfad (sensorapi/databases/victoria.js + victoria2json.js) holt Rohdaten per VictoriaMetrics' /api/v1/export und bucketet/aggregiert stundenweise clientseitig, nach Mongo-Konvention (Stunden-Start als Label, kein Zeit-Shift nötig wie bei Influx). Scope bewusst auf die schon heute per DBASE umschaltbaren Funktionen begrenzt (getActData/getNoiseAVGData) - getAvgData/getLongAvg/getGeigerData bleiben wie bisher. Docker-Compose um victoriametrics-Service ergänzt (Retention explizit auf 100y gesetzt, da VictoriaMetrics sonst nach 1 Monat Daten löscht). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,7 +33,7 @@ const DBASE = process.env.DBASE || 'both'
|
||||
// Mehr als 4 bringt nichts: ab da liefert das Archiv nicht mehr schneller.
|
||||
const PARALLEL = parseInt(process.env.PARALLEL) || 4
|
||||
|
||||
const DATABASE = ['mongo', 'influx', 'both']
|
||||
const DATABASE = ['mongo', 'influx', 'victoria', 'both']
|
||||
|
||||
const DEVELOP = process.env.DEVELOP || false;
|
||||
const LIVE = (process.env.LIVE == "true") || true
|
||||
@@ -47,6 +47,7 @@ import axios from 'axios'
|
||||
import https from 'https'
|
||||
import * as mongo from '../common/mongo.js'
|
||||
import * as influx from '../common/influx_post.js'
|
||||
import * as victoria from '../common/victoria_post.js'
|
||||
import fs from 'fs'
|
||||
import csv from 'csvtojson'
|
||||
import pkg from './package.json' with { type: "json" }
|
||||
@@ -67,6 +68,8 @@ const newProps = []
|
||||
|
||||
// Sensor/Tag-Paare, deren Influx-Write fehlgeschlagen ist - Auswertung am Ende von main()
|
||||
const failedInfluxWrites = []
|
||||
// Sensor/Tag-Paare, deren VictoriaMetrics-Write fehlgeschlagen ist - Auswertung am Ende von main()
|
||||
const failedVictoriaWrites = []
|
||||
|
||||
const saveList = (list) => {
|
||||
fs.writeFileSync('data/list.json', JSON.stringify(list))
|
||||
@@ -397,6 +400,12 @@ async function enterOneSensorinDB(client, sid, erg, dataline, day, styp, args) {
|
||||
failedInfluxWrites.push({sensorid: sid, day: day})
|
||||
}
|
||||
}
|
||||
if ((args.database === 'victoria') && (dataline !== '')) {
|
||||
const ok = await victoria.victoriaWrite(dataline)
|
||||
if (!ok) {
|
||||
failedVictoriaWrites.push({sensorid: sid, day: day})
|
||||
}
|
||||
}
|
||||
if((args.database === 'both') || (args.database === 'mongo')) {
|
||||
if(erg.length !== 0) {
|
||||
await mongo.writeDataArray(client, mongo.dataCollName(styp), erg)
|
||||
@@ -507,7 +516,7 @@ function parse_cmdline(argv) {
|
||||
console.log(" will be used and endDate = startDate + 1 day")
|
||||
console.log(" -t sensorType: if given, only those sensors will be used; default: 'noise'");
|
||||
console.log(" allowed types: 'noise', 'radiactivity', 'pm' and 'thp'")
|
||||
console.log(" -d database: 'mongo', 'influx' or 'both'; default: 'both'")
|
||||
console.log(" -d database: 'mongo', 'influx', 'victoria' or 'both' ('both' = mongo + influx); default: 'both'")
|
||||
console.log(` -p parallel: number of sensors fetched at the same time; default: ${PARALLEL}`)
|
||||
console.log(" -v version: show version");
|
||||
console.log(" -h this help text");
|
||||
@@ -555,6 +564,13 @@ async function main() {
|
||||
}
|
||||
process.exitCode = 1 // damit cron/docker den Fehlschlag sieht
|
||||
}
|
||||
if (failedVictoriaWrites.length > 0) {
|
||||
logerror(`${failedVictoriaWrites.length} Victoria-Writes fehlgeschlagen - diese Daten fehlen in VictoriaMetrics:`)
|
||||
for (const f of failedVictoriaWrites) {
|
||||
logerror(` Sensor ${f.sensorid}, Tag ${f.day}`)
|
||||
}
|
||||
process.exitCode = 1 // damit cron/docker den Fehlschlag sieht
|
||||
}
|
||||
let dauer = starttime.diffNow('seconds').toObject().seconds * -1
|
||||
const duration1 = Duration.fromObject({ seconds: dauer });
|
||||
const output1 = duration1.toFormat('hh:mm:ss');
|
||||
|
||||
Reference in New Issue
Block a user