How do I convert my libsonnet files into jsonnet files and then plot them in Grafana?

1.3k Views Asked by At

How do I convert my libsonnet files into jsonnet files and then plot them in Grafana? I am using the repo: grafonnet-lib. Here I want to execute the libsonnet files in grafonnet, but when I execute a file, for example: dashboard.libsonnet, in vscode I get this: { } FYI: I am using a Windows 10 machine

What should I do in order to execute a libsonnet file and see something in Grafana?

Also, where are the libsonnet libraries and how do I work with them? I think I dont have to install any libraries, right?

1

There are 1 best solutions below

3
On

Don't execute the libsonnet itself, it's a library. Import and call the grafonnet functions from a separate jsonnet file. For grafonnet, there are tons of examples.

Straight from the grafana/grafonnet-lib/examples page... (hint: this goes in a separate .jsonnet file, not in grafana.libsonnet)

local grafana = import 'grafonnet/grafana.libsonnet';
local dashboard = grafana.dashboard;
local row = grafana.row;
dashboard.new(
  'JVM',
  schemaVersion=16,
  tags=['java'],
)

Look into jb (jsonnet builder) for managing the libsonnet called by in jsonnet.