Grafana Image Renderer

We have all had issues with Grafana generating static png charts for some time now. The root cause is PhantomJS. According to the docs on Grafana’s website:

PhantomJS is deprecated since Grafana v6.4 and will be removed in a future release. Please migrate to Grafana image renderer plugin or remote rendering service.

For at least a year now rendering the images on an RPi has been unavailable as PhantomJS would run amok and consume all the resources until openHAB itself was killed by the kernel. As of the past couple of weeks, it appears there has been an update made where rendering the pngs using PhantomJS even on more powerful machines no longer works (perhaps they finally removed the library).

Why not just use a webview? I’ve never had good luck with webviews. Either the Android app won’t show it, or it won’t work through a reverse proxy or through myopenhab.org. If I generate static images it works everywhere.

Thankfully, Grafana now provides a separate image renderer plugin for rendering charts to pngs.

Installation

You have a few options for installing this plugin.

  • If Grafana is installed on your machine, you can use grafana-cli.

    grafana-cli plugins install grafana-image-renderer

  • Alternatively, you can download the zip file and unpack it into the plugins folder (see the link above for the latest links to the downloads).

  • Finally, you can run the renderer as a separate service using Docker. This approach is handy if you want to host the render on a host separate from your Grafana instance.

I run Grafana in Docker and I tried to install the plugin but it will not work. I get the following error:

Oct  9 15:05:49 argus 1f33221f8c3a[1686]: t=2019-10-09T15:05:49-0600 lvl=eror msg="Rendering failed." logger=context userId=0 orgId=1 uname= error="Rendering failed: Error: Failed to launch chrome!\n/var/lib/grafana/plugins/grafana-image-renderer/chrome-linux/chrome: error while loading shared libraries: libX11.so.6: cannot open shared object file: No such file or directory\n\n\nTROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md\n"
Oct  9 15:05:49 argus 1f33221f8c3a[1686]: t=2019-10-09T15:05:49-0600 lvl=eror msg="Request Completed" logger=context userId=0 orgId=1 uname= method=GET path=/render/d-solo/000000001/home-automation status=500 remote_addr=10.10.1.138 time_ms=16 size=1722 referer="http://argus:3000/d/000000001/home-automation?orgId=1"

So it looks like I have to host a separate container for the renderer. Instructions for doing so are located at https://github.com/grafana/grafana-image-renderer/blob/master/docs/remote_rendering_using_docker.md.

That provides a DockerCompose file. I use Ansible so I’ll show that below:

- name: Pull and run latest Grafana image
  docker_container:
    detach: True
    exposed_ports:
      - "3000"
    hostname: grafana.koshak.net
    image: grafana/grafana
    log_driver: syslog
    name: grafana
    env:
      GF_USERS_ALLOW_SIGN_UP: "false"
      GF_AUTH_ANONYMOUS_ENABLED: "true"
      GF_SECURITY_ALLOW_EMBEDDING: "true"
      GF_SECURITY_COOKIE_SECURE: "true"
      GF_SECURITY_COOKIE_SAMESITE: "none"
      GF_RENDERING_SERVER_URL: "http://10.10.1.127:8081/render"
      GF_RENDERING_CALLBACK_URL: "http://10.10.1.127:3000/"
      GF_LOG_FILTERS: "rendering:debug"
    published_ports:
      - "3000:3000"
    pull: True
    restart: True
    restart_policy: always
    volumes:
      - "{{ grafana_data }}:/var/lib/grafana"
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/passwd:/etc/passwd:ro"

- name: Pull and run the latest grafana image renderer
  docker_container:
    detach: True
    exposed_ports:
      - 8081
    image: grafana/grafana-image-renderer:latest
    log_driver: syslog
    name: grafana-image-renderer
    published_ports:
        - "8081:8081"
    pull: True
    restart: True
    restart_policy: always

NOTE: I need to change the IP address above to use the ansible variables to make it more generic. You should use the IP address of the machine these containers are deployed to.

Use

Just like with PhantomJS, click on the title of one of your panels in Grafana and choose “Share”

Then click on “Direct link rendered image”. See InfluxDB+Grafana persistence and graphing or the Grafana docs for details on how to fill in the URL parameters for the time periods you care about.

See Grafana Image Charts for a Rule that will call the URL to generate the chart images only as often as necessary based on the time period currently selected in the UI. Without something like this, Grafana will be generating the images for all the panels and all the views whether they are being used or not. Since this is an expensive operation, using this Rule will reduce the cost to the minimum.

12 Likes

Is this new in Grafana 6.4.x and their new rendering plugin?
I use Grafana 5.4.3 on a windows server, and I still use the phantomjs.
I dont see any activity unless I´m on a sitemap which calls Grafana?

