Skip to content

Commit

Permalink
Merge pull request #5609 from guidoiaquinti/vitess_mixin
Browse files Browse the repository at this point in the history
vitess-mixin: add structure & first 2 dashboards
  • Loading branch information
sougou authored Jan 19, 2020
2 parents c9d2a14 + fdc7b22 commit bd8205e
Show file tree
Hide file tree
Showing 17 changed files with 1,217 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vitess-mixin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.yaml
dashboards_out
vendor
jsonnetfile.lock.json
44 changes: 44 additions & 0 deletions vitess-mixin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.PHONY: dashboards_out

JSONNET_ARGS := -n 2 --max-blank-lines 2 --string-style s --comment-style s
ifneq (,$(shell which jsonnetfmt))
JSONNET_FMT_CMD := jsonnetfmt
else
JSONNET_FMT_CMD := jsonnet
JSONNET_FMT_ARGS := fmt $(JSONNET_ARGS)
endif
JSONNET_FMT := $(JSONNET_FMT_CMD) $(JSONNET_FMT_ARGS)

all: fmt prometheus_alerts.yaml prometheus_rules.yaml dashboards_out lint test

fmt:
find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
xargs -n 1 -- $(JSONNET_FMT) -i

jsonnet_bundle_install:
jb install

prometheus_alerts.yaml: mixin.libsonnet lib/alerts.jsonnet alerts/*.libsonnet
jsonnet -S lib/alerts.jsonnet > $@

prometheus_rules.yaml: mixin.libsonnet lib/rules.jsonnet rules/*.libsonnet
jsonnet -S lib/rules.jsonnet > $@

dashboards_out: mixin.libsonnet lib/dashboards.jsonnet dashboards/*.libsonnet
@mkdir -p dashboards_out
jsonnet -J vendor -m dashboards_out lib/dashboards.jsonnet

lint: prometheus_alerts.yaml prometheus_rules.yaml
find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
while read f; do \
$(JSONNET_FMT) "$$f" | diff -u "$$f" -; \
done

promtool check rules prometheus_rules.yaml
promtool check rules prometheus_alerts.yaml

clean:
rm -rf dashboards_out prometheus_alerts.yaml prometheus_rules.yaml

test: prometheus_alerts.yaml prometheus_rules.yaml
promtool test rules tests.yaml
48 changes: 48 additions & 0 deletions vitess-mixin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# (Alpha) Prometheus Monitoring Mixin for Vitess

A set of Grafana dashboards and Prometheus alerts for Vitess.

## Prerequisites

1. Install `jsonnet-bundler`:
* via `go`: `go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb`
* via `brew`: `brew install jsonnet`

1. Install `promtool`: `go get github.com/prometheus/prometheus/cmd/promtool`

## Generate config files

You can manually generate the alerts, dashboards and rules files:

```
$ make prometheus_alerts.yaml
$ make prometheus_rules.yaml
$ make dashboards_out
```

The `prometheus_alerts.yaml` and `prometheus_rules.yaml` file then need to passed
to your Prometheus server, and the files in `dashboards_out` need to be imported
into you Grafana server. The exact details will depending on how you deploy your
monitoring stack.

## Running the tests (requires Docker)

Build the mixins, run the tests:

```
$ docker run -v $(pwd):/tmp --entrypoint "/bin/promtool" prom/prometheus:latest test rules /tmp/tests.yaml
```

Generate the alerts, rules and dashboards:

```
$ jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusAlerts)' > alerts.yml
$ jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusRules)' >files/rules.yml
$ jsonnet -J vendor -m files/dashboards -e '(import "mixin.libsonnet").grafanaDashboards'
```

## Background

* For more motivation, see
"[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.
* For more information about monitoring mixins, see this [design doc](https://docs.google.com/document/d/1A9xvzwqnFVSOZ5fD3blKODXfsat5fg6ZhnKu9LK3lB4/edit#).
1 change: 1 addition & 0 deletions vitess-mixin/alerts/alerts.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions vitess-mixin/alerts/default_alerts.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
39 changes: 39 additions & 0 deletions vitess-mixin/config.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
_config+:: {

// Selectors are inserted between {} in Prometheus queries.
regionSelector: 'region="$region"',
vtctldSelector: 'job="vitess-vtctld"',
vtgateSelector: 'job="vitess-vtgate"',
vttabletSelector: 'job="vitess-vttablet"',
vtworkerSelector: 'job="vitess-vtworker"',
mysqlSelector: 'job="mysql"',

// Datasource to use
dataSource: 'Prometheus_Vitess',

// Default config for the Grafana dashboards in the Vitess Mixin
grafanaDashboardMetadataDefault: {
dashboardNamePrefix: 'Vitess /',
dashboardNameSuffix: '(auto-generated)',
dashboardTags: ['vitess-mixin'],
},

// Grafana dashboard IDs are necessary for stable links for dashboards
grafanaDashboardMetadata: {
cluster_overview: {
uid: '0d0778047f5a64ff2ea084ec3e',
title: '%(dashboardNamePrefix)s Cluster Overview %(dashboardNameSuffix)s' % $._config.grafanaDashboardMetadataDefault,
description: 'Vitess cluster overview',
dashboardTags: $._config.grafanaDashboardMetadataDefault.dashboardTags + ['overview', 'cluster'],
},
keyspace_overview: {
uid: 'ff33eceed7d2b1267dd286a099',
title: '%(dashboardNamePrefix)s Keyspace Overview %(dashboardNameSuffix)s' % $._config.grafanaDashboardMetadataDefault,
description: 'General keyspace overview',
dashboardTags: $._config.grafanaDashboardMetadataDefault.dashboardTags + ['overview', 'keyspace'],
},
},

},
}
Loading

0 comments on commit bd8205e

Please sign in to comment.