Query REST APIs from Grafana

If we can consume the data we need via REST API (in JSON format), we will therefore be able to visualize ourselves in Grafana! The world is wonderful with Grafana! So, As we know, Today, almost any app allows us to perform queries through APIs, Don't wait any longer and squeeze them!

Well, And first of all… Tell you that we start after a summer of joy and enjoyment =) and work, go… It's been a few months of disconnection and we wait who knows if 1 or better 2 Posts per week until the end of the year… I more or less have the syllabus, But my kids suck my life :-), Come, To nougat!

In this post we will do something simple, an example of what we will require to have it up and running. Let's put an app, in this particular case we will use Wekan, which is a Kanban organizer and is the one with which I manage, among others,, the Pending tasks to be carried out (in my life, At work, with priorities…). As it is an app that allows via REST API in JSON format to consult the data, because the intention will be to make a Dashboard in Grafana that organizes the pending tasks, And of course, then this rotating pool will go to the Helpdesk screen. It will be a direct consultation, that we can cache or not if we want the values for a while, will not be stored in any databases.

First things, in Grafana we will install the datasource 'JSON API’ & we restart Grafana:

grafana-cli plugins install marcusolsson-json-datasource systemctl restart grafana-server

Let's take this simple example, After reading the documentation of each app, we will be able to know how to consult the data we need; As I said, Wekan, and list the Cards, which in my case I use as Tasks, with a curl we would do it quickly to validate the output of what we will see later in Grafana:

curl -H "Authorization: Bearer XXXXXXXXXX" -X GET http://192.168.1.115:3001/api/boards/xxxxxx/lists/xxxxxx/cards

[{"_Id":"Damn it","title":"Task 1...","Description":"","assignees":[]},{"_Id":"dfgmh2","title":"Task 2...","Description":"","assignees":[]},{"_Id":"Rymt8","title":"Task 3...","Description":"","assignees":[]}....

In this case, Requires authentication, And it goes at the head, with your token, and then we make a GET of the section we are interested in.

We will be able to create the Data Source in Grafana that points to the root URL of the APIs and in this case we will send the authentication in a custom header. It's just that Wekan it is a somewhat particular example, since everything that goes after the ':’ of 'Authorization’ We'll put it as 'value’ in the 'Header’ (not only the Token, but in this case, Insist).

And already in a Dashboard in Grafana we can add a new Panel, the kind we need, In my case, a simple one in table format is enough for me, I just want to see the Urgent Tasks pending. We indicate the field we want to extract, in this case in JSONPath format and in my particular case if you look closely at the previous curl, it would be '$.*.title’ to obtain the titles of all the Cards.

In the 'Path' tab’ We can specify the path of the query, in this case of type GET and (in my case) Adding the Path: '/boards/xxxxxxxxxx/lists/xxxxxxxxxx/cards’

And this would be an example of some of the Urgent Tasks that I have pending right now 🙂

What I said, is a mere example of how to consume data directly from Grafana through APIs in JSON format that the remote app can spit out. I hope you can get some use out of it, The truth is that it has 1000 possibilities and I fall short 😉

May you be happy, that it has been a pleasure to write these few lines, But I have to get the rust out, some documents that you may find interesting and others not so much, but with the intention that they contribute something. A big kiss!

Recommended Posts

Author

nheobug@bujarra.com
Autor del blog Bujarra.com Cualquier necesidad que tengas, Do not hesitate to contact me, I will try to help you whenever I can, Sharing is living ;) . Enjoy documents!!!

Install Volumio on a VM

13 de October de 2022