Tutorial - Grafana rendering on Raspberry Pi

Hi @Chrishab, @David_deMarco,
I’m facing the same “Rendering failed: Error: Failed to launch chrome!” issue.
The deployment of the rendering module was really smooth, no errors at all. During the install I also noticed Chrome getting installed. After restart of Grafana the module is loaded and listed.
This is happening on a Raspberry Pi 4, latest Openhabian test release.
I have the exact same deployment running on an Ubuntu VM. Followed the same deployment steps listed here and the result is a perfectly operating rendering module.
So it seems Buster / Raspberry related?

Thnx,
E

Hi all
Okay. I getting abit confused on this all with regards to the Chrome install.

My last test was on a blank install of OpenHabian then followed the instructions I thought I had edited.

Seen some other versions of the install so not sure how to update this yet. I removed all the additional info on adding chrome as my install worked without it

Appreciate a few users are following this so will try and recreate it this again. Please be aware I am offline travelling until 10 Dec from next week.

Don’t do the instructions of installing Chrome. I know they were in the first set and I thought I had removed them.

The Current instruction will include pupeteer and you don’t need to install chrome and all that. This worked for me on a fresh test install.

Understand that I now seem to be the lead on how this works and happy to follow up on that. Please be aware I’m not around for the next month so all follow up details welcome.

Hey @David_deMarco, thanks for the hard work on this, really appreciated.
Just wanted to let you know I gave up on rendering on the Pi4. I’ve done a couple of fresh installs on the Pi using Openhabian as a base OS (I’m quite the expert on this these days) and I must say everything (time over time) evrything worked perfectly except the last mile . . the rendering.
I already had an Ubuntu VM that I used for testing and found that running Grafana on that VM rendered like a charm.
So now I removed Grafana from my ‘production’ Pi4 (kept Influx on the Pi4) and use the Ubuntu based Grafana as a centralized instance for Graphing and Rendering using various databases running on different Pi’s.
:slight_smile:

For what it’s worth, this will NOT work on a Raspberry Pi 3B+ on Buster.

Some node.js packages can’t be installed (puppeteer, husky) and the compilation aborts in a matter of seconds.

1 Like

I have the same problem… Everything works on the Pi4, and it finally can handle all my things in one device, but the rendering doesn’t seem to work… I tried it multiple times, always stuck somewhere…

Hello,

sorry, but i did not understood this lines. It must looks so http://prntscr.com/pxy193 ?

after this i get error

[23:13:11] root@openhab:/var/lib/grafana/plugins/grafana-image-renderer# yarn run build
yarn run v1.19.1
$ yarn run tsc
error Command "tsc" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

How it can be fixed?

I am on OH 2.5M4 on Pi4

Hi.
I am travelling in Myanmar at the moment so can’t investigate this further. Back mid Dec

Have a good trip! We will be waiting)

Just to chime in, I end up with the same chrome error error once everything is installed

t=2019-11-17T21:30:52+0100 lvl=eror msg="Rendering failed." logger=context userId=1 orgId=1 uname=admin error="Rendering failed: Error: Failed to launch chrome!\n/var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: 1: /var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: Syntax error: Unterminated quoted string\n\n\nTROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md\n"
t=2019-11-17T21:30:52+0100 lvl=eror msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=GET path=/render/d-solo/vL8w4giRk/basement-office-thermostat status=500 remote_addr=10.13.2.11 time_ms=61 size=1722 referer="http://10.13.0.41:3000/d/vL8w4giRk/basement-office-thermostat?orgId=1"

In order to get everything installed I had to do the following:

After apt-get install git it did:
apt-get install nodejs

before the npm install I had to do the following also:

npm install typescript -g
sudo npm i husky
sudo npm i puppeteer
sudo npm i postinstall
1 Like

Here are instructions for compiling it on the RPi3B+:

sudo su
cd /var/lib/grafana/plugins
git clone https://github.com/grafana/grafana-image-renderer
cd grafana-image-renderer

Now we’ll update npm, just in case:

npm -g install npm

Now we’ll install yarn and typescript:

npm -g install yarn
npm -g install typescript

The following line is essential for compiling the plugin’s dependencies on a RPi3B+ on openhabian buster:

npm config set unsafe-perm=true

We can now at last add the Node.JS dependencies to compile the plugin:

npm i grpc

npm i husky
npm i puppeteer
npm i postinstall
npm i install
npm install

Time to edit add // @ts-ignore above 2 TypeScript lines (see above):

cd src
nano grpc-plugin.ts

And now we can build the plugin:

cd ..
yarn run build

Copy plugin_start_linux_amd64 as plugin_start_linux_arm and restart the Grafana server:

cp plugin_start_linux_amd64 plugin_start_linux_arm
systemctl restart grafana-server.service

After 10 seconds, verify that the plugin has been loaded successfully:

systemctl status grafana-server.service

Look for the following log lines:

Nov 24 12:11:58 openhab grafana-server[18874]: t=2019-11-24T12:11:58+0100 lvl=info msg="Renderer plugin found, starting" logger=rendering cmd=plugin_start_linux_arm
. . .
Nov 24 12:12:00 openhab grafana-server[18874]: t=2019-11-24T12:12:00+0100 lvl=info msg="Renderer plugin started" logger=rendering timestamp=0001-01-01T00:00:00.000Z

Have fun!

AWESOME step by step @shutterfreak
Thank you for all your help :muscle:

Thanks @shutterfreak for updating the tutorial for RPi3B+
Unfortunately I still end up with an error in the log like before.

t=2019-11-24T15:41:54+0100 lvl=eror msg="Rendering failed." logger=context userId=1 orgId=1 uname=admin error="Rendering failed: Error: Failed to launch chrome!\n/var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: 1: /var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: Syntax error: Unterminated quoted string\n\n\nTROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md\n"

