=====Timeseries darstellen - Erste Erfahrungen mit InfluxDB / Telegraf / Chronograf / Grafana ===== Für die Auswertung einer Heizungsteuerung von Atmos sollen die über REST im Json Format vorliegenden Log Daten graphisch aufbereitet und historisch ausgewertet werden. ===Architektur Übersicht=== {{ :prod:atmos_jbr_collect_data_v01.png | Atmos JBR Daten Visualisierung }} ===Umsetzung=== Für die Verarbeitung werden die folgenden Produkte eingesetzt: Daten Einsammlen * Client (Python Skript) ließt die Rohdaten und schreibt die Datenüber das REST Interface in die InfluxDB * Alternativ Telegraf - Sammelt die Daten ein Datenhaltung * InfluxDB - Speichert die Daten * Chronograf - Administriert die InfluxDB DB Visualiserung * Grafana - Visualisert die Daten Im ersten Schritt sollen diese Produkt als erste Entwicklungsumgebung unter Windows 2016 betrieben werden, später wird ein kleiner ARM Server( siehe [[raspberry:odroid_hc1_influx_db_grafana|Odroid HC1 Monitoring Appliance mit InfluxDB und Grafana]] ) diese Aufgabe übernehmen. Ablauf: * Download der Software Telegraf,InfluxDB,Chronograh von => https://portal.influxdata.com/downloads * Download der Sofware Grafana von => https://grafana.com/grafana/download?platform=windows * Installation der Software Komponenten * Konfiguratoin der Software Komponenten ---- ==== Time Series Database (TSDB) InfluxDB Umgebung aufstetzen==== ===Grundlagen=== * Zu jedem Eintrag in der DB ist ein zugehöriger Zeitstempel hinterlegt ===Installation=== Nach dem Download der drei Telegraf,InfluxDB,Chronograf von https://portal.influxdata.com/downloads werden diese Produkte in eine Verzeichnisstruktur ausgepackt ===InfluxDB=== Zu Beginn die Grundlagen => https://docs.influxdata.com/influxdb/v1.3/concepts/key_concepts * Entpacken nach D:\srv\ wie D:\srv\influxdb-1.4.2-1 * Erstellen eine Grundkonfiguration über die Datei D:\srv\influxdb-1.4.2-1\influxdb.conf * Erstellen einer Verzeichnisstruktur für die Daten PS D:\srv> mkdir influxdata01 PS D:\srv> mkdir influxdata01\meta PS D:\srv> mkdir influxdata01\data PS D:\srv> mkdir influxdata01\wal ==Grundkonfiguration== Folgendes anpassen in D:\srv\influxdb-1.4.2-1\influxdb.conf ... [meta] # Where the metadata/raft database is stored dir = "D:\\srv\\influxdata01\\meta" ... [data] # The directory where the TSM storage engine stores TSM files. dir = "D:\\srv\\influxdata01\\data" # The directory where the TSM storage engine stores WAL files. wal-dir = "D:\\srv\\influxdata01\\wal" [http] # Determines whether HTTP endpoint is enabled. enabled = true # The bind address used by the HTTP service. bind-address = "10.10.10.1:8086" ==Start== Administrative Powershell: cd D:\srv\influxdb-1.4.2-1 .\influxd.exe -config D:\srv\influxdb-1.4.2-1\influxdb.conf ==Administratoin== Ab der Version 1.3 der InfluxDB ist die Admin Oberfläche nicht mehr dabei, der Aufruf (oft noch im Internt zu finden!) führt nur noch zu einem "404 page not found"! Hier wäre wohl ein Hinweis auf dieses Thema sehr hilfreich. Daher nun im nächsten Schritt Chronograh installieren. ===Chronograf=== * Entpacken nach D:\srv\ wie D:\srv\chronograf-1.3.10.0-1 ==Start== Administrative Powershell: cd D:\srv\chronograf-1.3.10.0-1\ .\chronograf.exe /host:10.10.10.1 /port:9090 ==Anmelden an der InfluxDB== Aufruf der Oberfläche im Browser über http://10.10.10.1:9090 - Connection String http://10.10.10.1:8086/ - Name GPI_LOCAL ===Telegraf=== * Entpacken nach D:\srv\ wie D:\srv\telegraf ==Grundkonfiguration== Folgendes anpassen in D:\srv\telegraf\telegraf.conf .. [[outputs.influxdb]] # The full HTTP or UDP endpoint URL for your InfluxDB instance. urls = ["http://10.10.10.1:8086"] # required ... ==Start== Administrative Powershell: cd D:\srv\telegraf .\telegraf.exe -config .\telegraf.conf ---- ==== Grafana Umgebung aufstetzen==== * Software nach D:\srv entpacken * Konfiguraion anpassen / überprüfen in D:\srv\grafana-4.6.2\conf * sample.ini nach custom.ini kopieren und anpassen * Anmelden über http://localhost:8080 mit Admin/Admin Problem: **html/template: "index" is undefined** Mit der Version grafana-4.6.**2**.windows-x64.zip tritt dieser Fehler auf,mit der Version grafana-**4.6.1**.windows-x64.zip war ein Aufruf der Oberfläche sofort möglich! BUG ?? ==Grundkonfiguration== Folgendes anpassen in D:\srv\grafana-4.6.1\conf\custom.ini [server] # Protocol (http, https, socket) protocol = http # The ip address to bind to, empty will bind to all interfaces http_addr = 10.10.10.1 # The http port to use http_port = 8080 ==Start== Administrative Powershell: cd D:\srv\grafana-4.6.1\bin .\grafana-server.exe Aufruf Login mit admin/admin ---- ==== Start für die Entwicklungsumgebung einrichten ==== d: cd D:\srv\influxdb-1.4.2-1 start influxd.exe -config D:\srv\influxdb-1.4.2-1\influxdb.conf cd D:\srv\chronograf-1.3.10.0-1\ start chronograf.exe /host:10.10.10.1 /port:9090 cd D:\srv\grafana-4.6.1\bin start grafana-server.exe rem bei Bedarf telegraf rem cd D:\srv\telegraf rem start telegraf.exe -config .\telegraf.conf rem URLS rem Cronograph http://10.10.10.1:9090/sources/2/dashboards/1# rem Grafaana http://10.10.0.101:8080/ ---- ==== Daten direkt in die InfluxDB Schreiben === Über das Rest Interface ist es recht einfach direkt in die InfluxDB zu schreiben siehe => https://docs.influxdata.com/influxdb/v1.3/guides/writing_data/ Die Daten müssen in diesem Format übergeben werden => https://docs.influxdata.com/influxdb/v1.3/write_protocols/line_protocol_reference/ [,=[,=]] =[,=] [] Übersicht für ein Beispiel mit 3 Schlüsseln und 3 Werte + Timestamp {{ :prod:influxdb_example_for_data_record_v01.png | Example infuxdb Record mit three keyes and three values}} Sehr wichtig ist die Angabe des Timestamps in Unix nanoseconds, im Python Beispiel unter Windows gelingt das nur wenn die Stellenanzahl mit 000 am Ende aufgefüllt wird. Ein erstes einfaches Beispiel über den Rest Aufruf von http://:/write?db=: import httplib2 import time import datetime #int httplib2 h = httplib2.Http('.cache') headers={} headers={'Content-Type': 'application/text'} i=0 while True: print("====================Insert Example "+ str(i) +" =========================","\n") i=i+1 unixtime = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp() * 1000000) nanossecTime = str(unixtime)+"000" # [,=[,=]] =[,=] [] loadData="MESSUNG,tag_key1=tag_value1,tag_key2=tag_value2 field_key1=" + str(i) + ",field_key2=" + str(i+1) + " " +nanossecTime response, content = h.request(uri='http://10.10.10.1:8086/write?db=JBR',method='POST',headers=headers,body=loadData) print(loadData) print("\n") print(dict(response.items())) print("\n") time.sleep(2) D.h. der "Umweg" über ein Telegraf Plugin kann eigentlich eingespart werden. demnächst mehr ---- ==== Powershell und Influx ==== siehe diesen Eintrag => http://wragg.io/windows-based-grafana-analytics-platform-via-influxdb-and-powershell/ ---- ====Quellen ==== * https://hodgkins.io/windows-metric-dashboards-with-influxdb-and-grafana#viewing-the-data-in-grafana * http://opensourceforu.com/2016/12/introduction-influxdb-time-series-database/ * https://bdrouvot.wordpress.com/2016/03/05/graphing-oracle-performance-metrics-with-telegraf-influxdb-and-grafana/ * https://blog.outlyer.com/top10-open-source-time-series-databases