mirror of
https://github.com/LinoSchmidt/Allnet-Dashboard.git
synced 2026-03-20 18:21:16 +01:00
Kommentare hinzugefügt
This commit is contained in:
11
Dockerfile
11
Dockerfile
@@ -1,13 +1,18 @@
|
||||
# Benutze das offizielle Node.js-Image als Basis
|
||||
FROM node:alpine
|
||||
|
||||
# Setze das Arbeitsverzeichnis im Container
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Kopiere die Dateien in das Arbeitsverzeichnis
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY ./src .
|
||||
|
||||
# Installiere die Abhängigkeiten
|
||||
RUN npm install
|
||||
|
||||
# Öffne den Port 3000
|
||||
EXPOSE 3000
|
||||
|
||||
# Starte die Anwendung
|
||||
CMD ["node", "server.js"]
|
||||
@@ -6,4 +6,5 @@ Allnet Grafana Dashboard using InfluxDB as the Database.
|
||||
|
||||
- Projekt clonen
|
||||
- `.env` erstellen und mit den Daten aus `.env.example` befüllen
|
||||
- `INFLUXDB_TOKEN` mit einem zufälligen String befüllen
|
||||
- Ausführen: `docker-compose up -d`
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
// Lade die Umgebungsvariablen aus dem docker-compose.yml File
|
||||
const token = process.env.INFLUXDB_TOKEN
|
||||
const url = process.env.INFLUXDB_URL
|
||||
const org = process.env.INFLUXDB_ORG
|
||||
const bucket = process.env.INFLUXDB_BUCKET
|
||||
|
||||
// Importiere die benötigten Module
|
||||
const express = require('express');
|
||||
const {InfluxDB, Point} = require('@influxdata/influxdb-client')
|
||||
|
||||
// Erstelle eine Instanz von Express (Webserver)
|
||||
const app = express();
|
||||
|
||||
// Erstelle eine Instanz von InfluxDB (Datenbank)
|
||||
const client = new InfluxDB({url, token})
|
||||
let writeClient = client.getWriteApi(org, bucket, 'ns')
|
||||
|
||||
// Erstelle eine Variable, um die Sensordaten zu speichern
|
||||
let sensorData = [];
|
||||
|
||||
// Erstelle eine Route, um die Sensordaten zu empfangen
|
||||
app.post('/', (req, res) => {
|
||||
req.on('data', (data) => {
|
||||
// Teile die Daten in einzelne Sensoren auf und speichere sie in der Variable sensorData
|
||||
const sensoren = data.toString().split('&');
|
||||
sensorData = sensoren.map(sensor => {
|
||||
const [name, value] = sensor.split('=');
|
||||
@@ -24,6 +31,7 @@ app.post('/', (req, res) => {
|
||||
};
|
||||
});
|
||||
|
||||
// Schreibe die Sensordaten in die InfluxDB
|
||||
sensorData.forEach(sensor => {
|
||||
const point = new Point(sensor.name).floatField('value', parseFloat(sensor.value));
|
||||
writeClient.writePoint(point);
|
||||
@@ -33,6 +41,7 @@ app.post('/', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Starte den Webserver auf Port 3000
|
||||
app.listen(3000, () => {
|
||||
console.log('Server is running on port 3000');
|
||||
});
|
||||
Reference in New Issue
Block a user