This commit is contained in:
hubobel 2026-01-12 16:30:16 +01:00
parent 9b100825e7
commit d7e2e1a512
14 changed files with 190 additions and 1 deletions

View file

@ -0,0 +1,421 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 1,
"links": [],
"panels": [
{
"datasource": {
"type": "influxdb",
"uid": "cf9rc112kxds0c"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"showValues": false,
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 13,
"w": 24,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.3.1",
"targets": [
{
"datasource": {
"type": "influxdb",
"uid": "cf9rc112kxds0c"
},
"query": "from(bucket: \"Temperaturen\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"temperature\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"tC\")\r\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\r\n |> yield(name: \"mean\")",
"refId": "A"
}
],
"title": "Alle Sensoren",
"transparent": true,
"type": "timeseries"
},
{
"datasource": {
"type": "influxdb",
"uid": "cf9rc112kxds0c"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"fillOpacity": 80,
"gradientMode": "hue",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineWidth": 1,
"scaleDistribution": {
"type": "linear"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"max": 70,
"min": 10,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
},
{
"color": "red",
"value": 80
}
]
},
"unit": "celsius"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 13
},
"id": 2,
"options": {
"barRadius": 0.4,
"barWidth": 0.27,
"fullHighlight": false,
"groupWidth": 0.7,
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"orientation": "auto",
"showValue": "auto",
"stacking": "none",
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
},
"xTickLabelRotation": 0,
"xTickLabelSpacing": 200
},
"pluginVersion": "12.3.1",
"targets": [
{
"query": "from(bucket: \"Temperaturen\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"temperature\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"tC\")\r\n |> filter(fn: (r) => r[\"host\"] == \"982aebbfd808\")\r\n |> filter(fn: (r) => r[\"sensor_id\"] == \"100\")\r\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\r\n |> yield(name: \"mean\")",
"refId": "A"
}
],
"title": "100",
"type": "barchart"
},
{
"datasource": {
"type": "influxdb",
"uid": "cf9rc112kxds0c"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisGridShow": false,
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 26,
"gradientMode": "hue",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "smooth",
"lineWidth": 1,
"pointSize": 6,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"showValues": false,
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"max": 25,
"min": 10,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "dark-yellow",
"value": 0
},
{
"color": "red",
"value": 80
}
]
},
"unit": "celsius"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "tC {host=\"982aebbfd808\", sensor_id=\"100\", topic=\"daten/status/temperature:100\"}"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "dark-yellow",
"mode": "fixed"
}
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 13
},
"id": 3,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.3.1",
"targets": [
{
"query": "from(bucket: \"Temperaturen\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"temperature\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"tC\")\r\n |> filter(fn: (r) => r[\"host\"] == \"982aebbfd808\")\r\n |> filter(fn: (r) => r[\"sensor_id\"] == \"101\")\r\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\r\n |> yield(name: \"mean\")",
"refId": "A"
}
],
"title": "101",
"type": "timeseries"
},
{
"datasource": {
"type": "influxdb",
"uid": "cf9rc112kxds0c"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "dark-blue",
"value": 0
},
{
"color": "red",
"value": 40
}
]
},
"unit": "celsius"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "tC {host=\"982aebbfd808\", sensor_id=\"100\", topic=\"daten/status/temperature:100\"}"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "dark-blue",
"mode": "fixed"
}
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 21
},
"id": 4,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"text": {
"titleSize": 10,
"valueSize": 30
},
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "12.3.1",
"targets": [
{
"query": "from(bucket: \"Temperaturen\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"temperature\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"tC\")\r\n |> filter(fn: (r) => r[\"host\"] == \"982aebbfd808\")\r\n |> filter(fn: (r) => r[\"sensor_id\"] == \"102\")\r\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\r\n |> yield(name: \"mean\")",
"refId": "A"
}
],
"title": "102",
"transparent": true,
"type": "stat"
}
],
"preload": false,
"refresh": "5s",
"schemaVersion": 42,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "browser",
"title": "Shelly Temperaturen",
"uid": "grtkdqf",
"version": 12
}

View file

