From c719fdca378c3360cb42ffc95810753db6efe1f5 Mon Sep 17 00:00:00 2001 From: William Petit Date: Sat, 8 Jul 2023 12:18:38 -0600 Subject: [PATCH] feat: add prometheus + grafterm dashboard in local dev environment --- Makefile | 20 +- .../tutorials/getting-started-with-sources.md | 13 +- misc/grafterm/dashboard.json | 196 ++++++++++++++++++ misc/prometheus/prometheus.yml | 7 + misc/siege/urls.txt | 6 + modd.conf | 5 + 6 files changed, 243 insertions(+), 4 deletions(-) create mode 100644 misc/grafterm/dashboard.json create mode 100644 misc/prometheus/prometheus.yml create mode 100644 misc/siege/urls.txt diff --git a/Makefile b/Makefile index e704412..13ec1aa 100644 --- a/Makefile +++ b/Makefile @@ -101,6 +101,12 @@ gitea-release: tools/gitea-release/bin/gitea-release.sh goreleaser GITEA_RELEASE_ATTACHMENTS="$$(find .gitea-release/* -type f)" \ tools/gitea-release/bin/gitea-release.sh +grafterm: tools/grafterm/bin/grafterm + tools/grafterm/bin/grafterm -c ./misc/grafterm/dashboard.json -v job=bouncer-proxy -r 5s + +siege: + siege -i -c 100 -f ./misc/siege/urls.txt + tools/gitea-release/bin/gitea-release.sh: mkdir -p tools/gitea-release/bin curl --output tools/gitea-release/bin/gitea-release.sh https://forge.cadoles.com/Cadoles/Jenkins/raw/branch/master/resources/com/cadoles/gitea/gitea-release.sh @@ -110,6 +116,10 @@ tools/modd/bin/modd: mkdir -p tools/modd/bin GOBIN=$(PWD)/tools/modd/bin go install github.com/cortesi/modd/cmd/modd@latest +tools/grafterm/bin/grafterm: + mkdir -p tools/grafterm/bin + GOBIN=$(PWD)/tools/grafterm/bin go install github.com/slok/grafterm/cmd/grafterm@v0.2.0 + full-version: @echo $(FULL_VERSION) @@ -128,4 +138,12 @@ run-redis: redis-shell: docker exec -it \ bouncer-redis \ - redis-cli \ No newline at end of file + redis-cli + +run-prometheus: + docker kill bouncer-prometheus || exit 0 + docker run --rm -t \ + --name bouncer-prometheus \ + --network host \ + -v $(PWD)/misc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \ + prom/prometheus \ No newline at end of file diff --git a/doc/fr/tutorials/getting-started-with-sources.md b/doc/fr/tutorials/getting-started-with-sources.md index a9708f7..a45006c 100644 --- a/doc/fr/tutorials/getting-started-with-sources.md +++ b/doc/fr/tutorials/getting-started-with-sources.md @@ -70,15 +70,15 @@ docker run --rm -t \ Surveiller les sources, compiler celles ci en cas de modifications et lancer les services `bouncer-proxy` et `bouncer-admin`. -#### `make test` +### `make test` Exécuter les tests unitaires/d'intégration du projet. -#### `make build` +### `make build` Compiler une version de développement du binaire `bouncer`. -#### `make docker-build` +### `make docker-build` Construire une image Docker pour Bouncer. @@ -92,6 +92,13 @@ docker run \ bouncer server proxy run ``` +### `make grafterm` + +Afficher un tableau de bord [`grafterm`](https://github.com/slok/grafterm) branché sur l'instance Prometheus locale. + +### `make siege` + +Lancer une session de test [`siege`](https://github.com/JoeDog/siege) sur l'instance `bouncer-proxy` locale. ## Arborescence du projet ```bash diff --git a/misc/grafterm/dashboard.json b/misc/grafterm/dashboard.json new file mode 100644 index 0000000..7b5d1ea --- /dev/null +++ b/misc/grafterm/dashboard.json @@ -0,0 +1,196 @@ +{ + "version": "v1", + "datasources": { + "prometheus": { + "prometheus": { + "address": "http://127.0.0.1:9090" + } + } + }, + "dashboard": { + "variables": { + "job": { + "constant": { "value": "bouncer-proxy" } + }, + "interval": { + "interval": { "steps": 50 } + } + }, + "widgets": [ + { + "title": "Bouncer - Total queue sessions", + "gridPos": { "w": 20 }, + "singlestat": { + "thresholds": [{ "color": "#47D038" }], + "query": { + "datasourceID": "prometheus", + "expr": "sum(bouncer_layer_queue_sessions{job=\"{{.job}}\"})" + } + } + }, + { + "title": "Bouncer Traffic", + "gridPos": { + "w": 80 + }, + "graph": { + "queries": [ + { + "datasourceID": "prometheus", + "expr": "sum(rate(bouncer_proxy_director_proxy_requests_total{job=\"{{.job}}\"}[{{.interval}}]))", + "legend": "req/s" + } + ] + } + }, + { + "title": "Goroutines", + "gridPos": { "w": 20 }, + "singlestat": { + "thresholds": [{ "color": "#47D038" }], + "query": { + "datasourceID": "prometheus", + "expr": "sum(go_goroutines{job=\"{{.job}}\"})" + } + } + }, + { + "title": "GC duration", + "gridPos": { "w": 20 }, + "singlestat": { + "unit": "second", + "query": { + "datasourceID": "prometheus", + "expr": "max(go_gc_duration_seconds{job=\"{{.job}}\"})" + } + } + }, + { + "title": "Stack", + "gridPos": { "w": 20 }, + "singlestat": { + "unit": "bytes", + "thresholds": [{ "color": "#22F1F1" }], + "query": { + "datasourceID": "prometheus", + "expr": "sum(go_memstats_stack_inuse_bytes{job=\"{{.job}}\"})" + } + } + }, + { + "title": "Heap", + "gridPos": { "w": 20 }, + "singlestat": { + "unit": "bytes", + "thresholds": [{ "color": "#22F1F1" }], + "query": { + "datasourceID": "prometheus", + "expr": "sum(go_memstats_heap_inuse_bytes{job=\"{{.job}}\"})" + } + } + }, + { + "title": "Alloc", + "gridPos": { "w": 20 }, + "singlestat": { + "unit": "bytes", + "thresholds": [{ "color": "#22F1F1" }], + "query": { + "datasourceID": "prometheus", + "expr": "sum(go_memstats_alloc_bytes{job=\"{{.job}}\"})" + } + } + }, + { + "title": "Goroutines", + "gridPos": { "w": 50 }, + "graph": { + "visualization": { + "legend": { "disable": true }, + "yAxis": { "unit": "", "decimals": 2 } + }, + "queries": [ + { + "datasourceID": "prometheus", + "expr": "sum(go_goroutines{job=\"{{.job}}\"})" + } + ] + } + }, + { + "title": "GC duration", + "gridPos": { "w": 50 }, + "graph": { + "queries": [ + { + "datasourceID": "prometheus", + "expr": "max(go_gc_duration_seconds{job=\"{{.job}}\"}) by (quantile)", + "legend": "Q{{.quantile}}" + } + ], + "visualization": { + "yAxis": { "unit": "second" }, + "seriesOverride": [ + { "regex": "^Q0$", "color": "#F9E2D2" }, + { "regex": "^Q0.25$", "color": "#F2C96D" }, + { "regex": "^Q0.5(0)?$", "color": "#EAB839" }, + { "regex": "^Q0.75$", "color": "#EF843C" }, + { "regex": "^Q1(.0)?$", "color": "#E24D42" } + ] + } + } + }, + { + "title": "Memory", + "gridPos": { "w": 50 }, + "graph": { + "visualization": { + "yAxis": { "unit": "byte", "decimals": 0 } + }, + "queries": [ + { + "datasourceID": "prometheus", + "expr": "sum(go_memstats_stack_inuse_bytes{job=\"{{.job}}\"})", + "legend": "stack inuse" + }, + { + "datasourceID": "prometheus", + "expr": "sum(go_memstats_heap_inuse_bytes{job=\"{{.job}}\"})", + "legend": "heap inuse" + }, + { + "datasourceID": "prometheus", + "expr": "sum(go_memstats_alloc_bytes{job=\"{{.job}}\"})", + "legend": "alloc" + } + ] + } + }, + { + "title": "Memory ops rate", + "gridPos": { + "w": 50 + }, + "graph": { + "queries": [ + { + "datasourceID": "prometheus", + "expr": "sum(rate(go_memstats_frees_total{job=\"{{.job}}\"}[{{.interval}}]))", + "legend": "frees/s" + }, + { + "datasourceID": "prometheus", + "expr": "sum(rate(go_memstats_mallocs_total{job=\"{{.job}}\"}[{{.interval}}]))", + "legend": "mallocs/s" + }, + { + "datasourceID": "prometheus", + "expr": "sum(rate(go_memstats_lookups_total{job=\"{{.job}}\"}[{{.interval}}]))", + "legend": "lookups/s" + } + ] + } + } + ] + } +} \ No newline at end of file diff --git a/misc/prometheus/prometheus.yml b/misc/prometheus/prometheus.yml new file mode 100644 index 0000000..6c1a23b --- /dev/null +++ b/misc/prometheus/prometheus.yml @@ -0,0 +1,7 @@ +scrape_configs: + - job_name: bouncer-proxy + metrics_path: /.bouncer/metrics + static_configs: + - targets: + - "localhost:8080" + scrape_interval: 5s \ No newline at end of file diff --git a/misc/siege/urls.txt b/misc/siege/urls.txt new file mode 100644 index 0000000..a830156 --- /dev/null +++ b/misc/siege/urls.txt @@ -0,0 +1,6 @@ +http://localhost:8080/blog/ +http://localhost:8080/services/ +http://localhost:8080/ +http://localhost:8080/recrutement/ +http://localhost:8080/faq/ +http://localhost:8080/societe/histoire/ \ No newline at end of file diff --git a/modd.conf b/modd.conf index 4f5a88f..1873e0c 100644 --- a/modd.conf +++ b/modd.conf @@ -14,4 +14,9 @@ layers/** { daemon +sigint: make run-redis +} + +misc/prometheus/prometheus.yml +{ + daemon +sigint: make run-prometheus } \ No newline at end of file