InfluxDB+Grafana persistence and graphing

thanks will check before asking sorry for posting but lol getting close to finshed in :smiley:

Is @ThomDietrich saying I can skip

Because I did and now in data Source when adding openhab_db I get


InfluxDB Error: error authorizing query: create admin user first or disable authentication

Ok fixed if you

auth-enabled = false         # will enforce authentication

If anyone as “not smart” like me

Hi! If anyone is in the need of processing large amounts of data from OH1 rrd to OH2 influx maybe can be interested in this: rrdToInflux
I was in the need today and just dodged some manual work with this
HTH

Has anyone problem with the recent update of android OpenHAB application?
Grafana in WebView returns error (after tap on exclamation mark):

Invalid dimensions for plot, width = 384, height = 0

In previous OpenHAB android app I saw grafana chart without problems.

https://community.openhab.org/search?q=grafana%20category%3A18

1 Like

Hello,

I followed this nice tutorial to set up Influxdb and Grafana, but I get stuck while adding a datasource:

Openhab can write to the InfluxDB, according the service status:

● influxdb.service - InfluxDB is an open-source, distributed, time series database
   Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-11-19 22:59:38 CET; 10min ago
     Docs: https://docs.influxdata.com/influxdb/
 Main PID: 406 (influxd)
   CGroup: /system.slice/influxdb.service
           └─406 /usr/bin/influxd -config /etc/influxdb/influxdb.conf

Nov 19 23:05:24 openHABianPi influxd[406]: [httpd] 127.0.0.1 - openhab [19/Nov/2018:23:05:24 +0100] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=openhab HTTP/1.1" 204 0 "-" "okhttp/2.4.0" 36e449b3$
Nov 19 23:05:54 openHABianPi influxd[406]: [httpd] 127.0.0.1 - openhab [19/Nov/2018:23:05:54 +0100] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=openhab HTTP/1.1" 204 0 "-" "okhttp/2.4.0" 48b70f43$
Nov 19 23:06:24 openHABianPi influxd[406]: [httpd] 127.0.0.1 - openhab [19/Nov/2018:23:06:24 +0100] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=openhab HTTP/1.1" 204 0 "-" "okhttp/2.4.0" 5a98c234$
Nov 19 23:06:54 openHABianPi influxd[406]: [httpd] 127.0.0.1 - openhab [19/Nov/2018:23:06:54 +0100] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=openhab HTTP/1.1" 204 0 "-" "okhttp/2.4.0" 6c7a5eb2$
Nov 19 23:07:24 openHABianPi influxd[406]: [httpd] 127.0.0.1 - openhab [19/Nov/2018:23:07:24 +0100] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=openhab HTTP/1.1" 204 0 "-" "okhttp/2.4.0" 7e5b8809$
Nov 19 23:07:54 openHABianPi influxd[406]: [httpd] 127.0.0.1 - openhab [19/Nov/2018:23:07:54 +0100] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=openhab HTTP/1.1" 204 0 "-" "okhttp/2.4.0" 903d9099$
Nov 19 23:08:24 openHABianPi influxd[406]: [httpd] 127.0.0.1 - openhab [19/Nov/2018:23:08:24 +0100] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=openhab HTTP/1.1" 204 0 "-" "okhttp/2.4.0" a21f3831$
Nov 19 23:08:54 openHABianPi influxd[406]: [httpd] 127.0.0.1 - openhab [19/Nov/2018:23:08:54 +0100] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=openhab HTTP/1.1" 204 0 "-" "okhttp/2.4.0" b400dafa$
Nov 19 23:09:24 openHABianPi influxd[406]: [httpd] 127.0.0.1 - openhab [19/Nov/2018:23:09:24 +0100] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=openhab HTTP/1.1" 204 0 "-" "okhttp/2.4.0" c5e28e36$
Nov 19 23:09:54 openHABianPi influxd[406]: [httpd] 127.0.0.1 - openhab [19/Nov/2018:23:09:54 +0100] "POST /write?consistency=one&db=openhab_db&p=%5BREDACTED%5D&precision=n&rp=autogen&u=openhab HTTP/1.1" 204 0 "-" "okhttp/2.4.0" d7c42e49$

