InfluxDB+Grafana persistence and graphing

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.

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: