Tutorial - Grafana rendering on Raspberry Pi

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 Screenshot by Lightshot ?

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

Hi Andre,

I tried your compiled version but unfortunately it’s not working for me (Pi 4).
How did you compile it, maybe I can compile it as well?

Based on your post I tried again to install the Grafana renderer plugin.

Eventually I managed to run chrome but I first had to set the executable bit on the binary (trivial with chmod +x chrome) and then I had to install some missing shared libraries:

# apt install libxcomposite1
# apt install libxcursor1
# apt install libxdamage1
# apt install libxi6
# apt install libxtst6
# apt install libxrandr2
# apt install libpangocairo-1.0-0
# apt install libatk-bridge2.0-0
# apt install libgtk-3-0

Now I am able to run chrome and display the version:

#./chrome --version
Chromium 70.0.3508.0

However, after restarting the Grafana service, I still get a server error. In the logs I see the following error:

Rendering failed: Error: Failed to launch chrome!
Received signal 11 SEGV_MAPERR 000000000000
#0 0x000001ea2160 <unknown>
#1 0x000001ea20d6 <unknown>
#2 0x000075ba3130 <unknown>
#3 0x000001e93970 <unknown>
#4 0x0000010c6f66 <unknown>
#5 0x0000010c54ec <unknown>
#6 0x000000ee850e <unknown>
#7 0x000000ee6798 <unknown>
#8 0x0000011264c6 <unknown>
#9 0x000000ee637c <unknown>
#10 0x000000ee8e86 <unknown>
#11 0x0000048c0ff0 <unknown>
#12 0x000001b8b4d0 <unknown>
#13 0x000001baf032 <unknown>
#14 0x000001b8a0fc <unknown>
#15 0x00000423aa2e <unknown>
#16 0x00000423aa70 <unknown>
#17 0x000001badd2e <unknown>
#18 0x0000008d9966 ChromeMain
#19 0x000075b8d718 __libc_start_main
[end of stack trace]
Calling _exit(1). Core file will not be generated.


TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md

So I’m not there yet…

It appears that when running chrome without arguments, it tries to invoke other binaries which are also ELF (so unusable for ARM architecture). The first one is nacl_helper_bootstrap:

# ./chrome --no-sandbox
/var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/nacl_helper_bootstrap: 1: /var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/nacl_helper_bootstrap: ELF: not found
/var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/nacl_helper_bootstrap: 2: /var/lib/grafana/plugins/grafana-image-renderer/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/nacl_helper_bootstrap: Syntax error: "(" unexpected
[23041:23041:1202/224016.893634:ERROR:nacl_fork_delegate_linux.cc(314)] Bad NaCl helper startup ack (0 bytes)

(chrome:23039): Gtk-WARNING **: 22:40:16.899: cannot open display: 

By the way, running ./chrome --headless --no-sandbox also yields the same stack trace:

# ./chrome --headless --no-sandbox
Received signal 11 SEGV_MAPERR 000000000000
#0 0x000001e48160 <unknown>
#1 0x000001e480d6 <unknown>
#2 0x000075b59130 <unknown>
#3 0x000001e39970 <unknown>
#4 0x00000106cf66 <unknown>
#5 0x00000106b4ec <unknown>
#6 0x000000e8e50e <unknown>
#7 0x000000e8c798 <unknown>
#8 0x0000010cc4c6 <unknown>
#9 0x000000e8c37c <unknown>
#10 0x000000e8ee86 <unknown>
#11 0x000004866ff0 <unknown>
#12 0x000001b314d0 <unknown>
#13 0x000001b55032 <unknown>
#14 0x000001b300fc <unknown>
#15 0x0000041e0a2e <unknown>
#16 0x0000041e0a70 <unknown>
#17 0x000001b53d2e <unknown>
#18 0x00000087f966 ChromeMain
#19 0x000075b43718 __libc_start_main
[end of stack trace]
Calling _exit(1). Core file will not be generated.

Hey,

I used these Links and a Ubuntu VM to Cross-Compile

Build on Linux https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md#Get-the-code
Build Old Version https://chromium.googlesource.com/chromium/src/+/master/docs/building_old_revisions.md
Linux ARM https://chromium.googlesource.com/chromium/src.git/+/master/docs/linux_chromium_arm.md#Recipe1_Building-for-an-ARM-CrOS-device
Chromium work with branches / tags

you must checkout the right Branch, even it wont work with puppeeter.
for puppeeter 1.7.0 it is Chrome Version 70.0.3508.0

Hey shutterfreak,

it was my mistake, i had think, that I only replaced the chrome binary. But I replaced more… Like the nacl_helper_bootstrap.

Now you can find at my github link above the complete chromium folder from my working setup.

Hope now it will run… :wink: