From f9eba5ea722473fe10a34fa326cb1f9bb0f05574 Mon Sep 17 00:00:00 2001 From: Liudmi1a Date: Thu, 29 May 2025 20:02:30 +0300 Subject: [PATCH 01/35] Update README.md --- README.md | 62 ------------------------------------------------------- 1 file changed, 62 deletions(-) diff --git a/README.md b/README.md index 9e8a9c1..8b13789 100644 --- a/README.md +++ b/README.md @@ -1,63 +1 @@ -# Введение -Данная практика посвещена базовым принципам Docker. Для выполнения практики необходимо использовать 3 виртуальные машины Linux. -# Задание - -Необходимо развернуть следующую систему: - -![image](assets/images/DockerTask.png) - -Симуляторы сенсоров, развернутые в докер контейнерах, публикуют сообщения на Mqtt брокер. Сервис Consumer подписывается на все сообщение, -опубликованные в брокере, и заносит их в базу данных временных рядов. Сервис dashboard отображает графики полученных данных от сервисов. - -Для выполнения данного задания необходимо: -1. Использовать три виртуальные машины из предыдущей практики. Установить на каждой docker и docker-compose. - -2. Linux A. - 1. Разработать скрипты - симулятор технологических данных. Создать класс Sensor, а также наследников этого класса (указать 4 реально существующих типа датчиков, например, температура, давление, потребляемый ток). - 2. В основной программе реализовать клиента, который подключается к mqtt брокеру и публикует сообщения. - 3. Конфигурацию типов датчиков вывести через переменные среды - 4. Запуск реализовать с помощью докер контейнеров. Для запуска нескольких типов использовать docker-compose. - 5. В итоге сделать 4 типа датчиков, запустить 6 контейнеров разных типов, где задается: - * тип датчика - * название датчика - * дискретность публикации сообщений - * (ДОП ЗАДАЧА, НЕОБЯЗАТЕЛЬНО) тип формулы (подумайте как можно через конфигурацию повлиять на характер генерации нового числа) - * в формуле предусмотрите в качестве операнда дату вашего рождения (например умножение на год рождения или месяц) - * (ДОП ЗАДАЧА, НЕОБЯЗАТЕЛЬНО) тип топика (json формат (topic - /sensor/type, value {"name":"sensor1", "value": 22.4} ) или значение в конкретный топик (topic - /sensor/type/value, value - 22.4)) - 6. Залить на свою страницу в докерхаб созданный image контейнера в публичный репозиторий. - -3. Linux B - 1. Развернуть mosquitto брокер с помощью docker. Настроить проброс портов, необходимый для работы приложения. - 2. Настроить конфигурационный файл для брокера. Использовать volume для подгрузки файла в докер. - 3. В файрволе открыть порт, необходимый для работы брокера. -4. Linux C - 1. Развернуть influxdb (1.8 версия), telegraf, grafana с помощью docker-compose - 2. Настроить подписку телеграфа на mqtt топики брокера - 3. Сохранять все сообщения в influxdb - 4. В grafana вывести дашборды с текущими значениями всех датчиков и агрегированными показаниями (среднее значение по всем датчикам) - сделать скриншот - 5. Необходимо создать volume для каждого контейнера с конфигурационными файлами. (ДОП ЗАДАЧА, НЕОБЯЗАТЕЛЬНО) При пересоздании контейнеров конфигурация дашбордов должна сохранится (без самих данных). - 6. В конфигурационных файлах ссылаться по alias контейнеров (не по ip адресам) -5. При загрузки задания в гит репозиторий создать две ветки develop и master. В master загрузить только readme - задание. - В ветку develop - загружаем сделанное задание. Как только отправляете мне на проверку задание, создаете пул реквест в ветку мастер и назначаете меня ревьювером. Таким образом я смогу комментировать ваш репозиторий. -6. Оформить инструкцию в виде Markdown файла. Приложить конфигурационные файлы в репозиторий. - Критерием успеха выполнения задания будет являтся также написанная инструкция по запуску ваших контейнеров. То есть, если я загружу с докерхаба ваш image, запущу docker-compose файлы на своих виртуальных машинах, и при этом смогу зайти в интерфейс и посмотреть дашборд с потоком данных, то задание выполнено. - -Репозиторий оформить следующим образом: -- root - - assets - - images - картинки для отчета - - vms - - client - - simulator - код симулятора и докерфайл - - gateway - - mosquitto - папка с конфигом для mosquitto + sh скрипт по запуску докера - - server - - grafana - конфиги для тома графаны - - influxdb - конфиги для тома инфлукса - - telegraf - конфиги для тома телеграфа - - docker-compose.yml - - - report.md - Отчет markdown - -P.S. опираться можно на данную [статью](https://coderlessons.com/articles/programmirovanie/raspberry-pi-iot-datchiki-influxdb-mqtt-i-grafana) From 6f6c1e9ef000acedde44820f4a849e18d0afbd23 Mon Sep 17 00:00:00 2001 From: Liudmi1a Date: Thu, 29 May 2025 20:02:43 +0300 Subject: [PATCH 02/35] Delete vms directory --- vms/client/simulator/Dockerfile | 6 - vms/client/simulator/docker-compose.yml | 24 - vms/client/simulator/entity/__init__.py | 0 vms/client/simulator/entity/sensor.py | 54 - vms/client/simulator/main.py | 27 - vms/client/simulator/requirements.txt | 1 - vms/gateway/mosquitto/mosquitto.conf | 2 - vms/server/infra/docker-compose.yml | 42 - vms/server/infra/grafana/grafana.ini | 1119 -- .../provisioning/dashboards/default.yaml | 12 - .../grafana/provisioning/dashboards/mqtt.json | 150 - .../provisioning/datasources/default.yaml | 13 - .../infra/influxdb/scripts/influxdb-init.iql | 2 - vms/server/infra/telegraf/telegraf.conf | 9688 ----------------- 14 files changed, 11140 deletions(-) delete mode 100644 vms/client/simulator/Dockerfile delete mode 100644 vms/client/simulator/docker-compose.yml delete mode 100644 vms/client/simulator/entity/__init__.py delete mode 100644 vms/client/simulator/entity/sensor.py delete mode 100644 vms/client/simulator/main.py delete mode 100644 vms/client/simulator/requirements.txt delete mode 100644 vms/gateway/mosquitto/mosquitto.conf delete mode 100644 vms/server/infra/docker-compose.yml delete mode 100644 vms/server/infra/grafana/grafana.ini delete mode 100644 vms/server/infra/grafana/provisioning/dashboards/default.yaml delete mode 100644 vms/server/infra/grafana/provisioning/dashboards/mqtt.json delete mode 100644 vms/server/infra/grafana/provisioning/datasources/default.yaml delete mode 100644 vms/server/infra/influxdb/scripts/influxdb-init.iql delete mode 100644 vms/server/infra/telegraf/telegraf.conf diff --git a/vms/client/simulator/Dockerfile b/vms/client/simulator/Dockerfile deleted file mode 100644 index eb66b3a..0000000 --- a/vms/client/simulator/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM python:alpine3.19 -WORKDIR /app -COPY requirements.txt . -RUN pip install -r requirements.txt -COPY . . -CMD ["python", "main.py"] diff --git a/vms/client/simulator/docker-compose.yml b/vms/client/simulator/docker-compose.yml deleted file mode 100644 index b9e08bb..0000000 --- a/vms/client/simulator/docker-compose.yml +++ /dev/null @@ -1,24 +0,0 @@ -version: "3" - -services: - temp_sensor: - image: antonaleks/data-simulator - environment: - - SIM_HOST=192.168.1.1 - - SIM_NAME=TIRCAHL24 - - SIM_PERIOD=5 - - SIM_TYPE=temperature - pressure_sensor: - image: antonaleks/data-simulator - environment: - - SIM_HOST=192.168.1.1 - - SIM_NAME=PIRCAHL11 - - SIM_PERIOD=10 - - SIM_TYPE=pressure - current_sensor: - image: antonaleks/data-simulator - environment: - - SIM_HOST=192.168.1.1 - - SIM_NAME=A0_CURRENT - - SIM_PERIOD=1 - - SIM_TYPE=current diff --git a/vms/client/simulator/entity/__init__.py b/vms/client/simulator/entity/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/vms/client/simulator/entity/sensor.py b/vms/client/simulator/entity/sensor.py deleted file mode 100644 index 922fea5..0000000 --- a/vms/client/simulator/entity/sensor.py +++ /dev/null @@ -1,54 +0,0 @@ -import random - - -class Sensor: - value: float - name: str - type: str - - def __init__(self, name): - self.name = name - - def generate_new_value(self): - pass - - def get_data(self): - return self.value - - def __str__(self): - return {"type": self.type, "name": self.name, "value": self.value} - - -class Temperature(Sensor): - step = 25 - - def __init__(self, name): - super().__init__(name) - self.type = "temp" - - def generate_new_value(self): - self.value = random.random() + self.step - - -class Pressure(Sensor): - step = 55 - - def __init__(self, name): - super().__init__(name) - self.type = "pressure" - - def generate_new_value(self): - self.value = random.random() + self.step - 56.48 + 25 * 7 - - -class Current(Sensor): - step = 0 - - def __init__(self, name): - super().__init__(name) - self.type = "current" - - def generate_new_value(self): - import math - self.value = math.sin(self.step) - self.step = self.step + 1 diff --git a/vms/client/simulator/main.py b/vms/client/simulator/main.py deleted file mode 100644 index 4d17730..0000000 --- a/vms/client/simulator/main.py +++ /dev/null @@ -1,27 +0,0 @@ -import paho.mqtt.client as paho -from os import environ -import time - -from entity.sensor import * - -broker = "localhost" if "SIM_HOST" not in environ.keys() else environ["SIM_HOST"] -port = 1883 if "SIM_PORT" not in environ.keys() else int(environ["SIM_PORT"]) -name = "sensor" if "SIM_NAME" not in environ.keys() else environ["SIM_NAME"] -period = 1 if "SIM_PERIOD" not in environ.keys() else int(environ["SIM_PERIOD"]) -type_sim = "temperature" if "SIM_TYPE" not in environ.keys() else environ["SIM_TYPE"] -sensors = {"temperature": Temperature, "pressure": Pressure, "current": Current} - - -def on_publish(client, userdata, result): # create function for callback - print(f"data published {userdata}") - pass - - -sensor = sensors[type_sim](name=name) -client1 = paho.Client(sensor.name) # create client object -client1.on_publish = on_publish # assign function to callback -client1.connect(broker, port) # establish connection -while True: - sensor.generate_new_value() - ret = client1.publish("sensors/" + sensor.type + "/" + sensor.name, sensor.get_data()) # publish - time.sleep(period) diff --git a/vms/client/simulator/requirements.txt b/vms/client/simulator/requirements.txt deleted file mode 100644 index 13e9d8e..0000000 --- a/vms/client/simulator/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -paho_mqtt==1.6.1 diff --git a/vms/gateway/mosquitto/mosquitto.conf b/vms/gateway/mosquitto/mosquitto.conf deleted file mode 100644 index c8348ac..0000000 --- a/vms/gateway/mosquitto/mosquitto.conf +++ /dev/null @@ -1,2 +0,0 @@ -listener 1883 -allow_anonymous true diff --git a/vms/server/infra/docker-compose.yml b/vms/server/infra/docker-compose.yml deleted file mode 100644 index 94e705e..0000000 --- a/vms/server/infra/docker-compose.yml +++ /dev/null @@ -1,42 +0,0 @@ -version: "3" -services: - influxdb: - image: influxdb:1.8 - container_name: influxdb - volumes: - - ./influxdb/scripts:/docker-entrypoint-initdb.d - - influx_data:/var/lib/influxdb - networks: - - server-net - telegraf: - image: telegraf - container_name: telegraf - volumes: - - ./telegraf:/etc/telegraf:ro - restart: unless-stopped - networks: - - server-net - grafana: - image: grafana/grafana - container_name: grafana - volumes: - - grafana_data:/var/lib/grafana - - ./grafana/:/etc/grafana/ - - environment: - - GF_SECURITY_ADMIN_USER=admin - - GF_SECURITY_ADMIN_PASSWORD=admin - - GF_USERS_ALLOW_SIGN_UP=false - restart: unless-stopped - ports: - - 3000:3000 - networks: - - server-net - - -volumes: - influx_data: {} - grafana_data: {} - -networks: - server-net: {} \ No newline at end of file diff --git a/vms/server/infra/grafana/grafana.ini b/vms/server/infra/grafana/grafana.ini deleted file mode 100644 index 71abc3a..0000000 --- a/vms/server/infra/grafana/grafana.ini +++ /dev/null @@ -1,1119 +0,0 @@ -##################### Grafana Configuration Example ##################### -# -# Everything has defaults so you only need to uncomment things you want to -# change - -# possible values : production, development -;app_mode = production - -# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty -;instance_name = ${HOSTNAME} - -#################################### Paths #################################### -[paths] -# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used) -;data = /var/lib/grafana - -# Temporary files in `data` directory older than given duration will be removed -;temp_data_lifetime = 24h - -# Directory where grafana can store logs -;logs = /var/log/grafana - -# Directory where grafana will automatically scan and look for plugins -;plugins = /var/lib/grafana/plugins - -# folder that contains provisioning config files that grafana will apply on startup and while running. -;provisioning = conf/provisioning - -#################################### Server #################################### -[server] -# Protocol (http, https, h2, socket) -;protocol = http - -# The ip address to bind to, empty will bind to all interfaces -;http_addr = - -# The http port to use -;http_port = 3000 - -# The public facing domain name used to access grafana from a browser -;domain = localhost - -# Redirect to correct domain if host header does not match domain -# Prevents DNS rebinding attacks -;enforce_domain = false - -# The full public facing url you use in browser, used for redirects and emails -# If you use reverse proxy and sub path specify full url (with sub path) -;root_url = %(protocol)s://%(domain)s:%(http_port)s/ - -# Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons. -;serve_from_sub_path = false - -# Log web requests -;router_logging = false - -# the path relative working path -;static_root_path = public - -# enable gzip -;enable_gzip = false - -# https certs & key file -;cert_file = -;cert_key = - -# Unix socket path -;socket = - -# CDN Url -;cdn_url = - -# Sets the maximum time using a duration format (5s/5m/5ms) before timing out read of an incoming request and closing idle connections. -# `0` means there is no timeout for reading the request. -;read_timeout = 0 - -#################################### Database #################################### -[database] -# You can configure the database connection by specifying type, host, name, user and password -# as separate properties or as on string using the url properties. - -# Either "mysql", "postgres" or "sqlite3", it's your choice -;type = sqlite3 -;host = 127.0.0.1:3306 -;name = grafana -;user = root -# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;""" -;password = - -# Use either URL or the previous fields to configure the database -# Example: mysql://user:secret@host:port/database -;url = - -# For "postgres" only, either "disable", "require" or "verify-full" -;ssl_mode = disable - -# Database drivers may support different transaction isolation levels. -# Currently, only "mysql" driver supports isolation levels. -# If the value is empty - driver's default isolation level is applied. -# For "mysql" use "READ-UNCOMMITTED", "READ-COMMITTED", "REPEATABLE-READ" or "SERIALIZABLE". -;isolation_level = - -;ca_cert_path = -;client_key_path = -;client_cert_path = -;server_cert_name = - -# For "sqlite3" only, path relative to data_path setting -;path = grafana.db - -# Max idle conn setting default is 2 -;max_idle_conn = 2 - -# Max conn setting default is 0 (mean not set) -;max_open_conn = - -# Connection Max Lifetime default is 14400 (means 14400 seconds or 4 hours) -;conn_max_lifetime = 14400 - -# Set to true to log the sql calls and execution times. -;log_queries = - -# For "sqlite3" only. cache mode setting used for connecting to the database. (private, shared) -;cache_mode = private - -# For "mysql" only if lockingMigration feature toggle is set. How many seconds to wait before failing to lock the database for the migrations, default is 0. -;locking_attempt_timeout_sec = 0 - -################################### Data sources ######################### -[datasources] -# Upper limit of data sources that Grafana will return. This limit is a temporary configuration and it will be deprecated when pagination will be introduced on the list data sources API. -;datasource_limit = 5000 - -#################################### Cache server ############################# -[remote_cache] -# Either "redis", "memcached" or "database" default is "database" -;type = database - -# cache connectionstring options -# database: will use Grafana primary database. -# redis: config like redis server e.g. `addr=127.0.0.1:6379,pool_size=100,db=0,ssl=false`. Only addr is required. ssl may be 'true', 'false', or 'insecure'. -# memcache: 127.0.0.1:11211 -;connstr = - -#################################### Data proxy ########################### -[dataproxy] - -# This enables data proxy logging, default is false -;logging = false - -# How long the data proxy waits to read the headers of the response before timing out, default is 30 seconds. -# This setting also applies to core backend HTTP data sources where query requests use an HTTP client with timeout set. -;timeout = 30 - -# How long the data proxy waits to establish a TCP connection before timing out, default is 10 seconds. -;dialTimeout = 10 - -# How many seconds the data proxy waits before sending a keepalive probe request. -;keep_alive_seconds = 30 - -# How many seconds the data proxy waits for a successful TLS Handshake before timing out. -;tls_handshake_timeout_seconds = 10 - -# How many seconds the data proxy will wait for a server's first response headers after -# fully writing the request headers if the request has an "Expect: 100-continue" -# header. A value of 0 will result in the body being sent immediately, without -# waiting for the server to approve. -;expect_continue_timeout_seconds = 1 - -# Optionally limits the total number of connections per host, including connections in the dialing, -# active, and idle states. On limit violation, dials will block. -# A value of zero (0) means no limit. -;max_conns_per_host = 0 - -# The maximum number of idle connections that Grafana will keep alive. -;max_idle_connections = 100 - -# How many seconds the data proxy keeps an idle connection open before timing out. -;idle_conn_timeout_seconds = 90 - -# If enabled and user is not anonymous, data proxy will add X-Grafana-User header with username into the request, default is false. -;send_user_header = false - -# Limit the amount of bytes that will be read/accepted from responses of outgoing HTTP requests. -;response_limit = 0 - -# Limits the number of rows that Grafana will process from SQL data sources. -;row_limit = 1000000 - -#################################### Analytics #################################### -[analytics] -# Server reporting, sends usage counters to stats.grafana.org every 24 hours. -# No ip addresses are being tracked, only simple counters to track -# running instances, dashboard and error counts. It is very helpful to us. -# Change this option to false to disable reporting. -;reporting_enabled = true - -# The name of the distributor of the Grafana instance. Ex hosted-grafana, grafana-labs -;reporting_distributor = grafana-labs - -# Set to false to disable all checks to https://grafana.net -# for new versions (grafana itself and plugins), check is used -# in some UI views to notify that grafana or plugin update exists -# This option does not cause any auto updates, nor send any information -# only a GET request to http://grafana.com to get latest versions -;check_for_updates = true - -# Google Analytics universal tracking code, only enabled if you specify an id here -;google_analytics_ua_id = - -# Google Tag Manager ID, only enabled if you specify an id here -;google_tag_manager_id = - -# Rudderstack write key, enabled only if rudderstack_data_plane_url is also set -;rudderstack_write_key = - -# Rudderstack data plane url, enabled only if rudderstack_write_key is also set -;rudderstack_data_plane_url = - -# Rudderstack SDK url, optional, only valid if rudderstack_write_key and rudderstack_data_plane_url is also set -;rudderstack_sdk_url = - -# Rudderstack Config url, optional, used by Rudderstack SDK to fetch source config -;rudderstack_config_url = - -#################################### Security #################################### -[security] -# disable creation of admin user on first start of grafana -;disable_initial_admin_creation = false - -# default admin user, created on startup -;admin_user = admin - -# default admin password, can be changed before first start of grafana, or in profile settings -;admin_password = admin - -# used for signing -;secret_key = SW2YcwTIb9zpOOhoPsMm - -# current key provider used for envelope encryption, default to static value specified by secret_key -;encryption_provider = secretKey.v1 - -# list of configured key providers, space separated (Enterprise only): e.g., awskms.v1 azurekv.v1 -;available_encryption_providers = - -# disable gravatar profile images -;disable_gravatar = false - -# data source proxy whitelist (ip_or_domain:port separated by spaces) -;data_source_proxy_whitelist = - -# disable protection against brute force login attempts -;disable_brute_force_login_protection = false - -# set to true if you host Grafana behind HTTPS. default is false. -;cookie_secure = false - -# set cookie SameSite attribute. defaults to `lax`. can be set to "lax", "strict", "none" and "disabled" -;cookie_samesite = lax - -# set to true if you want to allow browsers to render Grafana in a ,