Grafana und Influxdb

Installation auf einem Armbian, 21.02.3 Focal

Installation Influxdb

Installation wird auch hier beschrieben: https://docs.influxdata.com/influxdb/v1.8/introduction/install/

sudo wget -qO- https://repos.influxdata.com/influxdb.key | gpg --dearmor > /etc/apt/trusted.gpg.d/influxdb.gpg
export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc) 
sudo echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" > sudo /etc/apt/sources.list.d/influxdb.list

Influxdb installieren

sudo apt-get update && sudo apt-get install influxdb 
sudo service influxdb start

Nun kann auf die Influx-Shell zugegriffen werden

influx

Benutzer anlegen

CREATE USER "admin" WITH PASSWORD '<adminpassword>' WITH ALL PRIVILEGES
CREATE USER "spacelynk" WITH PASSWORD '<userpassword>'

Datenbank anlegen und Berechtigung erteilen

CREATE DATABASE "knxdb"
GRANT ALL ON "knxdb" TO "user"

Influxdb konfigurieren

Das Konfig-File der Influx-DB liegt unter /etc/influxdb/…

sudo vi /etc/influxdb/influxdb.conf

Sicherstellen, dass folgende Punkte gesetzt sind:

[http] 
enabled = true 
bind-address = ":8086" 
auth-enabled = true
log-enabled = true 
write-tracing = false 
pprof-enabled = true 
https-enabled = false 
https-certificate = "/etc/ssl/influxdb.pem"

Service restarten

sudo service influxdb restart

Grafana installieren

Installation

Installation wird hier beschrieben: https://grafana.com/docs/grafana/latest/installation/debian/

Konfiguration

Die Configuration von Grafana findet man hier

sudo vi /etc/grafana/grafana.ini
# Grafana soll als eingebettetes Frame angezeigt werden können:
allow_embedding = true
[auth.anonymous]
# enable anonymous access
enabled = true

# specify organization name that should be used for unauthenticated users
org_name = Home

# specify role for unauthenticated users
org_role = Viewer

# mask the Grafana version number for unauthenticated users
hide_version = false
[date_formats]
# For information on what formatting patterns that are supported https://momentjs.com/docs/#/displaying/

# Default system date format used in time range picker and other places where full time is displayed
full_date = DD-MM-YYYY HH:mm:ss

# Used by graph and other places where we only show small intervals
interval_second = HH:mm:ss
interval_minute = HH:mm
interval_hour = DD/MM HH:mm
interval_day = DD/MM
interval_month = MM-YYYY
interval_year = YYYY

 

Telegraf installieren

Telegraf wird benutzt um die Modbus-Daten abzufragen und nach influxdb zu senden.

wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update && sudo apt-get install telegraf
sudo service telegraf start

Influxdb als output plugin konfigurieren

DB und User auf influxdb erstellen

CREATE DATABASE "telegraf"
CREATE USER "telegraf" WITH PASSWORD "<userpassword>"
GRANT ALL ON "telegraf" TO "telegraf"

Konfig anpassen

sudo vi /etc/telegraf/telegraf.conf
[[outputs.influxdb]]
urls = ["http://127.0.0.1:8086"] #influxdb und telegraf laufen auf dem selben server
database = "telegraf"
## HTTP Basic Auth
username = "telegraf"
password = "<password>"

Modbus als input plugin konfigurieren

sudo vi /etc/telegraf/telegraf.conf

Alle input Plugins (CPU, etc.) deaktivieren. Anschliessend Modubs konfigrieren:

[[inputs.modbus]]
name = "SE_PowerTagLink_F21"
slave_id = 150
timeout = "5s"
controller = "tcp://<ip>:502"
holding_registers = [
{ name = "PowerTag_Garage - Current C", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3003,3004]}
]
[[inputs.modbus]]
name = "SE_PowerTagLink_Hauszuleitung"
slave_id = 154
timeout = "5s"
controller = "tcp://<ip>:502"
holding_registers = [
{ name = "PowerTag_Hauszuleitung - Current A", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [2999,3000]},
{ name = "PowerTag_Hauszuleitung - Current B", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3001,3002]},
{ name = "PowerTag_Hauszuleitung - Current C", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3003,3004]},
{ name = "PowerTag_Hauszuleitung - Voltage A-N", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3027,3028]},
{ name = "PowerTag_Hauszuleitung - Voltage B-N", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3029,3030]},
{ name = "PowerTag_Hauszuleitung - Voltage C-N", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3031,3032]},
{ name = "PowerTag_Hauszuleitung - Voltage A-B", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3019,3020]},
{ name = "PowerTag_Hauszuleitung - Voltage B-C", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3021,3022]},
{ name = "PowerTag_Hauszuleitung - Voltage C-A", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3023,3024]},
{ name = "PowerTag_Hauszuleitung - Active Power", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3059,3060]},
{ name = "PowerTag_Hauszuleitung - Power Factor", byte_order = "ABCD", data_type = "FLOAT32-IEEE", scale=1.0, address = [3083,3084]},
{ name = "PowerTag_Hauszuleitung - Active Energy No reset", byte_order = "ABCDEFGH", data_type = "INT64", scale=1.0, address = [3203,3204,3205,3206]},
{ name = "PowerTag_Hauszuleitung - Active Energy Resetable", byte_order = "ABCDEFGH", data_type = "INT64", scale=1.0, address = [3255,3256,3257,3258]},
{ name = "PowerTag_Hauszuleitung - Active Energy Write Value", byte_order = "ABCDEFGH", data_type = "INT64", scale=1.0, address = [3259,3260,3261,3262]}
]

Commands

Login

influx -username <username> -password <password>

Benutzer anzeigen

show users

Zeige alle DBs

show databases

Zeitserie löschen (Beispiel)

DROP SERIES FROM "rawdata" WHERE "name" = 'XTH_U01-01 humidity'