Excerpt from

/etc/influxdb/influxdb.conf

[http]
  # Determines whether HTTP endpoint is enabled.
   enabled = true

  # Determines whether the Flux query endpoint is enabled.
  # flux-enabled = false

  # The bind address used by the HTTP service.
   bind-address = ":8086"

  # Determines whether user authentication is enabled over HTTP/HTTPS.
   auth-enabled = true


My influxdb.cfg:

# The database URL, e.g. http://127.0.0.1:8086 or https://127.0.0.1:8084 .
# Defaults to: http://127.0.0.1:8086
url=http://127.0.0.1:8086

# The name of the database user, e.g. openhab.
# Defaults to: openhab
user=openhab

# The password of the database user.
password=supersecret

# The name of the database, e.g. openhab.
# Defaults to: openhab
db=openhab_db

# The retention policy to be used, needs to configured in InfluxDB
# Till v0.13: 'default', since v1.0: 'autogen'
retentionPolicy=autogen

Any idea why Grafana is not able to connect to the DB?

change the Data Source type from Graphite to InfluxDB :slight_smile:

2 Likes

@Dim

Shame on me, the only setting I did not transfer carefully.

I remember one of my profs saying “90% of all problems can be solved by looking carefully!”

He was right, thank you!

1 Like

Try this in grafana.ini

[auth.basic]
enabled = false

Hi thread.
I have made an effort of automate the initial installation and configuration for InfluxDB + Grafana within the scope of the openhabian project. If you have some spare time please help me test it out before I merge it.

Have a missed some essential feature/configuration that every user need to do?

3 Likes

This is great! How exactly might one go about testing this?

Is there a git command that can be used to fetch this particular commit into existing directory (/opt/openhabian/functions) of an existing openhabian setup?

followed by running the openhabian-config wizard?

If so, I could potentially give this a whirl on a fresh installation of a Raspberry Pi3B and report back.

… 2 days later…


Right or wrong, I manually merged your updated code to the 2 files (openhab.sh and packages.sh) in the folder /opt/openhabian/functions of my new install which seemed to do the trick!. Then I ran the command

$ sudo openhabian-config

I chose the option to install influxdba+grafana. and i believe it was running using this updated code. However, line 419 should be updated as the message still includes the text “Soon this procedure will also set up the connection between them and with openHAB.” which was misleading…

Anyway, here is the error I received on my raspberryPi 3B. It looks like the wrong package architecture was downloaded.

I corrected manually by downloading the following file:

wget https://dl.grafana.com/oss/release/grafana_5.4.0_armhf.deb 
sudo dpkg -i grafana_5.4.0_armhf.deb 

Here is the error I received.

$ dpkg -i grafana_5.3.4_arm64.deb 
dpkg: error processing archive grafana_5.3.4_arm64.deb (--install):
 package architecture (arm64) does not match system (armhf)
Errors were encountered while processing:
 grafana_5.3.4_arm64.deb

$ systemctl daemon-reload 

$ systemctl enable grafana-server.service 
Failed to enable unit: File grafana-server.service: No such file or directory

Thanks for testing out!
Looks like I didn’t really got the installation correct with Grafana.
I will look into it!

Thanks! Again, great work.

I look forward to seeing this in the latest openhabian build soon! It will be helpful to many.

Sorry if this is the wrong place to post, let me know and i will change accordingly.

I am having a hell of a time finding this answer. I’v been searching for days and came up short. How do I display my Switch status ( ON/OFF ) on a Graph? I want to compare certain Sonoff’s ON and OFF states compared to when I am Home/Away . Also, How would you display a string ( Home/Away)? Is there a way where you can assign ON=1 and Away=0 in the metrics area? Sorry if this is a NOOB question I am very new to Grafana and Influx.

