InfluxDB+Grafana persistence and graphing

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.

Hello,

Today i setup grafana+influxdb and made my first charts. Then i tried to insert my chart in a sitemap as image element but the chart wont render in basic UI. I don’t know if/what i’m doing wrong. I used the html i got from selecting the share option of the chart in grafana an input it in the sitemap like this:

Image refresh=300000 url="http://openhabianpi:3000/d/s4ZZzUZRk/eetkamer-temperatuur?orgId=1&panelId=2&fullscreen&from=1545824491566&to=1545846091568"

Wich doesn’t work. then i noticed a difference between my html and the one in the tutorial. So allso tried this:

Image refresh=300000 url="http://openhabianpi:3000/d/s4ZZzUZRk/eetkamer-temperatuur?orgId=1&panelId=2&width=700&height=350&from=now-48h&to=now"

but still no result. When i try clicking " [Direct link rendered image]"

http://openhabianpi:3000/render/d-solo/s4ZZzUZRk/eetkamer-temperatuur?orgId=1&amp;panelId=2&amp;from=1545824491566&amp;to=1545846091568&amp;width=1000&amp;height=500&amp;tz=Europe%2FBerlin

I get an error saying: “Rendering failed - PhantomJS isn’t included in arm build per default”.
So i think the problem is i don’t have PhantomJS installed on my rpi. I tried installing 3 different packages of PhantomJS that were build for rpi, but can’t get it working.

When i try inserting a chart in habpanel (embedded) it works fine.

I’m running openhabian on a rpi3. grafana is installed on the same pi. Can anyone point me in the right direction? Maybe i’m doing something stupid since i’m not so gifted when it comes to linux (its kind of a wonder i got this far :blush:)

Did you read this post:

?

Hello,
I must say i didn’t read this post. I’ve been reading alot on the subject yesterday but not this post. Thanks for pointing me to it :grinning:. But as i said i’m not so gifted with linux :frowning_face: so i’m not sure what to do with this file. I guess i have to copy it to the pi and then run it somehow. Is this correct?

Thanks for putting up with this noob :grin:

How much changes are there I used the Openhabian-config > addon Influxdb+Grafana?

Thx.

I used the openhabian config to. Everything worked pretty much out of the box. Db’s got created automaticly. I only needed to link db in grafana and everything was up and running. Only problem i’m facing is phantomjs, needed to display grafana charts in sitemap.

Did you solve this ?? I just upgrade grafana to latest (5.4.x) from 5.1.4. And now I´m facing the same… Need phantomjs. And it´s not included with Grafana, plus very limited info on how to use it.

I found the solution… Actually it´s the link provided from Udo above… And a few messages above that from BobRak :slight_smile:

Anyway - this is it:

But… openhabian does not have permission to that folder… So you´ll need to enter a terminal and use Sudo to copy the file into there. Like this:

 sudo cp /home/openhabian/phantomjs /usr/share/grafana/tools/phantomjs/

After that, you´ll need to set the execute permission to the phantomjs file:

sudo chmod 755 /usr/share/grafana/tools/phantomjs/*

And you´re good to go!

1 Like

Thanks for the info, if you could just help me one more little bit. I dont know how i can get the file into /home/openhabian. Do you download it from the above link via commandline? If so how do you do that? (Im a complete linux noob :frowning_face: sorry) or do you do this via the openhab share? If so, Wich directory do you put it in? Cant find /home/openhabian here.
Sorry for my stupid question, i have a lot of learning to do when it comes to linux and ssh commands.
Thanks

Edit:
Is this right?

wget -P /home/openhabian/“https://github.com/fg2it/phantomjs-on-raspberry/blob/master/rpi-2-3/wheezy-jessie/v2.1.1/phantomjs
?

Thanks

Edit:
I must have done something wrong. I used the wget command above to download the file, then copied it with first command you gave and then set the permissions as per your second command. When i go look in /usr/grafana/tools/ i can see the file phantomjs, so i think i did it. But i still cant visualise the chart in basic ui. When i click on ‘direct link rendered image’ i no longer get the error that phantomjs is missing but just an error ‘rendering failed’. Do you have any idea how i can get to the grafana server log? I think i managed to install phantomjs correctly because the error message changed. Might be an other problem.

cd ~
wget https://github.com/fg2it/phantomjs-on-raspberry/raw/master/rpi-2-3/wheezy-jessie/v2.1.1/phantomjs
chmod 755 phantomjs
sudo chown root: phantomjs
sudo mv phantomjs /usr/share/grafana/tools/phantomjs/

However, as I didn’t upgrade grafa yet, I don’t know if the path exists per default, so maybe you have to create the folder first:

sudo mkdir -p /usr/share/grafana/tools/phantomjs
1 Like

Thanks for your help on the linux commands, but still no victory. when i use the “direct link rendered image” buttun in the share tab of my grafana chart i still get the message “Rendering failed.”.

When i look in the grafana server log I get these entries:

t=2018-12-30T11:03:56+0100 lvl=info msg=Rendering logger=rendering path="d-solo/s4ZZzUZRk/eetkamer-temperatuur?orgId=1&from=1546142584388&to=1546164184388&panelId=2&width=1000&height=500&tz=Europe%2FBrussels"
t=2018-12-30T11:03:56+0100 lvl=eror msg="Phantomjs exited with non zero exit code" logger=rendering error="fork/exec /usr/share/grafana/tools/phantomjs/phantomjs: exec format error"
t=2018-12-30T11:03:56+0100 lvl=eror msg="Rendering failed." logger=context userId=1 orgId=1 uname=admin error="fork/exec /usr/share/grafana/tools/phantomjs/phantomjs: exec format error"
t=2018-12-30T11:03:56+0100 lvl=eror msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=GET path=/render/d-solo/s4ZZzUZRk/eetkamer-temperatuur status=500 remote_addr=192.168.1.17 time_ms=13 size=1703 referer="http$

But thanks alot for your help on the linux commands, now I am shure phantomjs is insalled correctly. Now i’m going to take a look at the grafana docs to see how i can expand the logging for grafana and phantomjs. Maybe this way i will get some wiser. :wink:

Edit:
Tried setting the logs to debug in grafana.ini, but still the same 4 lines in the logs. No extra info :unamused:

Grafana is highly difficult, in my opinion, (I´m a Linux noob as well). I dont get the same errros you do, but I do seem to have problems rendering as well, if I render more than one chart at a time, the whole system lock up, (did the same with Grafana 5.1.4 after openhab has been upgraded from 2.3 to 2.4, thats why I thought updating Grafana to latest version would fix it… It didn´t).
So I can render one chart at at time… If I try to render more, my system locks up, crash and reboot. And Grafana log file is no good in this situation.

Something odd surely goes on, but I cant say for sure it´s because of Grafana. Since I updated openhab from 2.3 to 2.4, Grafana acting strange, and my system tend to crash and reboot a few minutes after I have rendered a few charts (one at a time).
I did make other changes as well, than just upgrade openhab. I also change from modbus1 to modbus 2 binding. But this was after openhab 2.3 has been running for a week or something like that, while Grafana was still acting strange.
I also get tons of binding errors and warnings when starting openhab, which never happened with openhab 2.3

Right now I´m close to give up on my system and start all over. I simply cant find the reason other than something seems very wrong on my system. I have a feeling its something with the openhab upgrade, in combination with grafana, maybe some permission problems somewhere.
But since I´m a total noob at Linux too, I have no knowledge of to how to correct or fix things like that.

PS. While writing this, I entered a sitemap on my system with two charts… System crashed and rebooted, again!
This is what Grafana log shows:

t=2018-12-30T17:51:53+0100 lvl=info msg=Rendering logger=rendering path="d-solo/pq1-vpgRz/casper-temperatur?orgId=1&panelId=2&from=now-12h&to=now&refresh=15s&width=1000&height=500"
t=2018-12-30T17:52:14+0100 lvl=info msg=Rendering logger=rendering path="d-solo/znwsvpRRz/lille-bad?refresh=30s&orgId=1&panelId=2&from=now-12h&to=now&width=1000&height=500"
t=2018-12-30T17:52:14+0100 lvl=info msg=Rendering logger=rendering path="d-solo/znwsvpRRz/lille-bad?refresh=30s&orgId=1&panelId=4&from=now-12h&to=now&width=1000&height=500"
t=2018-12-30T17:52:23+0100 lvl=eror msg="Phantomjs exited with non zero exit code" logger=rendering error="signal: killed"
t=2018-12-30T17:52:23+0100 lvl=eror msg="Phantomjs exited with non zero exit code" logger=rendering error="signal: killed"
t=2018-12-30T17:52:23+0100 lvl=eror msg="Rendering failed." logger=context userId=0 orgId=1 uname= error="signal: killed"
t=2018-12-30T17:52:23+0100 lvl=eror msg="Rendering failed." logger=context userId=0 orgId=1 uname= error="signal: killed"
t=2018-12-30T17:52:23+0100 lvl=eror msg="Request Completed" logger=context userId=0 orgId=1 uname= method=GET path=/render/d-solo/znwsvpRRz/lille-bad status=500 remote_addr=10.4.28.30 time_ms=9597 size=1722 referer="http://10.4.28.237:8080/basicui/app?sitemap=lillebad"
t=2018-12-30T17:52:23+0100 lvl=eror msg="Request Completed" logger=context userId=0 orgId=1 uname= method=GET path=/render/d-solo/znwsvpRRz/lille-bad status=500 remote_addr=10.4.28.30 time_ms=9656 size=1722 referer="http://10.4.28.237:8080/basicui/app?sitemap=lillebad"

First line is one sitemap with one chart.
Second line is a sitemap with two charts…
BAM! openhab restarted (notice my Rpi didn´t reboot, openhab just restart).

This is just great! :rage: