github.com/thanos-io/thanos@v0.32.5/mixin/README.md (about) 1 # thanos-mixin 2 3 > Note that everything is experimental and may change significantly at any time. Also it still has missing alert and dashboard definitions for certain components, e.g. rule and sidecar. Please feel free to contribute. 4 5 This directory contains extensible and customizable monitoring definitons for Thanos. [Grafana](http://grafana.com/) dashboards, and [Prometheus rules](https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/) combined with documentation and scripts to provide easy monitoring experience for Thanos. 6 7 You can find more about monitoring-mixins in [the design document](https://github.com/monitoring-mixins/docs/blob/master/design.pdf), and you can check out other examples like [Prometheus Mixin](https://github.com/prometheus/prometheus/tree/master/documentation/prometheus-mixin). 8 9 The content of this project is written in [jsonnet](http://jsonnet.org/). This project could both be described as a package as well as a library. 10 11 ## Requirements 12 13 ### jsonnet 14 15 The content of this project consists of a set of [jsonnet](http://jsonnet.org/) files making up a library to be consumed. 16 17 We recommend to use [go-jsonnet](https://github.com/google/go-jsonnet). It's an implementation of [Jsonnet](http://jsonnet.org/) in pure Go. It is feature complete but is not as heavily exercised as the [Jsonnet C++ implementation](https://github.com/google/jsonnet). 18 19 To install: 20 21 ```shell 22 go get github.com/google/go-jsonnet/cmd/jsonnet 23 ``` 24 25 ### jsonnet-bundler 26 27 `thanos-mixin` uses [jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler#install) (the jsonnet package manager) to manage its dependencies. 28 29 We also recommend you to use `jsonnet-bundler` to install or update if you decide to use `thanos-mixin` as a dependency for your custom configurations. 30 31 To install: 32 33 ```shell 34 go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb 35 ``` 36 37 > An e.g. of how to install a given version of this library: `jb install github.com/thanos-io/thanos/mixin@main`. 38 39 ## Use as a library 40 41 To use the `thanos-mixin` as a dependency, simply use the `jsonnet-bundler` install functionality: 42 43 ```shell 44 $ mkdir thanos-mixin; cd thanos-mixin 45 $ jb init # Creates the initial/empty `jsonnetfile.json` 46 # Install the thanos-mixin dependency 47 $ jb install github.com/thanos-io/thanos/mixin@main # Creates `vendor/` & `jsonnetfile.lock.json`, and fills in `jsonnetfile.json` 48 ``` 49 50 To update the `thanos-mixin` as a dependency, simply use the `jsonnet-bundler` update functionality: 51 52 ```shell 53 $ jb update 54 ``` 55 56 #### Configure 57 58 This project is intended to be used as a library. You can extend and customize dashboards and alerting rules by creating for own generators, such as the generators ([alerts.jsonnet](alerts.jsonnet) and [dashboards.jsonnet](dashboards.jsonnet)) that are use to create [examples](../examples). Default parameters are collected in [config.libsonnet](config.libsonnet), feel free to modify and generate your own definitions. 59 60 ```libsonnet mdox-exec="cat mixin/config.libsonnet" 61 { 62 local thanos = self, 63 // TargetGroups is a way to help mixin users to add high level target grouping to their alerts and dashboards. 64 // With the help of TargetGroups you can use a single observability stack to monitor several Thanos instances. 65 // The key in the key-value pair will be used as "label name" in the alerts and variable name in the dashboards. 66 // The value in the key-value pair will be used as a query to fetch available values for the given label name. 67 targetGroups+:: { 68 // For example for given following groups, 69 // namespace: 'thanos_status', 70 // cluster: 'find_mi_cluster_bitte', 71 // zone: 'an_i_in_da_zone', 72 // region: 'losing_my_region', 73 // will generate queriers for the alerts as follows: 74 // ( 75 // sum by (cluster, namespace, region, zone, job) (rate(thanos_compact_group_compactions_failures_total{job=~"thanos-compact.*"}[5m])) 76 // / 77 // sum by (cluster, namespace, region, zone, job) (rate(thanos_compact_group_compactions_total{job=~"thanos-compact.*"}[5m])) 78 // * 100 > 5 79 // ) 80 // 81 // AND for the dashborads: 82 // 83 // sum by (cluster, namespace, region, zone, job) (rate(thanos_compact_group_compactions_failures_total{cluster=\"$cluster\", namespace=\"$namespace\", region=\"$region\", zone=\"$zone\", job=\"$job\"}[$interval])) 84 // / 85 // sum by (cluster, namespace, region, zone, job) (rate(thanos_compact_group_compactions_total{cluster=\"$cluster\", namespace=\"$namespace\", region=\"$region\", zone=\"$zone\", job=\"$job\"}[$interval])) 86 }, 87 query+:: { 88 selector: 'job=~".*thanos-query.*"', 89 title: '%(prefix)sQuery' % $.dashboard.prefix, 90 }, 91 queryFrontend+:: { 92 selector: 'job=~".*thanos-query-frontend.*"', 93 title: '%(prefix)sQuery Frontend' % $.dashboard.prefix, 94 }, 95 store+:: { 96 selector: 'job=~".*thanos-store.*"', 97 title: '%(prefix)sStore' % $.dashboard.prefix, 98 }, 99 receive+:: { 100 selector: 'job=~".*thanos-receive.*"', 101 title: '%(prefix)sReceive' % $.dashboard.prefix, 102 }, 103 rule+:: { 104 selector: 'job=~".*thanos-rule.*"', 105 title: '%(prefix)sRule' % $.dashboard.prefix, 106 }, 107 compact+:: { 108 selector: 'job=~".*thanos-compact.*"', 109 title: '%(prefix)sCompact' % $.dashboard.prefix, 110 }, 111 sidecar+:: { 112 selector: 'job=~".*thanos-sidecar.*"', 113 thanosPrometheusCommonDimensions: 'namespace, pod', 114 title: '%(prefix)sSidecar' % $.dashboard.prefix, 115 }, 116 bucketReplicate+:: { 117 selector: 'job=~".*thanos-bucket-replicate.*"', 118 title: '%(prefix)sBucketReplicate' % $.dashboard.prefix, 119 }, 120 dashboard+:: { 121 prefix: 'Thanos / ', 122 tags: ['thanos-mixin'], 123 timezone: 'UTC', 124 selector: ['%s="$%s"' % [level, level] for level in std.objectFields(thanos.targetGroups)], 125 dimensions: ['%s' % level for level in std.objectFields(thanos.targetGroups)], 126 127 overview+:: { 128 title: '%(prefix)sOverview' % $.dashboard.prefix, 129 selector: std.join(', ', thanos.dashboard.selector), 130 dimensions: std.join(', ', thanos.dashboard.dimensions + ['job']), 131 }, 132 }, 133 } 134 ``` 135 136 You can format your code using: 137 138 ```shell 139 $ make jsonnet-format 140 ``` 141 142 ## Examples 143 144 This project is intended to be used as a library. However, it also provides drop-in examples to monitor Thanos. 145 146 ### Requirements 147 148 Although all the required dependencies are handled by `Makefile`, keep in mind that in addition the dependencies that are listed above we have following dependencies: 149 150 #### gojsontoyaml 151 152 `gojsontoyaml` is used to convert generated `json` definitions to `yaml`. 153 154 To install: 155 156 ```shell 157 go get github.com/brancz/gojsontoyaml 158 ``` 159 160 ### Generate 161 162 To generate examples after modifying, make sure `jsonnet` dependencies are installed. 163 164 ```shell 165 $ make jsonnet-vendor 166 ``` 167 168 and then 169 170 ```shell 171 $ make examples 172 ``` 173 174 Make action runs the jsonnet code, then reads each key of the generated json and uses that as the file name, and writes the value of that key to that file, and converts each json manifest to yaml. 175 176 > Make commands should handle dependencies for you. 177 178 ### Test and validate 179 180 You validate your structural correctness of your Prometheus [alerting rules](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/) or [recording rules](https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/) with: 181 182 ```shell 183 $ make example-rules-lint 184 ``` 185 186 Check out [test.yaml](../examples/alerts/tests.yaml) to add/modify tests for the mixin. To learn more about how to write test for Prometheus, check out [official documentation](https://www.prometheus.io/docs/prometheus/latest/configuration/unit_testing_rules/). 187 188 You test alerts with: 189 190 ```shell 191 $ make alerts-test 192 ``` 193 194 ---