I’ve deleted the folder grafana-image-renderer, followed every step and besides very few warnings everything looked fine in the console.

npm WARN renderer@1.0.0 No repository field.

When I try to export a graph to an image, I also run into the same error messages in /var/log/grafana/grafana.log:

t=2019-11-24T20:53:30+0100 lvl=eror msg="Render request failed" logger=rendering url="http://localhost:3000/d-solo/Bj1viEiRk/weather?orgId=1&from=1572029597812&to=1574625197812&panelId=9&width=1000&height=500&tz=Europe%2FBrussels&render=1" error=map[] timestamp=0001-01-01T00:00:00.000Z
t=2019-11-24T20:53:30+0100 lvl=eror msg="Rendering failed." logger=context userId=1 orgId=1 uname=admin error="Rendering failed: Error: Failed to launch chrome!\n/var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: 1: /var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: Syntax error: Unterminated quoted string\n\n\nTROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md\n"
t=2019-11-24T20:53:30+0100 lvl=eror msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=GET path=/render/d-solo/Bj1viEiRk/weather status=500 remote_addr=[::1] time_ms=429 size=1730 referer="https://shutterfreak.routemehome.com/grafana/d/Bj1viEiRk/weather?orgId=1&from=now-30d&to=now"

So it appears that the renderer plugin complains about an unterminated string somewhere. Problem is that /var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome is an ELF binary and not a script, so it must be a problem within one of the JavaScript (TypeScript) files.

Maybe puppeteer expects a launch script instead of the chrome binary?

It appears that puppeteer installs the wrong binary for the chrome browser:

$ sudo su
# /var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome --version
bash: /var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: cannot execute binary file: Exec format error

No wonder that the Grafana renderer plugin bails out.

My bet is that the chrome binary shipped with puppeteer is for the wrong processor architecture.

UPDATE: This is apparently a know problem of puppeteer: https://github.com/puppeteer/puppeteer/issues/550

I installed a recent snapshot of the chromium-browser package, and that one reports:

# apt list --installed | grep -i chrom

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

chromium-browser-l10n/testing,now 74.0.3729.157-rpt5 all [installed,automatic]
chromium-browser/testing,now 74.0.3729.157-rpt5 armhf [installed]
chromium-codecs-ffmpeg/testing,now 74.0.3729.157-rpt5 armhf [installed]

# which chromium-browser 
/usr/bin/chromium-browser

# /usr/bin/chromium-browser --version
Chromium 74.0.3729.157 Built on Raspbian , running on Raspbian 10

Now I need to figure out either how to replace the incorrect chrome image deployed by puppeteer or by configuring the grafana renderer plugin to use /usr/bin/chromium-browser (or a compatible version for puppeteer).

Actually getting the render plugin to use your custom chromium is very simple :wink: once you figure out how.
Add this line

export GF_RENDERER_PLUGIN_CHROME_BIN="/usr/bin/chromium-browser"

just above the

node ${DIR}/build/app.js

in plugin_start_linux_arm

I actually managed to install the chromium browser just by going sudo apt-get install chromium-browser

However I am still not there as I now get the following errors in the grafana logs

t=2019-11-26T09:36:56+0100 lvl=info msg="Renderer plugin started" logger=rendering chromeBin=/usr/bin/chromium-browser ignoreHttpsErrors=false timestamp=0001-01-01T00:00:00.000Z
t=2019-11-26T09:37:35+0100 lvl=eror msg="Render request failed" logger=rendering url="http://localhost:3000/d-solo/45sF64igk/air-quality?orgId=1&from=1574735848638&to=1574757448638&panelId=2&width=1000&height=500&tz=Europe%2FParis&render=1" error=map[] timestamp=0001-01-01T00:00:00.000Z
t=2019-11-26T09:37:35+0100 lvl=eror msg="Rendering failed." logger=context userId=1 orgId=1 uname=admin error="Rendering failed: Error: Protocol error: Connection closed. Most likely the page has been closed."
t=2019-11-26T09:37:35+0100 lvl=eror msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=GET path=/render/d-solo/45sF64igk/air-quality status=500 remote_addr=10.13.2.11 time_ms=4095 size=1722 referer="http://10.13.0.41:3000/d/45sF64igk/air-quality?orgId=1"

UPDATE:
Maybe I should just have tried running chromium headless first which gives this error:
Failed to put Xlib into threaded mode.

Thanks for this update!

I have the impression that puppeteer requires a specific version of the chromium browser, and that it is impossible to find as it’s not pre-built for the ARM processor architecture. In the thread I mentioned in my earlier post (https://github.com/puppeteer/puppeteer/issues/550) it seems that some people tried to cross-compile chromium-browser so it could run on a Raspberry Pi 3B+ / 4.

However, given the RPi3 is very tight on memory (1GB), I fear that running the chromium browser from puppeteer will be very slow and will wear out the SD card in no time due to the need of swap space for running. Hence I decided to abandon this track.

You may want to try the following instructions: https://code-flow-hjbello.blogspot.com/2018/11/make-puppeteer-work-with-raspbian-vers.html

That did the trick! I followed the instructions in you last link and used the added line of code from @petero
Works like a charm now in grafana. Thanks!

1 Like

And just as I gave up and moved the rendering to a docker instance on a separate server. Kudos to you for persistence. How is the performance? Are you in Rpi 4 or 3?

RPi3+ takes around 5 seconds to render, no matter about the size of the images

Hey,
I’am had the same problems, i managed it to cross-compile the right Chrome version. The pupeteer-versions that ships with the Pluging need a specific Chrome Version.

Feel free to use my Compiled bin, you only must replace it in the Folder /var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux

Chromium Binary