0

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?

rioV8
  • 24,506
  • 3
  • 32
  • 49
M65
  • 27
  • 3

1 Answers1

2

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.

userK
  • 21
  • 3
  • Alright, that is very helpful! In that same directory (grafonnet-lib) there are some examples. And I want to run the following wxample: grafonnet-lib/examples/jvm.jsonnet. But when I run it by the command "jsonnet -J grafonnet-lib jvm.jsonnet"; I get an error: RUNTIME ERROR: couldn't open import "grafana_libraries/grafonnet/grafana.libsonnet": no match locally or in the Jsonnet library paths – M65 Dec 20 '22 at 15:40
  • The error is relative to where the files actually are. If the current working directory (cwd) is `grafonnet-lib/examples/` and `jsonnet` is run, then the path to the libsonnet has to be adjusted because it's not in the same directory as jvm.jsonnet. Assuming the cwd is the examples subdir of the repo, try: `jsonnet -J ../ jvm.jsonnet` If the cwd is the `grafonet-lib` subdir, then `jsonnet -J ./ examples/jvm.jsonnet` should work. – userK Dec 21 '22 at 14:42
  • Just remembered that you are using Windows 10, so those `/` might need to change to `//` or a `\\`. I forget how exactly that works. – userK Dec 21 '22 at 15:03