Nikola Kotur 3 years ago
commit
b367dbfb4c

+ 7 - 0
README.md

@@ -0,0 +1,7 @@
+
+```
+docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' grafana
+docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' grafana_influxdb_1
+```
+
+Ideas from: https://github.com/stefanprodan/dockprom/blob/master/docker-compose.yml

+ 56 - 0
docker-compose.yaml

@@ -0,0 +1,56 @@
+version: '2.1'
+
+# networks:
+#   grafa-net:
+#     driver: bridge
+#   web:
+#     external: true
+
+volumes:
+    grafana_data: {}
+    influxdb_data: {}
+    chronograf_data: {}
+
+services:
+  grafana:
+    image: grafana/grafana:7.3.6
+    container_name: grafana
+    volumes:
+      - grafana_data:/var/lib/grafana:z
+      - ./grafana/provisioning:/etc/grafana/provisioning:z
+    environment:
+      - GF_SECURITY_ADMIN_USER=${ADMIN_USER:-admin}
+      - GF_SECURITY_ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin}
+      - GF_USERS_ALLOW_SIGN_UP=false
+      - GF_AUTH_BASIC_ENABLED=false
+      - GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource
+    restart: "no"
+    expose:
+      - 3000
+
+  influxdb:
+    image: influxdb:latest
+    volumes:
+      - influxdb_data:/var/lib/influxdb
+    environment:
+      - INFLUXDB_DB=db0
+      - INFLUXDB_ADMIN_USER=${ADMIN_USER:-admin}
+      - INFLUXDB_ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin}
+    restart: "no"
+    expose:
+      - 8086
+
+  # chronograf:
+  #   image: chronograf:latest
+  #   container_name: chronograf
+  #   volumes:
+  #     - chronograf_data:/var/lib/chronograf
+  #   depends_on:
+  #     - influxdb
+  #   environment:
+  #     - INFLUXDB_URL=http://influxdb:8086
+  #     - INFLUXDB_USERNAME=${ADMIN_USER:-admin}
+  #     - INFLUXDB_PASSWORD=${ADMIN_PASSWORD:-admin}
+  #   restart: "no"
+  #   expose:
+  #     - 8888

+ 1 - 0
grafana/provisioning/dashboards/.gitignore

@@ -0,0 +1 @@
+#

+ 1 - 0
grafana/provisioning/datasources/.gitignore

@@ -0,0 +1 @@
+#

+ 1 - 0
influxdb-test/.gitignore

@@ -0,0 +1 @@
+.env

+ 5 - 0
influxdb-test/README.md

@@ -0,0 +1,5 @@
+```
+virtualenv .env
+source .env/bin/activate
+python3 -m pip install influxdb pendulum
+```

+ 48 - 0
influxdb-test/create-test-data.py

@@ -0,0 +1,48 @@
+import json
+import random
+import copy
+
+from influxdb import InfluxDBClient
+import pendulum
+
+client = InfluxDBClient(host='172.20.0.2', port=8086)
+
+db_created = False
+for db in client.get_list_database():
+    if db['name'] == 'test':
+        db_created = True
+if not db_created:
+    client.create_database('test')
+client.switch_database('test')
+
+test_data = {
+    "measurement": "pocketArticles",
+    "tags": {
+        "user": "Nikola",
+        "source": "getpocket.com"
+    },
+    "time": "2018-03-30T8:02:00Z",
+    "fields": {
+        "count": 1
+    }
+}
+
+final_data = []
+start = pendulum.datetime(2020, 1, 1)
+end = pendulum.today()
+period = pendulum.period(start, end)
+for dt in period.range('hours', 2):
+    num_articles = random.randrange(1, 50)
+    new_point = copy.deepcopy(test_data)
+    new_point['time'] = dt.isoformat()
+    new_point['fields']['count'] = num_articles
+    final_data.append(new_point)
+
+if client.write_points(final_data):
+    print('ok')
+
+res = client.query('SELECT * FROM "pocketArticles"')
+print(res.raw)
+points = res.get_points(tags={'user': 'Nikola'})
+for point in points:
+    print("Time: %s, Articles: %i" % (point['time'], point['count']))