diff --git a/assets/images/1- version A.PNG b/assets/images/1- version A.PNG new file mode 100644 index 0000000..44b284a Binary files /dev/null and b/assets/images/1- version A.PNG differ diff --git a/assets/images/1- version B.PNG b/assets/images/1- version B.PNG new file mode 100644 index 0000000..079c733 Binary files /dev/null and b/assets/images/1- version B.PNG differ diff --git a/assets/images/1- version c.PNG b/assets/images/1- version c.PNG new file mode 100644 index 0000000..a4649c3 Binary files /dev/null and b/assets/images/1- version c.PNG differ diff --git a/assets/images/2 -4 run mosquitto on vm2.PNG b/assets/images/2 -4 run mosquitto on vm2.PNG new file mode 100644 index 0000000..f44409d Binary files /dev/null and b/assets/images/2 -4 run mosquitto on vm2.PNG differ diff --git a/assets/images/2-1.PNG b/assets/images/2-1.PNG new file mode 100644 index 0000000..da29305 Binary files /dev/null and b/assets/images/2-1.PNG differ diff --git a/assets/images/2-2.PNG b/assets/images/2-2.PNG new file mode 100644 index 0000000..4b8268a Binary files /dev/null and b/assets/images/2-2.PNG differ diff --git a/assets/images/2-3.PNG b/assets/images/2-3.PNG new file mode 100644 index 0000000..cd110b4 Binary files /dev/null and b/assets/images/2-3.PNG differ diff --git a/assets/images/3- 6 test sensor.PNG b/assets/images/3- 6 test sensor.PNG new file mode 100644 index 0000000..e39a93b Binary files /dev/null and b/assets/images/3- 6 test sensor.PNG differ diff --git a/assets/images/3-1 test sensor.PNG b/assets/images/3-1 test sensor.PNG new file mode 100644 index 0000000..01e4f29 Binary files /dev/null and b/assets/images/3-1 test sensor.PNG differ diff --git a/assets/images/3-2 -1 tesetsensor.PNG b/assets/images/3-2 -1 tesetsensor.PNG new file mode 100644 index 0000000..20e135f Binary files /dev/null and b/assets/images/3-2 -1 tesetsensor.PNG differ diff --git a/assets/images/3-2 tesetsensor.PNG b/assets/images/3-2 tesetsensor.PNG new file mode 100644 index 0000000..de91ceb Binary files /dev/null and b/assets/images/3-2 tesetsensor.PNG differ diff --git a/assets/images/3-4 tesetsensor.PNG b/assets/images/3-4 tesetsensor.PNG new file mode 100644 index 0000000..ef74944 Binary files /dev/null and b/assets/images/3-4 tesetsensor.PNG differ diff --git a/assets/images/3-5 test sensor.PNG b/assets/images/3-5 test sensor.PNG new file mode 100644 index 0000000..311763c Binary files /dev/null and b/assets/images/3-5 test sensor.PNG differ diff --git a/assets/images/4- 1 push image.PNG b/assets/images/4- 1 push image.PNG new file mode 100644 index 0000000..2cdf213 Binary files /dev/null and b/assets/images/4- 1 push image.PNG differ diff --git a/assets/images/4- 2 dockercompose.PNG b/assets/images/4- 2 dockercompose.PNG new file mode 100644 index 0000000..6cc33fb Binary files /dev/null and b/assets/images/4- 2 dockercompose.PNG differ diff --git a/assets/images/4- 3 dockercompose.PNG b/assets/images/4- 3 dockercompose.PNG new file mode 100644 index 0000000..abf7a14 Binary files /dev/null and b/assets/images/4- 3 dockercompose.PNG differ diff --git a/assets/images/4- 4 docker compose check ports.PNG b/assets/images/4- 4 docker compose check ports.PNG new file mode 100644 index 0000000..c53aa34 Binary files /dev/null and b/assets/images/4- 4 docker compose check ports.PNG differ diff --git a/assets/images/5-1 mqtt.PNG b/assets/images/5-1 mqtt.PNG new file mode 100644 index 0000000..c2b1879 Binary files /dev/null and b/assets/images/5-1 mqtt.PNG differ diff --git a/assets/images/5-2 mqtt.PNG b/assets/images/5-2 mqtt.PNG new file mode 100644 index 0000000..d1160e7 Binary files /dev/null and b/assets/images/5-2 mqtt.PNG differ diff --git a/assets/images/5-3 mqtt.PNG b/assets/images/5-3 mqtt.PNG new file mode 100644 index 0000000..c807fc4 Binary files /dev/null and b/assets/images/5-3 mqtt.PNG differ diff --git a/assets/images/A- 1 sensor .PNG b/assets/images/A- 1 sensor .PNG new file mode 100644 index 0000000..8e763f6 Binary files /dev/null and b/assets/images/A- 1 sensor .PNG differ diff --git a/assets/images/A- 2 sensor .PNG b/assets/images/A- 2 sensor .PNG new file mode 100644 index 0000000..a2036d1 Binary files /dev/null and b/assets/images/A- 2 sensor .PNG differ diff --git a/assets/images/A- 3 sensor .PNG b/assets/images/A- 3 sensor .PNG new file mode 100644 index 0000000..227a398 Binary files /dev/null and b/assets/images/A- 3 sensor .PNG differ diff --git a/assets/images/B 1 mosq.PNG b/assets/images/B 1 mosq.PNG new file mode 100644 index 0000000..7f43af8 Binary files /dev/null and b/assets/images/B 1 mosq.PNG differ diff --git a/assets/images/B 2 mosq.PNG b/assets/images/B 2 mosq.PNG new file mode 100644 index 0000000..de86c7a Binary files /dev/null and b/assets/images/B 2 mosq.PNG differ diff --git a/assets/images/f1.PNG b/assets/images/f1.PNG new file mode 100644 index 0000000..fee5e7c Binary files /dev/null and b/assets/images/f1.PNG differ diff --git a/assets/images/f2.PNG b/assets/images/f2.PNG new file mode 100644 index 0000000..55b70d8 Binary files /dev/null and b/assets/images/f2.PNG differ diff --git a/assets/images/f3.PNG b/assets/images/f3.PNG new file mode 100644 index 0000000..b1c1998 Binary files /dev/null and b/assets/images/f3.PNG differ diff --git a/assets/images/g1.PNG b/assets/images/g1.PNG new file mode 100644 index 0000000..0117a35 Binary files /dev/null and b/assets/images/g1.PNG differ diff --git a/assets/images/g2.PNG b/assets/images/g2.PNG new file mode 100644 index 0000000..22c82b2 Binary files /dev/null and b/assets/images/g2.PNG differ diff --git a/assets/images/grafana 1 .PNG b/assets/images/grafana 1 .PNG new file mode 100644 index 0000000..573199c Binary files /dev/null and b/assets/images/grafana 1 .PNG differ diff --git a/assets/images/grafana 1- 1 .PNG b/assets/images/grafana 1- 1 .PNG new file mode 100644 index 0000000..4d8d878 Binary files /dev/null and b/assets/images/grafana 1- 1 .PNG differ diff --git a/assets/images/grafana 2.PNG b/assets/images/grafana 2.PNG new file mode 100644 index 0000000..ab5b6f5 Binary files /dev/null and b/assets/images/grafana 2.PNG differ diff --git a/assets/images/grafana 3.PNG b/assets/images/grafana 3.PNG new file mode 100644 index 0000000..8a51ec2 Binary files /dev/null and b/assets/images/grafana 3.PNG differ diff --git a/assets/images/grafana 4.PNG b/assets/images/grafana 4.PNG new file mode 100644 index 0000000..03a3c7a Binary files /dev/null and b/assets/images/grafana 4.PNG differ diff --git a/assets/images/influxdb 1.PNG b/assets/images/influxdb 1.PNG new file mode 100644 index 0000000..bbea254 Binary files /dev/null and b/assets/images/influxdb 1.PNG differ diff --git a/assets/images/telegraf conf.PNG b/assets/images/telegraf conf.PNG new file mode 100644 index 0000000..5aa52c4 Binary files /dev/null and b/assets/images/telegraf conf.PNG differ diff --git a/report.md b/report.md new file mode 100644 index 0000000..a78e376 --- /dev/null +++ b/report.md @@ -0,0 +1,109 @@ +- Install on each virtual machine docker and docker-compose. + +![1- version A](https://user-images.githubusercontent.com/25878224/234697074-ee27f537-754b-4935-a552-43f76bdc7843.PNG) + +![1- version B](https://user-images.githubusercontent.com/25878224/234697168-816b99c6-c84f-45f1-a5b7-a51d7c514424.PNG) + +![1- version c](https://user-images.githubusercontent.com/25878224/234697182-737a155a-0f8f-4ab9-84e7-6c8fa20391fb.PNG) + +- Create the four Sensors classes (Temperature, Pressure, Current, Humidity) by module "sensor.py" + +![A- 1 sensor ](https://user-images.githubusercontent.com/25878224/235059677-3d219643-9710-4199-8916-76d7c819f968.PNG) + +![A- 2 sensor ](https://user-images.githubusercontent.com/25878224/235059709-062cf237-5f9e-4ea0-8bdf-b74e7459d3a2.PNG) + +![A- 3 sensor ](https://user-images.githubusercontent.com/25878224/235059716-a834701f-fe0b-4e9d-96f6-67001fc99398.PNG) + +- Configure the docker image configuration file (DockerFile) + + FROM python:3.7 + WORKDIR /app + COPY requirements.txt . + RUN pip install -r requirements.txt + COPY . . + CMD ["python", "main.py"] + +- Build the docker image with the following command: + + sudo docker build -t souhair/sensor-simulator:v0.0.1 . + +![1](https://github.com/souhair/DockerPractice/assets/25878224/f753b2b5-8f6d-487b-ad27-22d0ac182b41) + + +- Download mosquitto broker, create mosquitto.conf file + +![B 1 mosq](https://user-images.githubusercontent.com/25878224/235062194-88a0e5df-c59e-4d56-8648-84c3127bdc53.PNG) + +- Start a container with a binding to a port and loading a conf file into the system + +![B 2 mosq](https://user-images.githubusercontent.com/25878224/235062613-a823d3e5-bbd6-4e00-8ce1-6488e5acbe8e.PNG) + +- Let's see when running this command to test temperature sensor: + +![3- 6 test sensor](https://user-images.githubusercontent.com/25878224/235064111-59c08193-60a6-4e1c-9f97-717ef6a3a63d.PNG) + +![3-1 test sensor](https://user-images.githubusercontent.com/25878224/235064130-5a82d272-818a-49ae-8d53-3e826f6a8cc0.PNG) + +![3-5 test sensor](https://user-images.githubusercontent.com/25878224/235064223-3cd49436-a18d-48c3-95dd-cdaabfba1424.PNG) + +- And check with mqtt explorer + +![5-1 mqtt](https://user-images.githubusercontent.com/25878224/235063223-29384927-36ec-483a-9fc8-d1ceedeb4c9f.PNG) + + +- Pushing the Image to DockerHub + +![2](https://github.com/souhair/DockerPractice/assets/25878224/10c8bdd0-6434-4a71-892f-3c977f560615) + +![3](https://github.com/souhair/DockerPractice/assets/25878224/5cc298da-2f5c-4555-916e-08efd353a584) + +![4](https://github.com/souhair/DockerPractice/assets/25878224/8af60964-a911-4c5a-ad79-2cb9e76495d3) + + +- Now test all sensors: + +![3-2 tesetsensor](https://user-images.githubusercontent.com/25878224/235063689-efbb0454-b255-4288-be44-e04beb389fe8.PNG) + +![3-4 tesetsensor](https://user-images.githubusercontent.com/25878224/235064211-247cd9fa-c7db-4bc4-9165-26b15aa9bb3c.PNG) + +![3-2 -1 tesetsensor](https://user-images.githubusercontent.com/25878224/235063939-1f29b84a-4c0a-48d7-a14a-d1f702212b1b.PNG) + + +- Check with mqtt explorer + +![5-3 mqtt](https://user-images.githubusercontent.com/25878224/235063315-6e97974e-e161-4947-bbc2-f03dd62ec598.PNG) + +- After that, we create a docker-compose file: + +![8 compose server 1](https://github.com/souhair/DockerPractice/assets/25878224/dd366dd0-016a-4992-88b6-a08ec65d5fc5) + +![9 compose server 2](https://github.com/souhair/DockerPractice/assets/25878224/49bdf3dd-ff4b-43a1-980b-9bcad41deddf) + + In Linux A: +- Influxdb +Run a container with a database with an attached volume (version 1.8) + +![influxdb 1](https://user-images.githubusercontent.com/25878224/235066231-131e54e7-93a2-429a-a40a-985b413cb592.PNG) + +- Telegraf - configration file + +![telegraf conf](https://user-images.githubusercontent.com/25878224/235066474-db765f99-3908-4e73-91b8-e5f41a9dab50.PNG) + +- Now we have: + +![f1](https://github.com/souhair/DockerPractice/assets/25878224/0aaf4e12-eea0-4c43-9e98-8e2eeb45db61) + +![f2](https://user-images.githubusercontent.com/25878224/235067324-c976bfbf-e29b-4f4d-8f3a-6e31e4770036.PNG) + +![f3](https://user-images.githubusercontent.com/25878224/235067345-81b4ed28-8be9-4f21-a521-2d03533cb9f8.PNG) + +- Grafana on port 3000 + +![grafana 1- 1 ](https://user-images.githubusercontent.com/25878224/235066132-86838126-656b-4e4c-93b2-56bb8ef54275.PNG) + +![5](https://github.com/souhair/DockerPractice/assets/25878224/ad13e673-39b7-4b93-beda-41e3ed6f3b97) + +![6](https://github.com/souhair/DockerPractice/assets/25878224/629b8eae-c696-49d7-9d95-34fee7abd5cd) + +![7](https://github.com/souhair/DockerPractice/assets/25878224/b92efedc-9215-4004-a25a-220fa061c203) + diff --git a/vms/client/client.sh b/vms/client/client.sh new file mode 100644 index 0000000..b958952 --- /dev/null +++ b/vms/client/client.sh @@ -0,0 +1,14 @@ +#! /bin/bash +# script to create the third virtual machine +ip link add macvlan1 link eth0 type macvlan mode bridge +ip address add dev macvlan1 192.168.4.100/24 +ip link set macvlan1 up +ip route add 192.168.18.0/24 via 192.168.4.1 +while [ true ] ; do +read -t 3 -n 1 +if [ $? = 0 ] ; then +break ; +else +echo "waiting for the keypress" +fi +done diff --git a/vms/client/simulator/.env b/vms/client/simulator/.env new file mode 100644 index 0000000..a289a06 --- /dev/null +++ b/vms/client/simulator/.env @@ -0,0 +1 @@ +SIM_HOST_IP = 192.168.4.1 diff --git a/vms/client/simulator/docker-compose.yml b/vms/client/simulator/docker-compose.yml index b9e08bb..7a33061 100644 --- a/vms/client/simulator/docker-compose.yml +++ b/vms/client/simulator/docker-compose.yml @@ -2,23 +2,31 @@ version: "3" services: temp_sensor: - image: antonaleks/data-simulator + image: souhair/sensor-simulator:v0.0.1 environment: - - SIM_HOST=192.168.1.1 + - SIM_HOST=$SIM_HOST_IP - SIM_NAME=TIRCAHL24 - SIM_PERIOD=5 - SIM_TYPE=temperature pressure_sensor: - image: antonaleks/data-simulator + image: souhair/sensor-simulator:v0.0.1 environment: - - SIM_HOST=192.168.1.1 + - SIM_HOST=$SIM_HOST_IP - SIM_NAME=PIRCAHL11 - SIM_PERIOD=10 - SIM_TYPE=pressure current_sensor: - image: antonaleks/data-simulator + image: souhair/sensor-simulator:v0.0.1 environment: - - SIM_HOST=192.168.1.1 + - SIM_HOST=$SIM_HOST_IP - SIM_NAME=A0_CURRENT - SIM_PERIOD=1 - SIM_TYPE=current + humidity_sensor: + image: souhair/sensor-simulator:v0.0.1 + environment: + - SIM_HOST=$SIM_HOST_IP + - SIM_NAME=H0_HUMIDITY + - SIM_PERIOD=10 + - SIM_TYPE=humidity + diff --git a/vms/client/simulator/entity/sensor.py b/vms/client/simulator/entity/sensor.py index 922fea5..280bb9e 100644 --- a/vms/client/simulator/entity/sensor.py +++ b/vms/client/simulator/entity/sensor.py @@ -20,7 +20,7 @@ def __str__(self): class Temperature(Sensor): - step = 25 + step = 15 def __init__(self, name): super().__init__(name) @@ -31,7 +31,7 @@ def generate_new_value(self): class Pressure(Sensor): - step = 55 + step = 65 def __init__(self, name): super().__init__(name) @@ -52,3 +52,16 @@ def generate_new_value(self): import math self.value = math.sin(self.step) self.step = self.step + 1 + +class Humidity(Sensor): + step = 0 + + def __init__(self, name): + super().__init__(name) + self.type = "humidity" + + def generate_new_value(self): + import math + self.value = (math.cos(self.step + 3) + 2) * 10 + self.step = self.step + 4 + diff --git a/vms/client/simulator/main.py b/vms/client/simulator/main.py index cccbc47..059ef82 100644 --- a/vms/client/simulator/main.py +++ b/vms/client/simulator/main.py @@ -9,7 +9,7 @@ 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} +sensors = {"temperature": Temperature, "pressure": Pressure, "current": Current, "humidity": Humidity} def on_publish(client, userdata, result): # create function for callback diff --git a/vms/gateway/gateway.sh b/vms/gateway/gateway.sh new file mode 100644 index 0000000..cdbc59f --- /dev/null +++ b/vms/gateway/gateway.sh @@ -0,0 +1,10 @@ +#! /bin/bash +# script to create the second virtual machine + +ip link add macvlan1 link eth0 type macvlan mode bridge +ip address add dev macvlan1 192.168.18.1/24 +ip link set macvlan1 up +ip link add macvlan2 link eth0 type macvlan mode bridge +ip address add dev macvlan2 192.168.4.1/24 +ip link set macvlan2 up + diff --git a/vms/server/infra/docker-compose.yml b/vms/server/infra/docker-compose.yml index 94e705e..7374ee0 100644 --- a/vms/server/infra/docker-compose.yml +++ b/vms/server/infra/docker-compose.yml @@ -9,7 +9,7 @@ services: networks: - server-net telegraf: - image: telegraf + image: telegraf:1.26.2 container_name: telegraf volumes: - ./telegraf:/etc/telegraf:ro @@ -17,7 +17,7 @@ services: networks: - server-net grafana: - image: grafana/grafana + image: grafana/grafana:9.5.1-ubuntu container_name: grafana volumes: - grafana_data:/var/lib/grafana @@ -39,4 +39,4 @@ volumes: grafana_data: {} networks: - server-net: {} \ No newline at end of file + server-net: {} diff --git a/vms/server/infra/grafana/provisioning/dashboards/mqtt.json b/vms/server/infra/grafana/provisioning/dashboards/mqtt.json index ec65ac0..ecf4342 100644 --- a/vms/server/infra/grafana/provisioning/dashboards/mqtt.json +++ b/vms/server/infra/grafana/provisioning/dashboards/mqtt.json @@ -3,43 +3,268 @@ "list": [ { "builtIn": 1, - "datasource": "-- Grafana --", + "datasource": { + "type": "grafana", + "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" } ] }, + "description": "", "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, + "id": 6, "links": [], "liveNow": false, "panels": [ { "datasource": { "type": "influxdb", - "uid": "P4B5EB7AC8565B06F" + "uid": "" + }, + "description": "Temp", + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-GrYlRd" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 20, + "gradientMode": "scheme", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "smooth", + "lineWidth": 3, + "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": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "alias": "Temp", + "datasource": { + "type": "influxdb", + "uid": "" + }, + "groupBy": [], + "measurement": "mqtt_consumer", + "orderByTime": "ASC", + "policy": "autogen", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + } + ] + ], + "tags": [ + { + "key": "topic::tag", + "operator": "=", + "value": "sensors/temp/TIRCAHL24" + } + ] + } + ], + "title": "Temp", + "type": "timeseries" + }, + { + "datasource": { + "type": "influxdb", + "uid": "" }, + "description": "Pressure", + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-GrYlRd" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 20, + "gradientMode": "scheme", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "smooth", + "lineWidth": 3, + "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": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 3, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "9.5.1", + "targets": [ + { + "alias": "Pressure", + "datasource": { + "type": "influxdb", + "uid": "" + }, + "groupBy": [], + "measurement": "mqtt_consumer", + "orderByTime": "ASC", + "policy": "autogen", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + } + ] + ], + "tags": [ + { + "key": "topic::tag", + "operator": "=", + "value": "sensors/pressure/PIRCAHL11" + } + ] + } + ], + "title": "Pressure", + "type": "timeseries" + }, + { + "datasource": { + "type": "influxdb", + "uid": "" + }, + "description": "Humidity", "fieldConfig": { "defaults": { "color": { "mode": "palette-classic" }, "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, "drawStyle": "line", - "fillOpacity": 0, + "fillOpacity": 25, "gradientMode": "none", "hideFrom": { "legend": false, @@ -67,8 +292,7 @@ "mode": "absolute", "steps": [ { - "color": "green", - "value": null + "color": "green" }, { "color": "red", @@ -80,17 +304,18 @@ "overrides": [] }, "gridPos": { - "h": 9, + "h": 8, "w": 12, "x": 0, - "y": 0 + "y": 8 }, "id": 2, "options": { "legend": { "calcs": [], "displayMode": "list", - "placement": "bottom" + "placement": "bottom", + "showLegend": true }, "tooltip": { "mode": "single", @@ -99,14 +324,15 @@ }, "targets": [ { + "alias": "Humidity", "datasource": { "type": "influxdb", - "uid": "P4B5EB7AC8565B06F" + "uid": "" }, "groupBy": [], "measurement": "mqtt_consumer", "orderByTime": "ASC", - "policy": "default", + "policy": "autogen", "refId": "A", "resultFormat": "time_series", "select": [ @@ -121,18 +347,101 @@ ], "tags": [ { - "key": "topic", + "key": "topic::tag", "operator": "=", - "value": "sensors/current/A0_CURRENT" + "value": "sensors/humidity/H0_HUMIDITY" } ] } ], - "title": "Panel Title", + "title": "Humidity", "type": "timeseries" + }, + { + "datasource": { + "type": "influxdb", + "uid": "" + }, + "description": "current", + "fieldConfig": { + "defaults": { + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "short" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 8 + }, + "id": 1, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.5.1", + "targets": [ + { + "alias": "current", + "datasource": { + "type": "influxdb", + "uid": "" + }, + "groupBy": [], + "measurement": "mqtt_consumer", + "orderByTime": "ASC", + "policy": "autogen", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + } + ] + ], + "tags": [ + { + "key": "topic::tag", + "operator": "=", + "value": "sensors/current/A0_CURRENT" + } + ] + } + ], + "title": "Current", + "type": "stat" } ], - "schemaVersion": 35, + "refresh": "", + "schemaVersion": 38, "style": "dark", "tags": [], "templating": { @@ -144,7 +453,8 @@ }, "timepicker": {}, "timezone": "", - "title": "New dashboard", - "version": 0, + "title": "New final", + "uid": "ba3a60e0-eb75-4655-80bb-cd1eae97f079", + "version": 6, "weekStart": "" -} \ No newline at end of file +} diff --git a/vms/server/infra/grafana/provisioning/datasources/default.yaml b/vms/server/infra/grafana/provisioning/datasources/default.yaml index d4e29dd..17b1b30 100644 --- a/vms/server/infra/grafana/provisioning/datasources/default.yaml +++ b/vms/server/infra/grafana/provisioning/datasources/default.yaml @@ -10,4 +10,4 @@ datasources: jsonData: httpMode: GET secureJsonData: - password: telegraf \ No newline at end of file + password: telegraf diff --git a/vms/server/infra/influxdb/scripts/influxdb-init.iql b/vms/server/infra/influxdb/scripts/influxdb-init.iql index 0e0fb65..f9008d2 100644 --- a/vms/server/infra/influxdb/scripts/influxdb-init.iql +++ b/vms/server/infra/influxdb/scripts/influxdb-init.iql @@ -1,2 +1,3 @@ CREATE database sensors -CREATE USER telegraf WITH PASSWORD 'telegraf' WITH ALL PRIVILEGES \ No newline at end of file +USE sensors +CREATE USER telegraf WITH PASSWORD 'telegraf' WITH ALL PRIVILEGES diff --git a/vms/server/infra/server.sh b/vms/server/infra/server.sh new file mode 100644 index 0000000..a96a872 --- /dev/null +++ b/vms/server/infra/server.sh @@ -0,0 +1,16 @@ +#! /bin/bash +# script to create the First virtual machine + +echo -e "-Create a server dirctory and create app.py inside it\n and install flask and tcpdump\nand run bash again\n" +while [ true ] ; do +read -t 3 -n 1 +if [ $? = 0 ] ; then +break; +else +echo "waiting for the keypress" +fi +done +ip link add macvlan1 link eth0 type macvlan mode bridge +ip address add dev macvlan1 192.168.18.10/24 +ip link set macvlan1 up +ip route add 192.168.4.0/24 via 192.168.18.1 diff --git a/vms/server/infra/telegraf/telegraf.conf b/vms/server/infra/telegraf/telegraf.conf index ddd8b05..21ed2e0 100644 --- a/vms/server/infra/telegraf/telegraf.conf +++ b/vms/server/infra/telegraf/telegraf.conf @@ -120,7 +120,16 @@ # Configuration for sending metrics to InfluxDB [[outputs.influxdb]] -urls = ["http://influxdb:8086"] # адрес докера с influxdb (указать alias при docker-compose, ip адрес для docker run) +#urls = ["http://influxdb:8086"] # адрес докера с influxdb (указать alias при docker-compose, ip адрес для docker run) +#database = "sensors" +#skip_database_creation = true +#username = "telegraf" +#password = "telegraf" + +# в блок [outputs.influxdb] +#[[outputs.influxdb]] +# адрес докера с influxdb (указать alias при docker-compose) +urls = ["http://influxdb:8086"] database = "sensors" skip_database_creation = true username = "telegraf" @@ -8558,12 +8567,21 @@ password = "telegraf" # "telegraf/+/mem", # "sensors/#", # ] -servers = ["tcp://192.168.26.1:1883"] # адрес vm с mqtt-брокером +#servers = ["tcp://192.168.26.1:1883"] # адрес vm с mqtt-брокером +#topics = [ +# "sensors/#" +#] +#data_format = "value" +#data_type = "float" +# в блок mqtt_consumer +# [[inputs.mqtt_consumer]] +servers = ["tcp://192.168.18.1:1883"] # адрес vm с mqtt-брокером topics = [ "sensors/#" ] data_format = "value" data_type = "float" +max_undelivered_messages = 1500 # # topic_fields = "_/_/_/temperature" # ## The message topic will be stored in a tag specified by this value. If set # ## to the empty string no topic tag will be created.