@ -0,0 +1,19 @@
services:
grafana:
image: grafana/grafana
container_name: grafana
restart: unless-stopped
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:3000/api/health" ]
interval: 5s
timeout: 3s
retries: 20
user: '0'
ports:
- '3000:3000'
volumes:
- /home/christof/grafana/storage/:/var/lib/grafana
networks:
default:
name: mqtt5-network
external: true

View file

@ -0,0 +1,22 @@
services:
influxdb:
image: influxdb:latest
restart: unless-stopped
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:8086/health" ]
interval: 5s
timeout: 3s
retries: 20
ports:
- '8086:8086'
volumes:
- /home/christof/influx/storage/:/var/lib/influxdb
environment:
- INFLUXDB_DB=db0
- INFLUXDB_ADMIN_USER=influx_user
- INFLUXDB_ADMIN_PASSWORD=influx_pw
networks:
default:
name: mqtt5-network
external: true

1
Pool/mqtt/Links Normal file
View file

@ -0,0 +1 @@
https://github.com/sukesh-ak/setup-mosquitto-with-docker

133
Pool/mqtt/README.md Normal file
View file

@ -0,0 +1,133 @@
# How to setup Mosquitto MQTT Broker using docker
These instructions will work on any Debian based OS including Ubuntu, RaspberryPi, WSL2 etc...
(For non-Debian distros, commands for installation need to be tweaked)
_By default the config allows only to use local connections for security reasons but since authentication is enabled below, that's not the case._
## 1. Install docker
Latest instructions are [here](https://docs.docker.com/engine/install/ubuntu/) on docker website.
You can also use this script - [install-docker.sh](/install-docker.sh)
## 2. Create base folder for mqtt configuration
```bash
mkdir mqtt5
cd mqtt5
# for storing mosquitto.conf and pwfile (for password)
mkdir config
```
## 3. Create Mosquitto config file - mosquitto.conf
```bash
nano config/mosquitto.conf
```
Basic configuration file content below including websocket config
```
allow_anonymous false
listener 1883
listener 9001
protocol websockets
persistence true
password_file /mosquitto/config/pwfile
persistence_file mosquitto.db
persistence_location /mosquitto/data/
```
## 4. Create Mosquitto password file - pwfile
```bash
touch config/pwfile
```
## 5. Create docker-compose file called 'docker-compose.yml'
```yml
version: "3.7"
services:
# mqtt5 eclipse-mosquitto
mqtt5:
image: eclipse-mosquitto
container_name: mqtt5
ports:
- "1883:1883" #default mqtt port
- "9001:9001" #default mqtt port for websockets
volumes:
- ./config:/mosquitto/config:rw
- ./data:/mosquitto/data:rw
- ./log:/mosquitto/log:rw
restart: unless-stopped
# volumes for mapping data,config and log
volumes:
config:
data:
log:
networks:
default:
name: mqtt5-network
```
## 6. Create and run docker container for MQTT
```bash
# In case you don't have docker-compose you can install it
sudo apt install docker-compose
# Run the docker container for mqtt
sudo docker-compose -p mqtt5 up -d
```
### Check if the container is up and working (note down container-id)
```bash
sudo docker ps
```
## 7. Create a user/password in the pwfile
```bash
# login interactively into the mqtt container
sudo docker exec -it <container-id> sh
# Create new password file and add user and it will prompt for password
mosquitto_passwd -c /mosquitto/config/pwfile user1
# Add additional users (remove the -c option) and it will prompt for password
mosquitto_passwd /mosquitto/config/pwfile user2
# delete user command format
mosquitto_passwd -D /mosquitto/config/pwfile <user-name-to-delete>
# type 'exit' to exit out of docker container prompt
```
Command line help for `mosquitto_passwd` command above
```
mosquitto_passwd is a tool for managing password files for mosquitto.
Usage: mosquitto_passwd [-H sha512 | -H sha512-pbkdf2] [-c | -D] passwordfile username
mosquitto_passwd [-H sha512 | -H sha512-pbkdf2] [-c] -b passwordfile username password
mosquitto_passwd -U passwordfile
-b : run in batch mode to allow passing passwords on the command line.
-c : create a new password file. This will overwrite existing files.
-D : delete the username rather than adding/updating its password.
-H : specify the hashing algorithm. Defaults to sha512-pbkdf2, which is recommended.
Mosquitto 1.6 and earlier defaulted to sha512.
-U : update a plain text password file to use hashed passwords
```
Then restart the container
```bash
sudo docker restart <container-id>
```

View file

@ -0,0 +1,8 @@
allow_anonymous false
listener 1883
listener 9001
protocol websockets
persistence true
password_file /mosquitto/config/pwfile
persistence_file mosquitto.db
persistence_location /mosquitto/data/

View file

@ -0,0 +1,26 @@
services:
# mqtt5 eclipse-mosquitto
mqtt5:
image: eclipse-mosquitto
container_name: mqtt5
healthcheck:
test: [ "CMD-SHELL", "mosquitto_pub -h localhost -p 1883 -u 'mqtt_user' -P 'mqtt_pw' -t 'healthcheck/ping' -n -q 0 >/dev/null 2>&1 || exit 1" ]
ports:
- "1883:1883" #default mqtt port
- "9001:9001" #default mqtt port for websockets
volumes:
- ./config:/mosquitto/config:rw
- ./data:/mosquitto/data:rw
- ./log:/mosquitto/log:rw
restart: unless-stopped
# volumes for mapping data,config and log
volumes:
config:
data:
log:
networks:
default:
name: mqtt5-network

2
Pool/telegraf/.env Normal file
View file

@ -0,0 +1,2 @@
MQTT_USERNAME=mqtt_user
MQTT_PASSWORD=mqtt_pw

View file

@ -0,0 +1,19 @@
services:
telegraf:
image: docker.io/telegraf:latest
container_name: telegraf
restart: unless-stopped
healthcheck:
test: [ "CMD-SHELL", "pidof telegraf >/dev/null 2>&1 || exit 1" ]
interval: 10s
timeout: 3s
retries: 12
environment:
- MQTT_USERNAME=${MQTT_USERNAME}
- MQTT_PASSWORD=${MQTT_PASSWORD}
volumes:
- ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
networks:
default:
name: mqtt5-network
external: true

View file

@ -0,0 +1,79 @@
# Configuration for telegraf agent
[agent]
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
## Override default hostname, if empty use os.Hostname()
hostname = ""
## If set to true, do no set the "host" tag in the telegraf agent.
omit_hostname = false
[[outputs.influxdb_v2]]
## The URLs of the InfluxDB cluster nodes.
urls = ["http://influx-influxdb-1:8086"]
## Token for authentication.
token = "1wml0Wzrno-VPHxw0N4CSJh42aTAE-zCCAnAj8BLY_YxsmexXO6_8o7i1HDdAPzDUndCCsejWKq9GJXeYFDhpQ=="
## Organization is the name of the organization you wish to write to; must exist.
organization = "Bischoffsheim"
## Destination bucket to write into.
bucket = "Temperaturen"
[[inputs.mqtt_consumer]]
servers = ["tcp://mqtt5:1883"]
topics = ["daten/status/+"] # deckt "daten/status/temperature:100" ab
qos = 1
persistent_session = true
client_id = "telegraf_mqtt_influx3"
username = "${MQTT_USERNAME}"
password = "${MQTT_PASSWORD}"
topic_tag = "topic"
data_format = "json_v2"
[[inputs.mqtt_consumer.json_v2]]
measurement_name = "temperature"
# id als Tag (saubere Gruppierung / Filter in Influx)
[[inputs.mqtt_consumer.json_v2.tag]]
path = "id"
rename = "sensor_id"
type = "int"
# Felder
[[inputs.mqtt_consumer.json_v2.field]]
path = "tC"
rename = "tC"
type = "float"
[[inputs.mqtt_consumer.json_v2.field]]
path = "tF"
rename = "tF"
type = "float"
[[inputs.mqtt_consumer]]
servers = ["tcp://mqtt5:1883"]
topics = ["daten/status/power/+"]
username = "${MQTT_USERNAME}"
password = "${MQTT_PASSWORD}"
data_format = "value"
data_type = "float"
name_override = "power"
topic_tag = "topic"