diff --git a/docs/developing-prometheus-rules-and-grafana-dashboards.md b/docs/developing-prometheus-rules-and-grafana-dashboards.md index 91f430f842b5e75a9c7d8cf375e42d9578e67c13..99cf271c03406f93b14805192cf5252899b912d7 100644 --- a/docs/developing-prometheus-rules-and-grafana-dashboards.md +++ b/docs/developing-prometheus-rules-and-grafana-dashboards.md @@ -164,7 +164,7 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + { Along with adding additional rules, we give the user the option to filter or adjust the existing rules imported by `kube-prometheus/kube-prometheus.libsonnet`. The recording rules can be found in [kube-prometheus/rules](../jsonnet/kube-prometheus/rules) and [kubernetes-mixin/rules](https://github.com/kubernetes-monitoring/kubernetes-mixin/tree/master/rules) while the alerting rules can be found in [kube-prometheus/alerts](../jsonnet/kube-prometheus/alerts) and [kubernetes-mixin/alerts](https://github.com/kubernetes-monitoring/kubernetes-mixin/tree/master/alerts). -Knowing which rules to change, the user can now use functions from the [Jsonnet standard library](https://jsonnet.org/ref/stdlib.html) to make these changes. Below are examples of both a filter and an adjustment being made to the default rules. These changes can be assigned to a local variable and then added to the `local kp` object as seen in the examples above. +Knowing which rules to change, the user can now use functions from the [Jsonnet standard library](https://jsonnet.org/ref/stdlib.html) to make these changes. Below are examples of both a filter and an adjustment being made to the default rules. These changes can be assigned to a local variable and then added to the `local kp` object as seen in the examples above. #### Filter Here the alert `KubeStatefulSetReplicasMismatch` is being filtered out of the group `kubernetes-apps`. The default rule can be seen [here](https://github.com/kubernetes-monitoring/kubernetes-mixin/blob/master/alerts/apps_alerts.libsonnet). @@ -228,7 +228,7 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + filter + updat { ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) } + { ['prometheus-adapter-' + name]: kp.prometheusAdapter[name] for name in std.objectFields(kp.prometheusAdapter) } + { ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) } -``` +``` ## Dashboards Dashboards can either be added using jsonnet or simply a pre-rendered json dashboard. @@ -312,7 +312,7 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + { { ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) } ``` -Incase you have lots of json dashboard exported out from grafan UI the above approch is going to take lots of time. to improve performance we can use `rawGrafanaDashboards` field and provide it's value as json string by using importstr +In case you have lots of json dashboard exported out from grafana UI the above approach is going to take lots of time to improve performance we can use `rawDashboards` field and provide it's value as json string by using `importstr` [embedmd]:# (../examples/grafana-additional-rendered-dashboard-example-2.jsonnet) ```jsonnet local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + { diff --git a/examples/grafana-additional-jsonnet-dashboard-example.jsonnet b/examples/grafana-additional-jsonnet-dashboard-example.jsonnet index 578d6a1fe7eb53f0f84ba0227d1128ea355695e4..b9b26fca552e983ab74d3ea2505240cb0892700e 100644 --- a/examples/grafana-additional-jsonnet-dashboard-example.jsonnet +++ b/examples/grafana-additional-jsonnet-dashboard-example.jsonnet @@ -9,30 +9,32 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + { _config+:: { namespace: 'monitoring', }, - grafanaDashboards+:: { - 'my-dashboard.json': - dashboard.new('My Dashboard') - .addTemplate( - { - current: { - text: 'Prometheus', - value: 'Prometheus', + grafana+:: { + dashboards+:: { + 'my-dashboard.json': + dashboard.new('My Dashboard') + .addTemplate( + { + current: { + text: 'Prometheus', + value: 'Prometheus', + }, + hide: 0, + label: null, + name: 'datasource', + options: [], + query: 'prometheus', + refresh: 1, + regex: '', + type: 'datasource', }, - hide: 0, - label: null, - name: 'datasource', - options: [], - query: 'prometheus', - refresh: 1, - regex: '', - type: 'datasource', - }, - ) - .addRow( - row.new() - .addPanel(graphPanel.new('My Panel', span=6, datasource='$datasource') - .addTarget(prometheus.target('vector(1)'))) - ), + ) + .addRow( + row.new() + .addPanel(graphPanel.new('My Panel', span=6, datasource='$datasource') + .addTarget(prometheus.target('vector(1)'))) + ), + }, }, }; diff --git a/examples/grafana-additional-rendered-dashboard-example-2.jsonnet b/examples/grafana-additional-rendered-dashboard-example-2.jsonnet index 391b0f02e62611853010ea4265fcf6bc59fa7c61..7d0926e99c05885cc1a0dbf1950c50b59db1a4d3 100644 --- a/examples/grafana-additional-rendered-dashboard-example-2.jsonnet +++ b/examples/grafana-additional-rendered-dashboard-example-2.jsonnet @@ -2,8 +2,10 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + { _config+:: { namespace: 'monitoring', }, - rawGrafanaDashboards+:: { - 'my-dashboard.json': (importstr 'example-grafana-dashboard.json'), + grafana+:: { + rawDashboards+:: { + 'my-dashboard.json': (importstr 'example-grafana-dashboard.json'), + }, }, }; diff --git a/examples/grafana-additional-rendered-dashboard-example.jsonnet b/examples/grafana-additional-rendered-dashboard-example.jsonnet index 8aa26bdc06459ea9b82bbab3f71a33e76a343ad7..f55eab8ae1345692421f41dfbd66fc9040ac1453 100644 --- a/examples/grafana-additional-rendered-dashboard-example.jsonnet +++ b/examples/grafana-additional-rendered-dashboard-example.jsonnet @@ -2,9 +2,14 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + { _config+:: { namespace: 'monitoring', }, - grafanaDashboards+:: { + grafanaDashboards+:: { // monitoring-mixin compatibility 'my-dashboard.json': (import 'example-grafana-dashboard.json'), }, + grafana+:: { + dashboards+:: { // use this method to import your dashboards to Grafana + 'my-dashboard.json': (import 'example-grafana-dashboard.json'), + }, + }, }; { ['00namespace-' + name]: kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus) } +