I don’t know how new the image renderer plugin is. Last week my charts stopped rendering, failing with a timeout. Yesterday I had a chance to look into it and their docs now state PhantomJS is deprecated and will be soon removed and to use the plugin instead. Hence this tutorial.

That should be completely explained in that other tutorial. The tl;dr is if you use visibility to show charts of a different period, Grafana has to generate all the images for all the time periods regardless of which one is visible. With the Rule at that link, only the charts for the time period you are actually looking at are rendered. If you have last: hour, day, week, month, and year, you will see a 4x reduction in load on Grafana using that Rule over using visibility.

Hmm okay I see your point… Its when using several images and visibility. I have one sitemap where I have 3 charts on at the same time. Grafana render this every 30 second, but only when I´m on the sitemap.

When I try to install the plugin on my RPi4 through grafana-cli, I get the following error:

Error: ✗ Plugin is not supported on your architecture and os.

I’m on openhab 2.4 and grafana 6.4.2. Is the plugin supposed to work in this environment?

1 Like

It’s complaining about architecture (i.e. to if CPU) and OS (i.e. operating system, e.g. Linux). Are you on an RPi? If so it seems not to be supported.

Grafana had no knowledge of ooenHAB.

I am experiencing the issues you are describing with the kernel killing openhab when all ressources are gone. I wanted to try your guide but got the following reply :

grafana-cli plugins install grafana-image-renderer
Failed to send requesterrorApi returned invalid status: 404 Not Found
Error: ✗ Failed to send request. error: Api returned invalid status: 404 Not Found

NAME:
   Grafana cli plugins install - install <plugin id> <plugin version (optional)>

USAGE:
   Grafana cli plugins install [arguments...]

I then checked my Grafana version and it is 5.1.4…I have just apt updated and upgraded my system, but Grafana remains 5.1.4 - not 6.4 which is the most recent. Any idea as to why it does not upgrade and what to do?
Running openhabian on raspberry pi 3B+

I may be wrong, but afaik grafana is not part of standard archives. I’m not sure about how openhabian handles grafana stuff either. Did you update openhabian-config yet?

I run Grafana in Docker so I don’t really know how openHABian installs it not how to install it using apt.

yep - I updated the openhabian-config, but still the same…

When I did the same long time ago. I noticed I had to uninstall the old Grafana, and then install the new one manually. It might be worth a try.
Remember to make a backup of your charts if any, (easily done with export json files, which afterwards can be imported to the new version).
Please notice - Today I´m running Grafana on a windows server, cause I simply gave up getting Grafana to render a chart on a Rpi3B+ Grafana consume too much resources when rendering with phantomjs, so it will breake Java and then kill openhab.

I am constantly updating Grafana with a regular reinstall. The old version does not need to be deleted. all charts remain in place. At the same time, no one canceled the backup.
The download page https://grafana.com/grafana/download has all the recommendations. They change with the release of a new stable version. It is necessary to execute only two teams.

Thanks all of you. I manually updated and am now running newest version.
Using this tutorial I now have the Grafana image renderer plugin working on my Rpi3B+ :slight_smile:

I’m glad you got it working and thanks for the confirmation that it works on an RPi.

HI Rich,

  1. after this command i get the messege
Error: ✗ Plugin is not supported on your architecture and os.

i am on 2.5M4 on Pi4 and Grafana v6.4.4

  1. Tried manual installation, but on this page https://grafana.com/grafana/plugins/grafana-image-renderer/installation the link with zip is unavailable Screenshot by Lightshot
    1.0.0 https://grafana.com/api/plugins/grafana-image-renderer/versions/1.0.0/download
    1.0.5 https://grafana.com/api/plugins/grafana-image-renderer/versions/1.0.5/download

It means i have no ability to render grafana images? :sleepy:

PS
Manual install from this thread also gives error

I don’t run it on an RPi so I can’t be of much help. But @sapster77 posted a link to a tutorial that might help.

1 Like

Thanks but as said above - Manual install from this thread also gives error

So it seems to be no way to render grafana on pi4 and the most bad thing is that according all that no way to get grafana on the myopenhab cloud and outside the local network.
It a pity.

Via the link I posted above I made it run nicely on a Pi3 (local network). I can see that the thread has now been updated to also include instructions for a Pi4, so you could try that.
Let us know if it works:-)

What did you do to make it work on a RPi3B+? So far all my attempts, following those instructions, failed. Compilation always ended prematurely.

EDIT: here are the instructions for compiling the new Grafana renderer plugin on RPi3B+:

Super - so you made it work:-) Thanks for sharing the updated solution.