|
1 | 1 | ---
|
2 |
| -title: Prometheus monitoring mixins |
| 2 | +title: Prometheus Monitoring Mixins |
3 | 3 | ---
|
4 | 4 |
|
| 5 | +A mixin is a set of Grafana dashboards and Prometheus rules and alerts, packaged together in a reuseable and extensible bundle. |
| 6 | +Mixins are written in [jsonnet](https://jsonnet.org/), and are typically installed and updated with [jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler). |
5 | 7 |
|
6 |
| -## prometheus |
| 8 | +For more information about mixins, see: |
| 9 | +* [Prometheus Monitoring Mixins Design Doc](https://docs.google.com/document/d/1A9xvzwqnFVSOZ5fD3blKODXfsat5fg6ZhnKu9LK3lB4/view). A [cached pdf](design.pdf) is included in monitoring mixins [documentation repository](https://github.com/monitoring-mixins/docs). |
| 10 | +* For more motivation, see |
| 11 | +"[The RED Method: How to instrument your services](https://kccncna17.sched.com/event/CU8K/the-red-method-how-to-instrument-your-services-b-tom-wilkie-kausal?iframe=no&w=100%&sidebar=yes&bg=no)" talk from CloudNativeCon Austin 2018. The KLUMPs system demo'd became the basis for the kubernetes-mixin. |
| 12 | +* "[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. |
| 13 | +* "[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). |
7 | 14 |
|
8 |
| -- [Alerts](/prometheus#alerts) |
9 |
| -- [Dashboards](/prometheus#dashboards) |
| 15 | +## How to use mixins. |
10 | 16 |
|
11 |
| -## node-exporter |
| 17 | +Mixins are designed to be vendored into the repo with your infrastructure config. |
| 18 | +To do this, use [jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler): |
12 | 19 |
|
13 |
| -- [Alerts](/node-exporter#alerts) |
14 |
| -- [Recording Rules](/node-exporter#recording-rules) |
15 |
| -- [Dashboards](/node-exporter#dashboards) |
| 20 | +You then have three options for deploying your dashboards |
| 21 | +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. |
16 | 24 |
|
17 |
| -## kubernetes |
| 25 | +## Generate config files |
18 | 26 |
|
19 |
| -- [Alerts](/kubernetes#alerts) |
20 |
| -- [Recording Rules](/kubernetes#recording-rules) |
21 |
| -- [Dashboards](/kubernetes#dashboards) |
| 27 | +You can manually generate the alerts, dashboards and rules files, but first you |
| 28 | +must install some tools: |
22 | 29 |
|
23 |
| -## kube-state-metrics |
| 30 | +```bash |
| 31 | +$ go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb |
24 | 32 |
|
25 |
| -- [Alerts](/kube-state-metrics#alerts) |
| 33 | +# macOS |
| 34 | +$ brew install jsonnet |
26 | 35 |
|
27 |
| -## etcd |
| 36 | +# Archlinux AUR |
| 37 | +$ yay -S jsonnet |
| 38 | +``` |
28 | 39 |
|
29 |
| -- [Alerts](/etcd#alerts) |
30 |
| -- [Dashboards](/etcd#dashboards) |
| 40 | +Then, grab the mixin and its dependencies: |
31 | 41 |
|
32 |
| -## ceph |
| 42 | +```bash |
| 43 | +$ git clone https://github.com/<mixin org>/<mixin repo> |
| 44 | +$ cd <mixin repo> |
| 45 | +$ jb install |
| 46 | +``` |
33 | 47 |
|
34 |
| -- [Alerts](/ceph#alerts) |
35 |
| -- [Recording Rules](/ceph#recording-rules) |
| 48 | +Finally, build the mixin: |
36 | 49 |
|
37 |
| -## gluster |
| 50 | +```bash |
| 51 | +$ make prometheus_alerts.yaml |
| 52 | +$ make prometheus_rules.yaml |
| 53 | +$ make dashboards_out |
| 54 | +``` |
38 | 55 |
|
39 |
| -- [Alerts](/gluster#alerts) |
40 |
| -- [Recording Rules](/gluster#recording-rules) |
41 |
| -- [Dashboards](/gluster#dashboards) |
| 56 | +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 |
| 58 | +into you Grafana server. The exact details will depending on how you deploy your |
| 59 | +monitoring stack to Kubernetes. |
42 | 60 |
|
43 |
| -## consul |
| 61 | +## Using with prometheus-ksonnet |
44 | 62 |
|
45 |
| -- [Alerts](/consul#alerts) |
46 |
| -- [Dashboards](/consul#dashboards) |
| 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: |
47 | 67 |
|
48 |
| -## jaeger |
| 68 | +Make sure you have the ksonnet v0.8.0: |
49 | 69 |
|
50 |
| -- [Alerts](/jaeger#alerts) |
| 70 | +```bash |
| 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 | +``` |
51 | 78 |
|
52 |
| -## memcached |
| 79 | +In your config repo, if you don't have a ksonnet application, make a new one (will copy credentials from current context): |
53 | 80 |
|
54 |
| -- [Dashboards](/memcached#dashboards) |
| 81 | +```bash |
| 82 | +$ ks init <application name> |
| 83 | +$ cd <application name> |
| 84 | +$ ks env add default |
| 85 | +``` |
55 | 86 |
|
56 |
| -## sealed-secrets |
| 87 | +Grab the kubernetes-jsonnet module using and its dependencies, which include |
| 88 | +the kubernetes-mixin: |
57 | 89 |
|
58 |
| -- [Alerts](/sealed-secrets#alerts) |
59 |
| -- [Dashboards](/sealed-secrets#dashboards) |
| 90 | +```bash |
| 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 | +{{< code lang="as3" >}} |
| 100 | +local prometheus = import "prometheus-ksonnet/prometheus-ksonnet.libsonnet"; |
| 101 | + |
| 102 | +prometheus { |
| 103 | + _config+:: { |
| 104 | + namespace: "default", |
| 105 | + }, |
| 106 | +} |
| 107 | +{{< /code >}} |
| 108 | + |
| 109 | +Apply your config: |
| 110 | + |
| 111 | +```bash |
| 112 | +$ ks apply default |
| 113 | +``` |
| 114 | + |
| 115 | +## Using kube-prometheus |
| 116 | + |
| 117 | +See the kube-prometheus docs for [instructions on how to use mixins with kube-prometheus](https://github.com/coreos/kube-prometheus#kube-prometheus). |
| 118 | + |
| 119 | +## Customising the mixin |
| 120 | + |
| 121 | +Mixins typically allows you to override the selectors used for various jobs, |
| 122 | +to match those used in your Prometheus set. |
| 123 | + |
| 124 | +This example uses the [kubernetes-mixin](https://github.com/kubernetes-monitoring/kubernetes-mixin). |
| 125 | + In a new directory, add a file `mixin.libsonnet`: |
| 126 | + |
| 127 | +{{< code lang="as3" >}} |
| 128 | +local kubernetes = import "kubernetes-mixin/mixin.libsonnet"; |
| 129 | + |
| 130 | +kubernetes { |
| 131 | + _config+:: { |
| 132 | + kubeStateMetricsSelector: 'job="kube-state-metrics"', |
| 133 | + cadvisorSelector: 'job="kubernetes-cadvisor"', |
| 134 | + nodeExporterSelector: 'job="kubernetes-node-exporter"', |
| 135 | + kubeletSelector: 'job="kubernetes-kubelet"', |
| 136 | + }, |
| 137 | +} |
| 138 | +{{< /code >}} |
| 139 | + |
| 140 | +Then, install the kubernetes-mixin: |
| 141 | + |
| 142 | +```bash |
| 143 | +$ jb init |
| 144 | +$ jb install github.com/kubernetes-monitoring/kubernetes-mixin |
| 145 | +``` |
| 146 | + |
| 147 | +Generate the alerts, rules and dashboards: |
| 148 | + |
| 149 | +```bash |
| 150 | +$ 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 |
| 152 | +$ jsonnet -J vendor -m files/dashboards -e '(import "mixin.libsonnet").grafanaDashboards' |
| 153 | +``` |
0 commit comments