Grafana dashboard with direct access to emonCMS data

Hello all, I’m here to share with you how configure grafana to direct access to emoncms data. For this you need to use MARCUSOLSSON-JSON-DATASOURCE with this configuration:


Value of Header Authorization = Bearer APIKEY.

Next step, config your panel:
image
with params:
image
where id is feed id in emoncms.
sorry for my english. :slight_smile:

1 Like

and we get grafana dashboard

For get list of the feeds we need add new data source:

and config panel as table:

For get last value of the feed, we need add new data source:


and config panel as gauge:

with params:

3 Likes

Nicely done. thumbsup

1 Like

Thanks for sharing @Oleg that’s great!

Hallo Oleg
many thanks for sharing this. I tried to replicate what you did with for “timevalue” data but unfortunately without success. I can read the “timevalue” data via Postman from EMONCMS. but Grafana does not seem to get any data. I do not get any errors either.

Do you maybe have a more detailed description what you did to:

  1. get the Bearer APIKEY - I must assume this is something different then the “normal” API read api-key shown in the EMONCMS GUI?

  2. add a panel - e.g. did you add anything other tabs then “Fields” and “Params” - especially in the “Path” tab to define the data to be pulled?

Many thanks

Fredi


all good now - Fredi

Hi Fredi,

What did you have to do to fix it?

Sharing that info might help other users who have the same or similar problem.

Thanks!

I did not correctly read/understand the comment about the “Authorization” Header value: Bearer APIKEY
APIKEY needs to be replaced by the Read API Key numeric value which you find in EMONCMS under “My Account”. I guess this is pretty straight forward it you know what you are doing :wink:
The EMONCMS API descriptions helped me to better understand what this stands for.
Other than that I just followed Oleg’s description.
Really great how everything works together - EMON is just a perfect system

Many thanks

Fredi

BTW - I am running the open-source version of Grafana instance for Raspberry PI installation: Install Grafana on Raspberry Pi | Grafana Labs

You might want to have a look at this thread:

Thanks for posting the solution.

thumbsup

Hello all,
I am trying to replicate what Oleg did, unsuccessfully.
Timevalue, current value nor list are showing any data.
I am able to create the data sources. Below 3 screenshots:

  • Data Source settings
  • Panel Settings
  • browser output (JSON) from API



Any ideas?

PS: I just uploaded the one regarding the list, hoping that by solving this one, the others (time value and current value) will be also solved.

I didn’t have any success trying to load the data using JSON directlly but have got it to work via mqtt and node-red, using the influxdb node..
Briefly - in node-red - I pickup the data using mqtt in and pass it to the influxdb node via a simple function. The influxdb node then sends the data to influxdb that can analyse/plot or be used by Grafana.
I found using influxdb was useful because once you see data coming in, it is straightforward to send the data to Grafana. However finding the right combination of tokens etc in both programs was frustrating - especially as they seemed different in every new version.
Once Grafana was able to connect to influx (running on another rPi) then plotting the data was mostly straightforward using cut and paste flux commands.

But it’s been running now a few weeks and seems stable and informative.
Here are some screenshots.
From Node-red:

From influxdb:


From Grafana (using influxdb):

My Node-red implementation is not optimised in that I am using a separate input for each MQTT topic and then summing them all into influxdb. I think there is a batch input, but I’ve not had any problems without it.

I also have another influx database for a 16 cell battery and use Grafana for that as well - after some struggles getting the batteryy BMS to provide data to a python script…

Hi

This looks exactly what id like to do.

However the first screen with Authorization fails to connect to the api when i click save and test.

Tried using borh read and read write api keys from emoncms.

Only difference is my opencms box is on a different box to grafana.

Any advice appreciated.

Matt

Check url to emoncms box.
For Authorization enough read api key.

I have exactly the same problem. Grafana reports ‘JSON API: Not Acceptable’ when saving and testing the connection. Has anyone found a solution to this ?

It seems the JSON data source listed here has been deprecated, i.e. it is no longer supported. This is the recommended replacement: Infinity plugin for Grafana | Grafana Labs

I was able to figure out how to configure it to work with emoncms (the web service, but should also work locally).

I run Grafana locally (in a Docker container, using Portainer for mangement). Installation was easy: Infinity plugin for Grafana | Grafana Labs

From the console where your Grafana lives:

grafana-cli plugins install yesoreyeram-infinity-datasource

Then from the UI for Grafana: Settings (gear) → Data Sources → Add (Others section is where I found Infinity)
Config is a little tricky:

  1. In Auth type, select Bearer Token
  2. In the input box for Bearer token, enter the Read Only API key (copied from your account page of emoncms)
  3. In the Allowed hosts section enter the host URI. I used https://emoncms.org/ for the service
  4. Save & test (it doesn’t appear to really test this so this should work)

Now create a new dashboard.
It is best to set Table view (so you can see the data) and/or the Table Visualization to start.

  1. Type: JSON
  2. Parser: Default (worked for me, but it suggests trying backend, which also works but needs different selectors)
  3. Method: GET
  4. URL: https://emoncms.org/feed/data.json
  5. Headers, Request params
    a. no headers needed
    b. URL Query Params
    i. key: id, value:
    ii. key: skipmissing, value: 0 or 1
    iii. key: interval, value: ${__interval_ms:date:seconds}
    iv. key: start, value: ${__from}
    v. key: end, value: ${__to}
  6. Parsing options & Result fields
    a. Rows/Root - not needed
    b. Columns
    i. Selector: [0] for default, 0 for backend, as: time, format as: Time ( UNIX ms)
    ii. Selector: [1] for default, 1 for backend, as: , format as: Number

The selectors as JSONPath (so it helps to understand that a little)

This is somewhat tedious to do, but copying queries and panels is pretty easy in Grafana

Data Source:

Query in a panel:

Performance seems okay, less than 1s per query, even asking for 5 years of data. I mostly use InfluxDB and Grafana, but still have some data in emoncms and wanted to see how well it would work with Grafana.

3 Likes