InfluxDB+Grafana persistence and graphing

influxdb
graphs
grafana
Tags: #<Tag:0x00007fe05da15280> #<Tag:0x00007fe05da150f0> #<Tag:0x00007fe05da14ec0>

(Elias Gabrielsson) #674

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?


(Gadget Guy) #675

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


(Elias Gabrielsson) #676

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


(Gadget Guy) #677

Thanks! Again, great work.

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


(Justin B) #678

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!


(Sebastian) #679

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


(Bob Raker) #680

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.


(Marcel Salein) #681

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


(Matt) #682

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.


(Matt) #683

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.


(jimmy loyens) #684

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:)


(Udo Hartmann) #685

Did you read this post:


?


(jimmy loyens) #686

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:


(jasper) #687

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

Thx.


(jimmy loyens) #688

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.


(Kim Andersen) #689

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.


(Kim Andersen) #690

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!


(jimmy loyens) #691

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.


(Udo Hartmann) #692
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

(jimmy loyens) #693

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: