diff --git a/New dashboard-1745359029061.json b/New dashboard-1745359029061.json new file mode 100644 index 0000000..30c6d11 --- /dev/null +++ b/New dashboard-1745359029061.json @@ -0,0 +1,614 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "datasource", + "uid": "grafana" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 1, + "links": [], + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 8, + "panels": [], + "title": "Датчики", + "type": "row" + }, + { + "datasource": { + "type": "influxdb", + "uid": "P4B5EB7AC8565B06F" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "bars", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [ + { + "__systemRef": "hideSeriesFrom", + "matcher": { + "id": "byNames", + "options": { + "mode": "exclude", + "names": [ + "mqtt_consumer.mean" + ], + "prefix": "All except:", + "readOnly": true + } + }, + "properties": [ + { + "id": "custom.hideFrom", + "value": { + "legend": false, + "tooltip": false, + "viz": true + } + } + ] + } + ] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 1 + }, + "id": 6, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "hideZeros": false, + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "influxdb", + "uid": "P4B5EB7AC8565B06F" + }, + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "mqtt_consumer", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "topic::tag", + "operator": "=", + "value": "sensors/pressure/PRES1" + } + ] + } + ], + "title": "Давление", + "type": "timeseries" + }, + { + "datasource": { + "type": "influxdb", + "uid": "P4B5EB7AC8565B06F" + }, + "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", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "red", + "value": 0 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 1 + }, + "id": 1, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "hideZeros": false, + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "alias": "Target variable", + "datasource": { + "type": "influxdb", + "uid": "P4B5EB7AC8565B06F" + }, + "groupBy": [ + { + "params": [ + "10s" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "mqtt_consumer", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "topic::tag", + "operator": "=", + "value": "sensors/current/CUR1" + } + ] + } + ], + "title": "Значение тока", + "type": "timeseries" + }, + { + "datasource": { + "type": "influxdb", + "uid": "P4B5EB7AC8565B06F" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "left", + "barAlignment": 0, + "barWidthFactor": 0.3, + "drawStyle": "bars", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 9 + }, + "id": 9, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "timezone": [ + "browser" + ], + "tooltip": { + "hideZeros": false, + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "influxdb", + "uid": "P4B5EB7AC8565B06F" + }, + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "mqtt_consumer", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "topic::tag", + "operator": "=", + "value": "sensors/temperature/TEMP1" + } + ] + } + ], + "title": "Температура", + "type": "timeseries" + }, + { + "datasource": { + "type": "influxdb", + "uid": "P4B5EB7AC8565B06F" + }, + "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": "smooth", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 9 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "hideZeros": false, + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "alias": "Internal", + "datasource": { + "type": "influxdb", + "uid": "P4B5EB7AC8565B06F" + }, + "groupBy": [ + { + "params": [ + "10s" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "mqtt_consumer", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "topic::tag", + "operator": "=", + "value": "sensors/humidity/HUM1" + } + ] + } + ], + "title": "Влажность", + "type": "timeseries" + } + ], + "preload": false, + "refresh": "", + "schemaVersion": 41, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "New dashboard", + "uid": "fdmpyb3g9tz40b", + "version": 3 +} \ No newline at end of file diff --git a/root/assets/1.png b/root/assets/1.png new file mode 100644 index 0000000..473a469 Binary files /dev/null and b/root/assets/1.png differ diff --git a/root/assets/Pasted image 20250422233745.png b/root/assets/Pasted image 20250422233745.png new file mode 100644 index 0000000..dc8f0f7 Binary files /dev/null and b/root/assets/Pasted image 20250422233745.png differ diff --git a/root/assets/Pasted image 20250422234213.png b/root/assets/Pasted image 20250422234213.png new file mode 100644 index 0000000..764978b Binary files /dev/null and b/root/assets/Pasted image 20250422234213.png differ diff --git a/root/assets/Pasted image 20250422234913.png b/root/assets/Pasted image 20250422234913.png new file mode 100644 index 0000000..159bbfe Binary files /dev/null and b/root/assets/Pasted image 20250422234913.png differ diff --git a/root/assets/Pasted image 20250422235459.png b/root/assets/Pasted image 20250422235459.png new file mode 100644 index 0000000..85a254e Binary files /dev/null and b/root/assets/Pasted image 20250422235459.png differ diff --git a/root/assets/Pasted image 20250422235812.png b/root/assets/Pasted image 20250422235812.png new file mode 100644 index 0000000..a70fca7 Binary files /dev/null and b/root/assets/Pasted image 20250422235812.png differ diff --git a/root/assets/Pasted image 20250423002833.png b/root/assets/Pasted image 20250423002833.png new file mode 100644 index 0000000..c04a7d9 Binary files /dev/null and b/root/assets/Pasted image 20250423002833.png differ diff --git a/root/assets/Pasted image 20250423002855.png b/root/assets/Pasted image 20250423002855.png new file mode 100644 index 0000000..4870dfb Binary files /dev/null and b/root/assets/Pasted image 20250423002855.png differ diff --git a/root/assets/Pasted image 20250423003238.png b/root/assets/Pasted image 20250423003238.png new file mode 100644 index 0000000..ce5e0e8 Binary files /dev/null and b/root/assets/Pasted image 20250423003238.png differ diff --git a/root/assets/Pasted image 20250423003426.png b/root/assets/Pasted image 20250423003426.png new file mode 100644 index 0000000..2ebc246 Binary files /dev/null and b/root/assets/Pasted image 20250423003426.png differ diff --git a/root/assets/Pasted image 20250423003701.png b/root/assets/Pasted image 20250423003701.png new file mode 100644 index 0000000..f6325df Binary files /dev/null and b/root/assets/Pasted image 20250423003701.png differ diff --git a/root/assets/Pasted image 20250423003828.png b/root/assets/Pasted image 20250423003828.png new file mode 100644 index 0000000..60c5038 Binary files /dev/null and b/root/assets/Pasted image 20250423003828.png differ diff --git a/root/assets/Pasted image 20250423004001.png b/root/assets/Pasted image 20250423004001.png new file mode 100644 index 0000000..6965e70 Binary files /dev/null and b/root/assets/Pasted image 20250423004001.png differ diff --git a/root/assets/Pasted image 20250423005726.png b/root/assets/Pasted image 20250423005726.png new file mode 100644 index 0000000..d9cccaf Binary files /dev/null and b/root/assets/Pasted image 20250423005726.png differ diff --git a/root/report.md b/root/report.md new file mode 100644 index 0000000..acdbb7b --- /dev/null +++ b/root/report.md @@ -0,0 +1,61 @@ +## Генерация данных +### 1 - Sensor.py +Начинаем разработку с создания ООП файла `sensor.py` с 4-мя типами датчиков. Создаем родительский класс датчика - Sensor. + +![[1.png]] + +На его основе создаем 4 подкласса: температура, давление, ток и влажность. + +![[Pasted image 20250422233745.png]] + +### 2 - Main.py + +Создаем основной файл-клиент, который будет обеспечивать соединение с mqtt-брокером на второй машине. + +![[Pasted image 20250423002855.png]] + +### 3 - Сборка и запуск проекта + +В Dockerfile пошагово описываем сборку образа и создаем первый образ с помощью команды `docker build` + +![[Pasted image 20250422234913.png]] + +## 2 - MQTT брокер + +Для настройки протокола создаем файл `mosquitto.conf`. И описываем поднятие контейнера в compose-файле. +![[Pasted image 20250422235459.png]] + +Связь между контейнерами будет обеспечена благодаря внешней сети mqtt-net. + +Предварительно создаем ее с помощью команды: `docker network create mqtt-net --subnet=192.168.21.0/24 --gateway=192.168.21.1` + +и проверяем перед запуском основных контейнеров. + +![[Pasted image 20250422235812.png]] + +Создаем образ нашего брокера и запускаем его. После запускаем клиента и наблюдаем, что подключение прошло успешно. +![[Pasted image 20250423002833.png]] + +## 3 - Визуализация данных + +Создаем место, где будут храниться данные полученные от клиента. В конфигурационном файле _influxdb-init.iql_ прописываем: +![[Pasted image 20250423003238.png]] + +После чего настраиваем получение данных с помощью telegraf. +![[Pasted image 20250423003426.png]] + +Для отображения данных будем использовать grafana. +Разворачиваем все три контейнера с помощью docker-compose файла. +![[Pasted image 20250423003701.png]] + +Запуск прошел успешно. +![[Pasted image 20250423003828.png]] + +Займемся настройкой графического интерфейса перейдя по localhost:3000 +Видно, что данные генерируются, значит все контейнеры настроены корректно. + +![[Pasted image 20250423004001.png]] + +Смоделируем удобный дашборд для всех датчиков. + +![[Pasted image 20250423005726.png]] \ No newline at end of file diff --git a/root/vms/client/Dockerfile b/root/vms/client/Dockerfile new file mode 100644 index 0000000..17d7897 --- /dev/null +++ b/root/vms/client/Dockerfile @@ -0,0 +1,6 @@ +FROM python:alpine3.20 +WORKDIR /app +COPY requirements.txt . +RUN pip install -r requirements.txt +COPY . . +CMD ["python", "main.py"] diff --git a/root/vms/client/docker-compose.yml b/root/vms/client/docker-compose.yml new file mode 100644 index 0000000..adcd3ec --- /dev/null +++ b/root/vms/client/docker-compose.yml @@ -0,0 +1,48 @@ +services: + temp_sensor: + image: tremenbez/data + environment: + - SIM_HOST=192.168.21.10 + - SIM_NAME=TEMP1 + - SIM_PERIOD=5 + - SIM_TYPE=temperature + networks: + mqtt-net: + ipv4_address: 192.168.21.11 + + pressure_sensor: + image: tremenbez/data + environment: + - SIM_HOST=192.168.21.10 + - SIM_NAME=PRES1 + - SIM_PERIOD=10 + - SIM_TYPE=pressure + networks: + mqtt-net: + ipv4_address: 192.168.21.12 + + current_sensor: + image: tremenbez/data + environment: + - SIM_HOST=192.168.21.10 + - SIM_NAME=CUR1 + - SIM_PERIOD=3 + - SIM_TYPE=current + networks: + mqtt-net: + ipv4_address: 192.168.21.13 + + humidity_sensor: + image: tremenbez/data + environment: + - SIM_HOST=192.168.21.10 + - SIM_NAME=HUM1 + - SIM_PERIOD=7 + - SIM_TYPE=humidity + networks: + mqtt-net: + ipv4_address: 192.168.21.14 + +networks: + mqtt-net: + external: true \ No newline at end of file diff --git a/root/vms/client/files/__init__.py b/root/vms/client/files/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/root/vms/client/files/sensor.py b/root/vms/client/files/sensor.py new file mode 100644 index 0000000..96598c9 --- /dev/null +++ b/root/vms/client/files/sensor.py @@ -0,0 +1,78 @@ +import random +import math +import time + + +class Sensor: + value: float + name: str + type: str + + def __init__(self, name, interval): + self.name = name + self.interval = interval + self.value = None + + def generate_new_value(self): + pass + + def get_data(self): + return self.value + + def run(self): + """Запускает цикл генерации данных с заданным интервалом.""" + while True: + self.generate_new_value() + print(f"Sensor {self.name} ({self.type}): {self.value}") + time.sleep(self.interval) + + +class Temperature(Sensor): + step = 10 + + def __init__(self, name, interval): + super().__init__(name, interval) + self.type = "temperature" + + def generate_new_value(self): + """Генерирует новое значение температуры.""" + self.value = random.random() + self.step + 222 * 6 + + +class Pressure(Sensor): + step = 15 + + def __init__(self, name, interval): + super().__init__(name, interval) + self.type = "pressure" + + def generate_new_value(self): + """Генерирует новое значение давления.""" + self.value = random.random() + self.step + + +class Current(Sensor): + step = 20 + + def __init__(self, name, interval): + super().__init__(name, interval) + self.type = "current" + + def generate_new_value(self): + """Генерирует новое значение тока.""" + import math + self.value = math.sin(self.step) + self.step += 1 + + +class Humidity(Sensor): + step = 25 + + def __init__(self, name, interval): + super().__init__(name, interval) + self.type = "humidity" + + def generate_new_value(self): + """Генерирует новое значение влажности.""" + self.value = random.uniform(self.step, self.step + 20) + diff --git a/root/vms/client/main.py b/root/vms/client/main.py new file mode 100644 index 0000000..73cd01c --- /dev/null +++ b/root/vms/client/main.py @@ -0,0 +1,51 @@ +import paho.mqtt.client as paho +import time +import logging +from os import environ +from files.sensor import * + +# Настройка логирования +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +# Настройка переменных среды +broker = environ.get("SIM_HOST", "localhost") +port = int(environ.get("SIM_PORT", 1883)) +name = environ.get("SIM_NAME", "sensor") +period = int(environ.get("SIM_PERIOD", 1)) # SIM_PERIOD используется как interval +type_sim = environ.get("SIM_TYPE", "temperature") + +# Проверка допустимых типов датчиков +sensors = { + "temperature": Temperature, + "pressure": Pressure, + "current": Current, + "humidity": Humidity +} +if type_sim not in sensors: + raise ValueError(f"Unknown sensor type: {type_sim}. Allowed types: {list(sensors.keys())}") + +# Создание экземпляра датчика +sensor = sensors[type_sim](name=name, interval=period) + +# Callback для публикации +def on_publish(client, userdata, result): + print(f"Data published successfully: {userdata}") + +# Подключение к брокеру +client = paho.Client(sensor.name) +client.on_publish = on_publish +try: + client.connect(broker, port) +except Exception as e: + logging.error(f"Failed to connect to broker: {e}") + exit(1) + +# Публикация данных +while True: + try: + sensor.generate_new_value() + topic = f"sensors/{sensor.type}/{sensor.name}" + ret = client.publish("sensors/" + sensor.type + "/" + sensor.name, sensor.get_data()) + except Exception as e: + logging.error(f"Error during publishing: {e}") + time.sleep(period) \ No newline at end of file diff --git a/root/vms/client/mosquitto/mosquitto.conf b/root/vms/client/mosquitto/mosquitto.conf new file mode 100644 index 0000000..c8348ac --- /dev/null +++ b/root/vms/client/mosquitto/mosquitto.conf @@ -0,0 +1,2 @@ +listener 1883 +allow_anonymous true diff --git a/root/vms/client/requirements.txt b/root/vms/client/requirements.txt new file mode 100644 index 0000000..13e9d8e --- /dev/null +++ b/root/vms/client/requirements.txt @@ -0,0 +1 @@ +paho_mqtt==1.6.1 diff --git a/root/vms/gw/docker-compose.yml b/root/vms/gw/docker-compose.yml new file mode 100644 index 0000000..4103273 --- /dev/null +++ b/root/vms/gw/docker-compose.yml @@ -0,0 +1,15 @@ +services: + broker: + image: eclipse-mosquitto + container_name: broker + volumes: + - ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf + ports: + - "1883:1883" + networks: + mqtt-net: + ipv4_address: 192.168.21.10 + +networks: + mqtt-net: + external: true \ No newline at end of file diff --git a/root/vms/gw/mosquitto/mosquitto.conf b/root/vms/gw/mosquitto/mosquitto.conf new file mode 100644 index 0000000..daa4137 --- /dev/null +++ b/root/vms/gw/mosquitto/mosquitto.conf @@ -0,0 +1,2 @@ +listener 1883 +allow_anonymous true \ No newline at end of file diff --git a/root/vms/server/docker-compose.yml b/root/vms/server/docker-compose.yml new file mode 100644 index 0000000..edd8364 --- /dev/null +++ b/root/vms/server/docker-compose.yml @@ -0,0 +1,44 @@ +services: + influxdb: + image: influxdb:1.8 + container_name: influxdb + volumes: + - ./influxdb/scripts:/docker-entrypoint-initdb.d + - influx_data:/var/lib/influxdb + networks: + mqtt-net: + ipv4_address: 192.168.21.20 + + telegraf: + image: telegraf + container_name: telegraf + volumes: + - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro + networks: + mqtt-net: + ipv4_address: 192.168.21.21 + + grafana: + image: grafana/grafana + container_name: grafana + volumes: + - grafana_data:/var/lib/grafana + - ./grafana/datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml + environment: + - GF_SECURITY_ADMIN_USER=admin + - GF_SECURITY_ADMIN_PASSWORD=admin + - GF_USERS_ALLOW_SIGN_UP=false + restart: unless-stopped + ports: + - "3000:3000" + networks: + mqtt-net: + ipv4_address: 192.168.21.22 + +volumes: + influx_data: {} + grafana_data: {} + +networks: + mqtt-net: + external: true \ No newline at end of file diff --git a/root/vms/server/grafana/datasources.yaml b/root/vms/server/grafana/datasources.yaml new file mode 100644 index 0000000..d4e29dd --- /dev/null +++ b/root/vms/server/grafana/datasources.yaml @@ -0,0 +1,13 @@ +apiVersion: 1 + +datasources: + - name: InfluxDB_v1 + type: influxdb + access: proxy + database: sensors + user: telegraf + url: http://influxdb:8086 + jsonData: + httpMode: GET + secureJsonData: + password: telegraf \ No newline at end of file diff --git a/root/vms/server/influxdb/scripts/influxdb-init.iql b/root/vms/server/influxdb/scripts/influxdb-init.iql new file mode 100644 index 0000000..fceac30 --- /dev/null +++ b/root/vms/server/influxdb/scripts/influxdb-init.iql @@ -0,0 +1,2 @@ +CREATE DATABASE sensors; +CREATE USER telegraf WITH PASSWORD 'telegraf' WITH ALL PRIVILEGES; \ No newline at end of file diff --git a/root/vms/server/telegraf/telegraf.conf b/root/vms/server/telegraf/telegraf.conf new file mode 100644 index 0000000..037f90a --- /dev/null +++ b/root/vms/server/telegraf/telegraf.conf @@ -0,0 +1,14 @@ +[[inputs.mqtt_consumer]] + servers = ["tcp://broker:1883"] # Имя сервиса брокера + topics = [ + "sensors/#" + ] + data_format = "value" + data_type = "float" + +[[outputs.influxdb]] + urls = ["http://influxdb:8086"] # Имя сервиса InfluxDB + database = "sensors" + skip_database_creation = true + username = "telegraf" + password = "telegraf" \ No newline at end of file