diff --git a/Readme.md b/Readme.md index c7d73a8b142bb79d275ddfa200ff2ea0890f56dd..e75d7cd19ef0d32d35f80e0b2f5b0e1b7ab577fe 100644 --- a/Readme.md +++ b/Readme.md @@ -30,11 +30,11 @@ http://docs.grafana.org/installation/debian/ `git clone` -`cd influxdb/sensor` +`cd influxdb/sensors/sensor_driver` `python3 -m pip install -r requirements.txt` -`python3 cpu_influx.py` +`python3 sensor_driver.py` # Connect to Grafana @@ -42,5 +42,5 @@ http://docs.grafana.org/installation/debian/ * user : admin * pwd : admin -* Ajouter une source de donnée influxdb avec comme nom de base de donnée "cpu-sense" -* Ajouter un graphique pour afficher usage CPU dans le temps \ No newline at end of file +* Ajouter une source de donnée influxdb avec comme nom de base de donnée "multi-sense" +* Ajouter un graphique pour afficher les données dans le temps \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e5586edd7113f4a2c15f1525756ae96e1cbd2312..7ec1aab5b13a7c1aa30ea63a66bca17a84aac39f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ services: env_file: - ./grafana/config.monitoring sensor: - build: ./sensor + build: ./sensors/cpu_load restart: always environment: - INFLUX_HOST=influxdb diff --git a/grafana/dashboards/CPU Usage-1549886184778.json b/grafana/dashboards/CPU Usage-1549886184778.json deleted file mode 100644 index 82a7677708533dfffa4c216207bc3b50888be71e..0000000000000000000000000000000000000000 --- a/grafana/dashboards/CPU Usage-1549886184778.json +++ /dev/null @@ -1,175 +0,0 @@ -{ - "annotations": { - "list": [ - { - "builtIn": 1, - "datasource": "-- Grafana --", - "enable": true, - "hide": true, - "iconColor": "rgba(0, 211, 255, 1)", - "name": "Annotations & Alerts", - "type": "dashboard" - } - ] - }, - "editable": true, - "gnetId": null, - "graphTooltip": 0, - "id": 1, - "links": [], - "panels": [ - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "Influxdb", - "fill": 1, - "gridPos": { - "h": 15, - "w": 18, - "x": 0, - "y": 0 - }, - "id": 2, - "legend": { - "avg": true, - "current": false, - "max": true, - "min": true, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 2, - "links": [], - "nullPointMode": "null", - "percentage": false, - "pointradius": 5, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "groupBy": [ - { - "params": [ - "10s" - ], - "type": "time" - }, - { - "params": [ - "null" - ], - "type": "fill" - } - ], - "measurement": "CPU Usage", - "orderByTime": "ASC", - "policy": "default", - "refId": "A", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "value" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - } - ] - ], - "tags": [] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Panel Title", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - } - ], - "schemaVersion": 16, - "style": "dark", - "tags": [], - "templating": { - "list": [] - }, - "time": { - "from": "now-6h", - "to": "now" - }, - "timepicker": { - "refresh_intervals": [ - "5s", - "10s", - "30s", - "1m", - "5m", - "15m", - "30m", - "1h", - "2h", - "1d" - ], - "time_options": [ - "5m", - "15m", - "1h", - "6h", - "12h", - "24h", - "2d", - "7d", - "30d" - ] - }, - "timezone": "", - "title": "CPU Usage", - "uid": "OwisVIuiz", - "version": 3 -} diff --git a/grafana/provisioning/dashboards/CPU Usage-1549886184778.json b/grafana/provisioning/dashboards/CPU Usage-1549886184778.json index 82a7677708533dfffa4c216207bc3b50888be71e..d25aa77d3519f983abed02d8608cbdb34fda4d98 100644 --- a/grafana/provisioning/dashboards/CPU Usage-1549886184778.json +++ b/grafana/provisioning/dashboards/CPU Usage-1549886184778.json @@ -69,7 +69,7 @@ "type": "fill" } ], - "measurement": "CPU Usage", + "measurement": "cpu_load", "orderByTime": "ASC", "policy": "default", "refId": "A", @@ -169,7 +169,7 @@ ] }, "timezone": "", - "title": "CPU Usage", + "title": "CPU Load", "uid": "OwisVIuiz", "version": 3 } diff --git a/grafana/provisioning/dashboards/dashboard.yml b/grafana/provisioning/dashboards/dashboard.yml index 5ab58f4c1d4ad966787b19fd8d88045be0478fed..d70d943ec2ea75897990d35d543c89e374a5ccda 100644 --- a/grafana/provisioning/dashboards/dashboard.yml +++ b/grafana/provisioning/dashboards/dashboard.yml @@ -1,6 +1,6 @@ apiVersion: 1 providers: - - name: 'CPU usage' + - name: 'CPU load' orgId: 1 folder: '' type: file diff --git a/grafana/provisioning/datasources/datasource.yml b/grafana/provisioning/datasources/datasource.yml index 49c544dc4ea20a605f8d421eb4bf8695c9e61985..f045db65d4a25f6b433a1e28eee22335070bee91 100644 --- a/grafana/provisioning/datasources/datasource.yml +++ b/grafana/provisioning/datasources/datasource.yml @@ -3,7 +3,7 @@ datasources: - name: Influxdb type: influxdb access: proxy - database: cpu-sense + database: multi-sense user: root password: root url: http://influxdb:8086 diff --git a/sensor/Dockerfile b/sensors/cpu_load/Dockerfile similarity index 65% rename from sensor/Dockerfile rename to sensors/cpu_load/Dockerfile index 26f60aee80887f3e916ce7cc87777c10b31f4bcb..7a9e5cd6fbac0f7fcd7950a708f091294cebc395 100644 --- a/sensor/Dockerfile +++ b/sensors/cpu_load/Dockerfile @@ -1,10 +1,10 @@ FROM python:3 RUN mkdir -p /usr/src/app -COPY cpu_influx.py /usr/src/app +COPY cpu_load.py /usr/src/app COPY requirements.txt /usr/src/app WORKDIR /usr/src/app RUN python3 -m pip install -r requirements.txt -CMD ["python3", "/usr/src/app/cpu_influx.py"] \ No newline at end of file +CMD ["python3", "/usr/src/app/cpu_load.py"] \ No newline at end of file diff --git a/sensor/cpu_influx.py b/sensors/cpu_load/cpu_load.py similarity index 61% rename from sensor/cpu_influx.py rename to sensors/cpu_load/cpu_load.py index 1a1d14641ae92e2f3520d69d8e99699f63e635ad..1a1b3719e6bc311e73748e14995e0e0321f60d26 100644 --- a/sensor/cpu_influx.py +++ b/sensors/cpu_load/cpu_load.py @@ -4,13 +4,14 @@ import psutil from influxdb import InfluxDBClient influx_host = os.getenv('INFLUX_HOST', 'localhost') -influx_client = InfluxDBClient(host=influx_host, database='cpu-sense') -influx_client.create_database('cpu-sense') +influx_dbname = os.getenv('INFLUX_DBNAME', 'multi-sense') +influx_client = InfluxDBClient(host=influx_host, database=influx_dbname) +influx_client.create_database(influx_dbname) while True: measurement = [ { - 'measurement': 'CPU Usage', + 'measurement': 'cpu_load', 'fields': { 'value': float(psutil.cpu_percent(0)) } diff --git a/sensor/requirements.txt b/sensors/cpu_load/requirements.txt similarity index 100% rename from sensor/requirements.txt rename to sensors/cpu_load/requirements.txt