Thanks!

I’m not using influx so I can’t answer the second part of your question. For MySQL you can have a mapping in the query. Not sure if this is also possible with influx.

But for the first part (how to display concrete values) I can recommend the “discrete” widget.

Follow the installation instructions as this plugin is not part of the standard installation.

Greetings
Sebastian

1 Like

Hi @ThomDietrich. Thank you for the terrific tutorial on installing InfuxDB and Grafana. Without this tutorial I would have had no idea how to do this.

I performed an install on my Raspberry Pi 3B a couple of days ago on 12/15/18. The instructions were flawless other than the location of some of the repositories changed. Here are the steps i followed.

Starting point:

Raspberry Pi 3B
OpenHAB version: 2.3.0-1 installed with openHABianPi
Raspberry Pi version: Raspbian GNU/Linux 9 (stretch)
apt-transport-https is already present (apt list apt-transport-https)

InfluxDB

From this link the recommended installation for stretch is:

curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update
sudo apt-get install influxdb

sudo systemctl start influxdb

To enable InfuxDB on startup execute the following commands

sudo systemctl daemon-reload
sudo systemctl enable influxdb.service

Granafa

Grafana now has a package for Raspberian stretch. The Grafana arm architecture packages can be found here. The Raspberian stretch architecture is ARMv7 (not ARM64 as the operating system is compiled as a 32 bit OS).

Installation is:

sudo wget https://dl.grafana.com/oss/release/grafana_5.4.2_armhf.deb 
sudo dpkg -i grafana_5.4.2_armhf.deb 

If you want Grafana to start at system startup execute the following commands:

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server

Finally, to start Grafana execute:

sudo /bin/systemctl start grafana-server

Add phantomjs to the Grafana install

Grafana for the ARM architecture does not come with a package to render a graph using a direct link. When clicking on the “Direct link rendered image” button on Grafana a page with “404 page not found” will be shown. This can be fixed by downloading a phantomjs created by @fg2it. It is located here. Copy the phantomjs file to /usr/share/grafana/tools/phantomjs/

It seems that phantomjs is not longer being actively developed or supported. Therefore there may be a better alternative in the near future which means this part of these instructions may soon become obsolete.

Continue with the setup steps in the first posting.

4 Likes

Hi,
I have updated to openhab 2.4 and therefore also grafana have been updated to version 5.4.2.
I have used the direct link rendered images of grafana with the openhab images like the following.

Image url="http://<grafana_ip>:3000/render/dashboard-solo/db/openhab_temperature?width=AUTO&height=AUTO&from=NOW-24&amp;to=NOW&amp;panelId=1&amp;theme=light" refresh=300000

I just wondered why the charts are no longer working, but I have noticed after removig

width=AUTO&height=AUTO

then the chart is rendered, but it does not fit to my screen size.

Does anybody now how to solve this?

Thanks in advance.

Best Regards,
Marcel

Regarding adding phantomjs manually as described a few inches above… first, thank you for that. I was PISSED when I googled and found Grafana’s stance on it was basically “Too bad, screw off”. Glad you guys had that covered.

When I saved the phantomjs file and copied it in, I found it didn’t have execute permissions, so it still didn’t work. I’ve seen that happen numerous times when downloading files off github like this.
sudo chmod 755 /usr/share/grafana/tools/phantomjs/*

Fully operational! And my god this is so much better than the clunky implementation of mySQL.

When I put the direct image into my sitemap, it works in the browser on my PC. But not in the OpenHAB app on my android device. Does the image direct link also not work without the full WAN reachable address?

So instead I have a rule with a cron that does a wget of the direct image link. The wget saves it to /etc/openhab2/html/grafana, which is really the only place it can go that is readily accessible from sitemaps.