Skip to content

Commit 5ef6256

Browse files
authored
Merge pull request #15 from grafana/gaantunes/update-docs
Update docs and provide an example Makefile
2 parents 9e5b186 + 89c7f71 commit 5ef6256

File tree

2 files changed

+80
-67
lines changed

2 files changed

+80
-67
lines changed

Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: prometheus_alerts.yaml prometheus_rules.yaml dashboards_out
2+
3+
prometheus_alerts.yaml: mixin.libsonnet
4+
@mkdir -p out/
5+
mixtool generate alerts -a out/prometheus_alerts.yaml -y $<
6+
7+
prometheus_rules.yaml: mixin.libsonnet
8+
@mkdir -p out/
9+
mixtool generate rules -r out/prometheus_rules.yaml -y $<
10+
11+
dashboards_out: mixin.libsonnet
12+
@mkdir -p out/dashboards
13+
mixtool generate dashboards -d out/dashboards $<
14+
15+
all: mixin.libsonnet
16+
@mkdir -p out/
17+
mixtool generate all -d out/dashboards -r out/prometheus_rules.yaml -a out/prometheus_alerts.yaml -y $<

README.md

+63-67
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,70 @@ For more information about mixins, see:
1212
* "[Prometheus Monitoring Mixins: Using Jsonnet to Package Together Dashboards, Alerts and Exporters](https://www.youtube.com/watch?v=b7-DtFfsL6E)" talk from CloudNativeCon Copenhagen 2018.
1313
* "[Prometheus Monitoring Mixins: Using Jsonnet to Package Together Dashboards, Alerts and Exporters](https://promcon.io/2018-munich/talks/prometheus-monitoring-mixins/)" talk from PromCon 2018 (slightly updated).
1414

