Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weeezes/dhall-grafana
Build Grafana dashboards with Dhall
https://github.com/weeezes/dhall-grafana
Last synced: 3 months ago
JSON representation
Build Grafana dashboards with Dhall
- Host: GitHub
- URL: https://github.com/weeezes/dhall-grafana
- Owner: weeezes
- License: mit
- Created: 2019-11-07T07:53:28.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T18:29:39.000Z (10 months ago)
- Last Synced: 2024-07-06T02:23:27.332Z (4 months ago)
- Language: Dhall
- Homepage:
- Size: 247 KB
- Stars: 24
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dhall - dhall-grafana - Build Grafana dashboards with Dhall. (Libraries)
README
# dhall-grafana
Your [Grafana](http://www.grafana.org/) dashboards-as-code with [Dhall](https://dhall-lang.org/)!
# Usage
Install `dhall-to-json` by downloading it from [dhall-haskell/releases](https://github.com/dhall-lang/dhall-haskell/releases). When you have the binary in your `$PATH` it's as easy as running:
```
$ dhall-to-json --file all_dashboard.dhall
```Import the output to Grafana and you're done!
Make sure you have a [TestData DB datasource](https://grafana.com/docs/features/datasources/testdata/) configured to see the [`./examples/all_dashboard.dhall`](./examples/all_dashboard.dhall) graphs be populated.
![all_dashboard_sample.png](docs/screenshots/all_dashboard_sample.png)
# Getting started
First confirm that your tooling works by walking through [Usage](#usage). Open up a new file after you're done, and copy-paste in the following:
```
let Grafana =
https://raw.githubusercontent.com/weeezes/dhall-grafana/master/package.dhall sha256:af6de80932dfaf74e46b72707b1264213afa28771c1e2bb53698c079b3e3ac2f
? https://raw.githubusercontent.com/weeezes/dhall-grafana/master/package.dhallin {=}
```Compile it by running `dhall-to-json`:
```
$ dhall-to-json --file tutorial.dhall
{}
```We have an empty object, it's something! Let's add in a dashboard:
```
let Grafana =
https://raw.githubusercontent.com/weeezes/dhall-grafana/master/package.dhall sha256:af6de80932dfaf74e46b72707b1264213afa28771c1e2bb53698c079b3e3ac2f
? https://raw.githubusercontent.com/weeezes/dhall-grafana/master/package.dhallin Grafana.Dashboard::
{ title = "Tutorial"
}
```Compile it and the output should be a bit more interesting. It's your first Grafana dashboard, built with Dhall!
Notice the `::` after `Grafana.Dashboard`? That's called *record completion*. We're filling in our own values on top of a default, which you can examine in [`defaults/Dashboard.dhall`](./default/Dashboard.dhall). You can find all other default values and overrideable parameters from [`defaults/`](./defaults)! To find an example of record completion, check out the [Dhall Cheatsheet](https://github.com/dhall-lang/dhall-lang/wiki/Cheatsheet#complex-types) *records* section to understand how `package.dhall` works.
Let's add in our first panel:
```
let Grafana =
https://raw.githubusercontent.com/weeezes/dhall-grafana/master/package.dhall sha256:af6de80932dfaf74e46b72707b1264213afa28771c1e2bb53698c079b3e3ac2f
? https://raw.githubusercontent.com/weeezes/dhall-grafana/master/package.dhallin Grafana.Dashboard::{
, title = "test"
, panels =
Grafana.Utils.generateIds
[ Grafana.Panels.mkGraphPanel
Grafana.GraphPanel::{
, title = "test"
, gridPos = { x = 0, y = 0, w = 12, h = 6 }
}
]
}
```Whoo, that looks a lot more exciting! There's a few things going on here. We're adding the panels by passing them in to the Dashboards `panels` field. The panels have to have unique IDs, so we can use the `generateIds` utility and the `mkGraphPanel` helper to get exactly that. `mkGraphPanel` eats a `GraphPanel`, also defined with record completion. The end result is a list of `Panels`, and `Dashboard` happily accepts that type.
Compile it, import it to Grafana, and let your eyes rest on that masterpiece!
# Local development
There is a local development setup that works on Linux that you can read more of [here](./local-dev/README.md)