»grafana-metadata-api«

Introduction

We are coming from Developing the »grafana-metadata-api« here.

About

Goal

Conveniently access multiple JSON files through a single native Grafana datasource based on the Grafana Simple JSON Datasource plugin.

This can be used to implement lookup and concordance tables and consume them easily from within Grafana.

Implementation

The server-side component of the Grafana Metadata API is serving as a hackable datasource implementation. Being in its infancy, it just delivers static JSON files after applying some basic routing.

It is based on the Simple JSON Datasource plugin, a backend datasource that sends generic HTTP requests to a given URL.

The grafana-metadata-api handler has been implemented with Nginx/Lua, responding to requests from simple-json-datasource.

Setup

The software "grafana-metadata-api" has been installed and configured on the data acquisition host weather.hiveeyes.org by following the corresponding setup documentation.

The new data source "environmental-metadata" has been added to pull this into Grafana.

Name:   environmental-metadata
Type:   SimpleJson
URL:    https://weather.hiveeyes.org/metadata
Access: proxy

Screenshots

Adding a new data source

image

The data source has been added

image

Howto: Publish and consume your own JSON metadata file

About

This document outlines the process of publishing and consuming a JSON file as a Grafana datasource along the lines of a meaningful example.

Publish

Just drop more .json files into the "/var/lib/grafana-metadata-api" directory, like luftdaten-stations-grafana.json:

[
  {"value": 8119, "text": "Karlsbader Stra\u00dfe, B\u00fcchenbach, Bayern, DE"},
  {"value": 1234, "text": "Hauptstra\u00dfe, Wolfratshausen, Bayern, DE"}
]

Grafana will use the "text" property as a the template variable’s label and the "value" property as the raw value of the template variable.

Implement

Add another Grafana variable to your dashboard (see configure Grafana variable) based on a data source already configured.

Example

Add a variable named "location_id" backed by the file "luftdaten-stations-grafana.json" from the "environmental-metadata" data source.

Name:           location_id
Label:          Location
Type:           Query

Data source:    environmental-metadata
Query:          luftdaten-stations-grafana.json

Refresh:        On Dashboard Load
Sort:           Alphabetical (asc)

Multi-value:    yes

Screenshot

image

Use

After implementing the variable in this way, it will be displayed as a select component at the top of the dashboard, as usual:
image

However, when using the select widget, it will propagate the numerical identifier values into the variable "location_id", not their textual representations.

2 Likes

Wow, that is something!

1 Like