15+
## Mixin creation guidelines
16+
17+
Mixins follow a standard structure, which is enforced by the [mixtool CLI](https://github.com/monitoring-mixins/mixtool).
18+
19+
The schema defines 4 root jsonnet objects to keep Grafana dashboards, Prometheus alerts and rules, and configuration parameters to be applied on the fly when building the mixin.
20+
21+
```
22+
.
23+
├── grafanaDashboards::
24+
├── prometheusAlerts::
25+
│ ├── groups:
26+
├── prometheusRules::
27+
│ ├── groups:
28+
├── _config::
29+
```
30+
31+
This is the expected structure of a mixin jsonnet object definition. The actual recommended file structure has a `mixin.libsonnet` file as root, like the following.
32+
33+
```
34+
.
35+
├── mixin.libsonnet
36+
├── dashboards
37+
│ ├── dashboards.libsonnet
38+
│ │ ├── grafanaDashboards::
39+
├── alerts
40+
│ ├── alerts.libsonnet
41+
│ │ ├── prometheusAlerts::
42+
├── rules
43+
│ ├── rules.libsonnet
44+
│ │ ├── prometheusRules::
45+
```
46+
47+
Please note that all the 3 jsonnet objects are made hidden/private (indicated by the trailing ::).
48+
This is the expected standard to be used with mixtool CLI.
49+
If you want to use pure jsonnet commands against the mixin, please make those objects public.
50+
51+
The mixin.libsonnet file imports all the files described on the previous section, packaging up the mixin.
52+
It may also contain some changes to the original files, whenever needed.
53+
These can be defined in itself or importing another jsonnet definition file that changes any of the 4 objects of the structure.
54+
55+
```json
56+
(import 'dashboards/dashboards.libsonnet') +
57+
(import 'alerts/alerts.libsonnet') +
58+
(import 'rules/rules.libsonnet')
59+
(import 'config.libsonnet') +
60+
```
61+
1562
## How to use mixins.
1663

1764
Mixins are designed to be vendored into the repo with your infrastructure config.
1865
To do this, use [jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler):
1966

2067
You then have three options for deploying your dashboards
2168
1. Generate the config files and deploy them yourself.
22-
1. Use ksonnet to deploy this mixin along with Prometheus and Grafana.
23-
1. Use kube-prometheus to deploy this mixin.
69+
2. Use kube-prometheus to deploy this mixin.
70+
3. Use Grizzly to deploy this mixin
2471

2572
## Generate config files
2673

2774
You can manually generate the alerts, dashboards and rules files, but first you
28-
must install some tools:
75+
must install some tools. Make sure you're using golang v1.17 or higher, and run:
2976

3077
```
31-
$ go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
32-
33-
# macOS
34-
$ brew install jsonnet-bundler
35-
36-
# Archlinux AUR
37-
$ yay -S jsonnet
78+
go install github.com/monitoring-mixins/mixtool/cmd/mixtool@master
3879
```
3980

4081
Then, grab the mixin and its dependencies:
@@ -45,84 +86,38 @@ $ cd <mixin repo>
4586
$ jb install
4687
```
4788

48-
Finally, build the mixin:
89+
Finally, build the mixin with the self contained Makefile, that can be copied from the one present in this repo:
4990

5091
```
5192
$ make prometheus_alerts.yaml
5293
$ make prometheus_rules.yaml
5394
$ make dashboards_out
95+
$ make all
5496
```
5597

98+
All files are generated inside an `out` folder.
5699
The `prometheus_alerts.yaml` and `prometheus_rules.yaml` file then need to passed
57-
to your Prometheus server, and the files in `dashboards_out` need to be imported
100+
to your Prometheus server, and the files in `out/dashboards` need to be imported
58101
into you Grafana server. The exact details will depending on how you deploy your
59102
monitoring stack to Kubernetes.
60103

61-
## Using with prometheus-ksonnet
62-
63-
Alternatively you can also use the mixin with
64-
[prometheus-ksonnet](https://github.com/grafana/jsonnet-libs/tree/master/prometheus-ksonnet),
65-
a [ksonnet](https://github.com/ksonnet/ksonnet) module to deploy a fully-fledged
66-
Prometheus-based monitoring system for Kubernetes:
67-
68-
Make sure you have the ksonnet v0.8.0:
69-
70-
```
71-
$ brew install https://raw.githubusercontent.com/ksonnet/homebrew-tap/82ef24cb7b454d1857db40e38671426c18cd8820/ks.rb
72-
$ brew pin ks
73-
$ ks version
74-
ksonnet version: v0.8.0
75-
jsonnet version: v0.9.5
76-
client-go version: v1.6.8-beta.0+$Format:%h$
77-
```
78-
79-
In your config repo, if you don't have a ksonnet application, make a new one (will copy credentials from current context):
80-
81-
```
82-
$ ks init <application name>
83-
$ cd <application name>
84-
$ ks env add default
85-
```
86-
87-
Grab the kubernetes-jsonnet module using and its dependencies, which include
88-
the kubernetes-mixin:
89-
90-
```
91-
$ go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
92-
$ jb init
93-
$ jb install github.com/kausalco/public/prometheus-ksonnet
94-
95-
```
96-
97-
Assuming you want to run in the default namespace ('environment' in ksonnet parlance), add the follow to the file `environments/default/main.jsonnet`:
98-
99-
```
100-
local prometheus = import "prometheus-ksonnet/prometheus-ksonnet.libsonnet";
101-
102-
prometheus {
103-
_config+:: {
104-
namespace: "default",
105-
},
106-
}
107-
```
104+
## Using kube-prometheus
108105

109-
Apply your config:
106+
See the kube-prometheus docs for [instructions on how to use mixins with kube-prometheus](https://github.com/coreos/kube-prometheus#kube-prometheus).
110107

111-
```
112-
$ ks apply default
113-
```
108+
## Using Grizzly
114109

115-
## Using kube-prometheus
110+
See the grizzly docs for [instructions on how to use mixins with grizzly](https://grafana.github.io/grizzly/hidden-elements/)
116111

117-
See the kube-prometheus docs for [instructions on how to use mixins with kube-prometheus](https://github.com/coreos/kube-prometheus#kube-prometheus).
112+
Grizzly support for monitoring-mixin standard is deprecated, but you can use [this adapter](https://github.com/grafana/jsonnet-libs/tree/master/grizzly) to make it work on newer versions of Grizlly.
118113

119114
## Customising the mixin
120115

121116
Mixins typically allows you to override the selectors used for various jobs,
122117
to match those used in your Prometheus set.
123118

124119
This example uses the [kubernetes-mixin](https://github.com/kubernetes-monitoring/kubernetes-mixin).
125-
In a new directory, add a file `mixin.libsonnet`:
120+
In a new directory, add a file `mixin.libsonnet`:
126121

127122
```
128123
local kubernetes = import "kubernetes-mixin/mixin.libsonnet";
@@ -148,9 +143,10 @@ Generate the alerts, rules and dashboards:
148143

149144
```
150145
$ jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusAlerts)' > alerts.yml
151-
$ jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusRules)' >files/rules.yml
146+
$ jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusRules)' > files/rules.yml
152147
$ jsonnet -J vendor -m files/dashboards -e '(import "mixin.libsonnet").grafanaDashboards'
153148
```
149+
154150
## Guidelines for alert names, labels, and annotations
155151

156152
Prometheus alerts deliberately allow users to define their own schema for

0 commit comments

Comments
 (0)