Using Jsonnet
By now, we’ve harnessed the power and potential of Jsonnet. But what does it really look like to use it outside of the narrowly-scoped, contrived examples we’ve looked at thus far? How do I use it with Prometheus? This is a Prometheus book, after all. Well, firstly, let’s look at how to use Jsonnet to actually generate files instead of just writing to our terminal.
Generating files
In its most simple form, writing to files with Jsonnet is as easy as providing an additional flag (-o
) and file path to the jsonnet
CLI. For example, we can write the output of our earlier variables_prometheus.jsonnet
file to a new file called out/rules.json
by running the following:
$ jsonnet -co ch11/out/rules.json ch11/variables_prometheus.jsonnet
The -c
flag is used in addition to -o
since -c
will create parent directories (such as ch11/out/
) for the output file if they don’t exist already. Our ch11/out/rules.json
file now contains the expected content...