From 7a32f37c1d7ce4b823a702301175d655271bc40e Mon Sep 17 00:00:00 2001 From: Vitaly Date: Mon, 8 Nov 2021 16:14:41 +0300 Subject: [PATCH 01/22] add gitea mixin --- contrib/gitea-mixin/.gitignore | 2 + contrib/gitea-mixin/Makefile | 31 +++ contrib/gitea-mixin/README.md | 38 +++ contrib/gitea-mixin/alerts/alerts.libsonnet | 12 + contrib/gitea-mixin/config.libsonnet | 47 ++++ .../dashboards/dashboards.libsonnet | 1 + .../gitea-mixin/dashboards/overview.libsonnet | 229 ++++++++++++++++++ contrib/gitea-mixin/jsonnetfile.json | 15 ++ contrib/gitea-mixin/jsonnetfile.lock.json | 16 ++ contrib/gitea-mixin/lib/alerts.jsonnet | 1 + contrib/gitea-mixin/lib/dashboards.jsonnet | 6 + contrib/gitea-mixin/lib/rules.jsonnet | 1 + contrib/gitea-mixin/mixin.libsonnet | 4 + contrib/gitea-mixin/rules/rules.libsonnet | 15 ++ 14 files changed, 418 insertions(+) create mode 100644 contrib/gitea-mixin/.gitignore create mode 100644 contrib/gitea-mixin/Makefile create mode 100644 contrib/gitea-mixin/README.md create mode 100644 contrib/gitea-mixin/alerts/alerts.libsonnet create mode 100644 contrib/gitea-mixin/config.libsonnet create mode 100644 contrib/gitea-mixin/dashboards/dashboards.libsonnet create mode 100644 contrib/gitea-mixin/dashboards/overview.libsonnet create mode 100644 contrib/gitea-mixin/jsonnetfile.json create mode 100644 contrib/gitea-mixin/jsonnetfile.lock.json create mode 100644 contrib/gitea-mixin/lib/alerts.jsonnet create mode 100644 contrib/gitea-mixin/lib/dashboards.jsonnet create mode 100644 contrib/gitea-mixin/lib/rules.jsonnet create mode 100644 contrib/gitea-mixin/mixin.libsonnet create mode 100644 contrib/gitea-mixin/rules/rules.libsonnet diff --git a/contrib/gitea-mixin/.gitignore b/contrib/gitea-mixin/.gitignore new file mode 100644 index 000000000000..f8472b0a233b --- /dev/null +++ b/contrib/gitea-mixin/.gitignore @@ -0,0 +1,2 @@ +dashboards_out +vendor diff --git a/contrib/gitea-mixin/Makefile b/contrib/gitea-mixin/Makefile new file mode 100644 index 000000000000..952143eac5c7 --- /dev/null +++ b/contrib/gitea-mixin/Makefile @@ -0,0 +1,31 @@ +JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 1 --string-style s --comment-style s + +default: vendor build dashboards_out prometheus_alerts.yaml prometheus_rules.yaml + +all: fmt build + +vendor: + jb install + +fmt: + find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ + xargs -n 1 -- $(JSONNET_FMT) -i + +lint: build + find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ + while read f; do \ + $(JSONNET_FMT) "$$f" | diff -u "$$f" -; \ + done + mixtool lint mixin.libsonnet + +dashboards_out: mixin.libsonnet config.libsonnet $(wildcard dashboards/*) + @mkdir -p dashboards_out + jsonnet -J vendor -m dashboards_out lib/dashboards.jsonnet + +prometheus_alerts.yaml: mixin.libsonnet lib/alerts.jsonnet alerts/*.libsonnet + jsonnet -J vendor -S lib/alerts.jsonnet > $@ + +prometheus_rules.yaml: mixin.libsonnet lib/rules.jsonnet rules/*.libsonnet + jsonnet -J vendor -S lib/rules.jsonnet > $@ + +build: vendor diff --git a/contrib/gitea-mixin/README.md b/contrib/gitea-mixin/README.md new file mode 100644 index 000000000000..99bc3864ae94 --- /dev/null +++ b/contrib/gitea-mixin/README.md @@ -0,0 +1,38 @@ +# Gitea Mixin + +Gitea Mixin is a set of configurable, reusable, and extensible alerts and +dashboards based on the metrics exported by the Gitea built-in metrics endpoint. The mixin creates +recording and alerting rules for Prometheus and suitable dashboard descriptions +for Grafana. + +## Generate config files + +You can manually generate the alerts, dashboards and rules files, but first you +must install some tools: + +```bash +go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb +go get github.com/google/go-jsonnet/cmd/jsonnet +# or in brew: brew install go-jsonnet +``` + +For linting and formatting, you would also need `mixtool` and `jsonnetfmt` installed. If you +have a working Go development environment, it's easiest to run the following: + +```bash +go get github.com/monitoring-mixins/mixtool/cmd/mixtool +go get github.com/google/go-jsonnet/cmd/jsonnetfmt +``` + +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 your Grafana server. The exact details will be depending on your environment. + +Edit `config.libsonnet` if required and then build JSON dashboard files for Grafana: + +```bash +make +``` + +For more advanced uses of mixins, see +https://github.com/monitoring-mixins/docs. diff --git a/contrib/gitea-mixin/alerts/alerts.libsonnet b/contrib/gitea-mixin/alerts/alerts.libsonnet new file mode 100644 index 000000000000..b635ee1d2d0a --- /dev/null +++ b/contrib/gitea-mixin/alerts/alerts.libsonnet @@ -0,0 +1,12 @@ +{ + prometheusAlerts+:: { + // groups+: [ + // { + // name: 'gitea sample alert', + // rules: [ + // // rules here + // ], + // }, + // ], + }, +} diff --git a/contrib/gitea-mixin/config.libsonnet b/contrib/gitea-mixin/config.libsonnet new file mode 100644 index 000000000000..823c2f8b51b8 --- /dev/null +++ b/contrib/gitea-mixin/config.libsonnet @@ -0,0 +1,47 @@ +{ + _config+:: { + local c = self, + dashboardNamePrefix: 'Gitea', + dashboardTags: ['gitea'], + + // add or remove metrics from dashboard + giteaStatMetrics: [ + { + name: 'gitea_organizations', + description: 'Organizations', + }, + { + name: 'gitea_teams', + description: 'Teams', + }, + { + name: 'gitea_users', + description: 'Users', + }, + { + name: 'gitea_repositories', + description: 'Repositories', + }, + { + name: 'gitea_milestones', + description: 'Milestones', + }, + { + name: 'gitea_stars', + description: 'Stars', + }, + { + name: 'gitea_releases', + description: 'Releases', + }, + { + name: 'gitea_issues', + description: 'Issues', + }, + { + name: 'gitea_comments', + description: 'Comments', + }, + ], + }, +} diff --git a/contrib/gitea-mixin/dashboards/dashboards.libsonnet b/contrib/gitea-mixin/dashboards/dashboards.libsonnet new file mode 100644 index 000000000000..800feec120b6 --- /dev/null +++ b/contrib/gitea-mixin/dashboards/dashboards.libsonnet @@ -0,0 +1 @@ +(import 'overview.libsonnet') diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet new file mode 100644 index 000000000000..3b444eb0e3b6 --- /dev/null +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -0,0 +1,229 @@ +local grafana = import 'github.com/grafana/grafonnet-lib/grafonnet/grafana.libsonnet'; +local prometheus = grafana.prometheus; + +{ + + grafanaDashboards+:: { + + local giteaSelector = 'job="$job", instance="$instance"', + local giteaStatsPanel = grafana.statPanel.new( + 'Gitea stats', + datasource='$datasource', + reducerFunction='last', + graphMode='none', + colorMode='value', + ) + .addTargets( + [ + prometheus.target(expr='%s{%s}' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=10) + for metric in $._config.giteaStatMetrics + ] + ) + + { + fieldConfig+: { + defaults+: { + color: { + fixedColor: 'blue', + mode: 'fixed', + }, + }, + }, + }, + + local giteaUptimePanel = grafana.statPanel.new( + 'Uptime', + datasource='$datasource', + reducerFunction='last', + graphMode='area', //none, + colorMode='value', //background + ) + .addTarget(prometheus.target(expr='time()-process_start_time_seconds{%s}' % giteaSelector, intervalFactor=1)) + // add color + + { + fieldConfig+: { + defaults+: { + color: { + fixedColor: 'blue', + mode: 'fixed', + }, + unit: 's', + }, + }, + }, + + local giteaMemoryPanel = grafana.graphPanel.new( + 'Memory(rss) usage', + datasource='$datasource', + format='decbytes', + lines=true, + fill=1, + legend_show=false + ) + .addTarget(prometheus.target(expr='process_resident_memory_bytes{%s}' % giteaSelector, intervalFactor=2)), + + local giteaCpuPanel = grafana.graphPanel.new( + 'CPU usage', + datasource='$datasource', + format='percent', + lines=true, + fill=1, + legend_show=false + ) + .addTarget(prometheus.target(expr='rate(process_cpu_seconds_total{%s}[$__rate_interval])*100' % giteaSelector, intervalFactor=2)), + + local giteaFileDescriptorsPanel = grafana.graphPanel.new( + 'File descriptors usage', + datasource='$datasource', + format='', + lines=true, + fill=1, + legend_show=false + ) + .addTarget(prometheus.target(expr='process_open_fds{%s}' % giteaSelector, intervalFactor=2)) + .addTarget(prometheus.target(expr='process_max_fds{%s}' % giteaSelector, intervalFactor=2)) + .addSeriesOverride( + { + alias: '/process_max_fds.+/', + color: '#F2495C', // red + dashes: true, + fill: 0, + }, + ), + + local giteaChangesPanel = grafana.graphPanel.new( + 'Gitea changes', + datasource='$datasource', + lines=false, + points=true + ) + .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__rate_interval]) > 0' % [giteaSelector], legendFormat='Restart', intervalFactor=1)) + .addTargets( + [ + prometheus.target(expr='changes(%s{%s}[$__rate_interval]) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) + for metric in $._config.giteaStatMetrics + ] + ), + + 'gitea-overview.json': + grafana.dashboard.new( + '%s Overview' % $._config.dashboardNamePrefix, + time_from='now-1h', + editable=false, + tags=($._config.dashboardTags), + timezone='utc', + refresh='1m', + graphTooltip='shared_crosshair', + uid='gitea-overview' + ) + .addTemplate( + { + current: { + text: 'Prometheus', + value: 'Prometheus', + }, + hide: 0, + label: null, + name: 'datasource', + options: [], + query: 'prometheus', + refresh: 1, + regex: '', + type: 'datasource', + }, + ) + .addTemplate( + { + hide: 0, + label: null, + name: 'job', + options: [], + query: 'label_values(gitea_organizations, job)', + refresh: 1, + regex: '', + type: 'query', + }, + ) + .addTemplate( + { + hide: 0, + label: null, + name: 'instance', + options: [], + query: 'label_values(gitea_organizations{job="$job"}, instance)', + refresh: 1, + regex: '', + type: 'query', + }, + ) + .addPanel( + grafana.row.new(title='General'), gridPos={ + x: 0, + y: 0, + w: 0, + h: 0, + }, + ) + .addPanel( + giteaStatsPanel, gridPos={ + x: 0, + y: 0, + w: 16, + h: 4, + } + ) + .addPanel( + giteaUptimePanel, gridPos={ + x: 16, + y: 0, + w: 8, + h: 4, + } + ) + .addPanel( + giteaMemoryPanel, gridPos={ + x: 0, + y: 4, + w: 8, + h: 6, + } + ) + .addPanel( + giteaCpuPanel, gridPos={ + x: 8, + y: 4, + w: 8, + h: 6, + } + ) + .addPanel( + giteaFileDescriptorsPanel, gridPos={ + x: 16, + y: 4, + w: 8, + h: 6, + } + ) + .addPanel( + grafana.row.new( + title='Changes', + collapse=false + ), + gridPos={ + x: 0, + y: 10, + w: 24, + h: 8, + } + ) + .addPanel( + giteaChangesPanel, + gridPos={ + x: 0, + y: 10, + w: 24, + h: 8, + } + ), + + }, +} diff --git a/contrib/gitea-mixin/jsonnetfile.json b/contrib/gitea-mixin/jsonnetfile.json new file mode 100644 index 000000000000..5e9bae205d3e --- /dev/null +++ b/contrib/gitea-mixin/jsonnetfile.json @@ -0,0 +1,15 @@ +{ + "version": 1, + "dependencies": [ + { + "source": { + "git": { + "remote": "https://github.com/grafana/grafonnet-lib.git", + "subdir": "grafonnet" + } + }, + "version": "master" + } + ], + "legacyImports": false + } \ No newline at end of file diff --git a/contrib/gitea-mixin/jsonnetfile.lock.json b/contrib/gitea-mixin/jsonnetfile.lock.json new file mode 100644 index 000000000000..1b634a3f2aaa --- /dev/null +++ b/contrib/gitea-mixin/jsonnetfile.lock.json @@ -0,0 +1,16 @@ +{ + "version": 1, + "dependencies": [ + { + "source": { + "git": { + "remote": "https://github.com/grafana/grafonnet-lib.git", + "subdir": "grafonnet" + } + }, + "version": "55cf4ee53ced2b6d3ce96ecce9fb813b4465be98", + "sum": "4/sUV0Kk+o8I+wlYxL9R6EPhL/NiLfYHk+NXlU64RUk=" + } + ], + "legacyImports": false + } \ No newline at end of file diff --git a/contrib/gitea-mixin/lib/alerts.jsonnet b/contrib/gitea-mixin/lib/alerts.jsonnet new file mode 100644 index 000000000000..d396a38cd711 --- /dev/null +++ b/contrib/gitea-mixin/lib/alerts.jsonnet @@ -0,0 +1 @@ +std.manifestYamlDoc((import '../mixin.libsonnet').prometheusAlerts) diff --git a/contrib/gitea-mixin/lib/dashboards.jsonnet b/contrib/gitea-mixin/lib/dashboards.jsonnet new file mode 100644 index 000000000000..dadaebe9bc44 --- /dev/null +++ b/contrib/gitea-mixin/lib/dashboards.jsonnet @@ -0,0 +1,6 @@ +local dashboards = (import '../mixin.libsonnet').grafanaDashboards; + +{ + [name]: dashboards[name] + for name in std.objectFields(dashboards) +} diff --git a/contrib/gitea-mixin/lib/rules.jsonnet b/contrib/gitea-mixin/lib/rules.jsonnet new file mode 100644 index 000000000000..2d7fa91f7ca8 --- /dev/null +++ b/contrib/gitea-mixin/lib/rules.jsonnet @@ -0,0 +1 @@ +std.manifestYamlDoc((import '../mixin.libsonnet').prometheusRules) diff --git a/contrib/gitea-mixin/mixin.libsonnet b/contrib/gitea-mixin/mixin.libsonnet new file mode 100644 index 000000000000..152721db9cb2 --- /dev/null +++ b/contrib/gitea-mixin/mixin.libsonnet @@ -0,0 +1,4 @@ +(import 'alerts/alerts.libsonnet') + +(import 'dashboards/dashboards.libsonnet') + +(import 'rules/rules.libsonnet') + +(import 'config.libsonnet') diff --git a/contrib/gitea-mixin/rules/rules.libsonnet b/contrib/gitea-mixin/rules/rules.libsonnet new file mode 100644 index 000000000000..b1056bfedb11 --- /dev/null +++ b/contrib/gitea-mixin/rules/rules.libsonnet @@ -0,0 +1,15 @@ +{ + prometheusRules+:: { + groups+: [ + // { + // name: 'group name', + // rules: [ + // { + // record: 'new metric name', + // expr: '', + // }, + // ], + // } + ], + }, +} From 9d7f1b6a091d709748b3496a2f069a93c4e6eb4d Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Mon, 22 Nov 2021 14:56:56 +0300 Subject: [PATCH 02/22] remove alerts/rules --- contrib/gitea-mixin/Makefile | 8 +------- contrib/gitea-mixin/README.md | 11 +++-------- contrib/gitea-mixin/alerts/alerts.libsonnet | 12 ------------ contrib/gitea-mixin/dashboards/overview.libsonnet | 5 ++--- contrib/gitea-mixin/mixin.libsonnet | 2 -- contrib/gitea-mixin/rules/rules.libsonnet | 15 --------------- 6 files changed, 6 insertions(+), 47 deletions(-) delete mode 100644 contrib/gitea-mixin/alerts/alerts.libsonnet delete mode 100644 contrib/gitea-mixin/rules/rules.libsonnet diff --git a/contrib/gitea-mixin/Makefile b/contrib/gitea-mixin/Makefile index 952143eac5c7..72eea0ca8da7 100644 --- a/contrib/gitea-mixin/Makefile +++ b/contrib/gitea-mixin/Makefile @@ -1,6 +1,6 @@ JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 1 --string-style s --comment-style s -default: vendor build dashboards_out prometheus_alerts.yaml prometheus_rules.yaml +default: vendor build dashboards_out all: fmt build @@ -22,10 +22,4 @@ dashboards_out: mixin.libsonnet config.libsonnet $(wildcard dashboards/*) @mkdir -p dashboards_out jsonnet -J vendor -m dashboards_out lib/dashboards.jsonnet -prometheus_alerts.yaml: mixin.libsonnet lib/alerts.jsonnet alerts/*.libsonnet - jsonnet -J vendor -S lib/alerts.jsonnet > $@ - -prometheus_rules.yaml: mixin.libsonnet lib/rules.jsonnet rules/*.libsonnet - jsonnet -J vendor -S lib/rules.jsonnet > $@ - build: vendor diff --git a/contrib/gitea-mixin/README.md b/contrib/gitea-mixin/README.md index 99bc3864ae94..30bd3d7e3a2b 100644 --- a/contrib/gitea-mixin/README.md +++ b/contrib/gitea-mixin/README.md @@ -1,14 +1,10 @@ # Gitea Mixin -Gitea Mixin is a set of configurable, reusable, and extensible alerts and -dashboards based on the metrics exported by the Gitea built-in metrics endpoint. The mixin creates -recording and alerting rules for Prometheus and suitable dashboard descriptions -for Grafana. +Gitea Mixin is a set of configurable Grafana dashboards based on the metrics exported by the Gitea built-in metrics endpoint. ## Generate config files -You can manually generate the alerts, dashboards and rules files, but first you -must install some tools: +You can manually generate dashboards, but first you should install some tools: ```bash go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb @@ -24,8 +20,7 @@ go get github.com/monitoring-mixins/mixtool/cmd/mixtool go get github.com/google/go-jsonnet/cmd/jsonnetfmt ``` -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 +The files in `dashboards_out` need to be imported into your Grafana server. The exact details will be depending on your environment. Edit `config.libsonnet` if required and then build JSON dashboard files for Grafana: diff --git a/contrib/gitea-mixin/alerts/alerts.libsonnet b/contrib/gitea-mixin/alerts/alerts.libsonnet deleted file mode 100644 index b635ee1d2d0a..000000000000 --- a/contrib/gitea-mixin/alerts/alerts.libsonnet +++ /dev/null @@ -1,12 +0,0 @@ -{ - prometheusAlerts+:: { - // groups+: [ - // { - // name: 'gitea sample alert', - // rules: [ - // // rules here - // ], - // }, - // ], - }, -} diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index 3b444eb0e3b6..3563dcd3d13e 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -34,11 +34,10 @@ local prometheus = grafana.prometheus; 'Uptime', datasource='$datasource', reducerFunction='last', - graphMode='area', //none, - colorMode='value', //background + graphMode='area', + colorMode='value', ) .addTarget(prometheus.target(expr='time()-process_start_time_seconds{%s}' % giteaSelector, intervalFactor=1)) - // add color + { fieldConfig+: { defaults+: { diff --git a/contrib/gitea-mixin/mixin.libsonnet b/contrib/gitea-mixin/mixin.libsonnet index 152721db9cb2..bb56a6c0b6f3 100644 --- a/contrib/gitea-mixin/mixin.libsonnet +++ b/contrib/gitea-mixin/mixin.libsonnet @@ -1,4 +1,2 @@ -(import 'alerts/alerts.libsonnet') + (import 'dashboards/dashboards.libsonnet') + -(import 'rules/rules.libsonnet') + (import 'config.libsonnet') diff --git a/contrib/gitea-mixin/rules/rules.libsonnet b/contrib/gitea-mixin/rules/rules.libsonnet deleted file mode 100644 index b1056bfedb11..000000000000 --- a/contrib/gitea-mixin/rules/rules.libsonnet +++ /dev/null @@ -1,15 +0,0 @@ -{ - prometheusRules+:: { - groups+: [ - // { - // name: 'group name', - // rules: [ - // { - // record: 'new metric name', - // expr: '', - // }, - // ], - // } - ], - }, -} From 8d78b7ade983035fff74d2d2007acddf6c64bd18 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Wed, 24 Nov 2021 18:03:26 +0300 Subject: [PATCH 03/22] gitea-mixin: add interval factor of 1/2 to remove duplicated change events --- contrib/gitea-mixin/dashboards/overview.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index 3563dcd3d13e..33a67eeb70bc 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -98,7 +98,7 @@ local prometheus = grafana.prometheus; .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__rate_interval]) > 0' % [giteaSelector], legendFormat='Restart', intervalFactor=1)) .addTargets( [ - prometheus.target(expr='changes(%s{%s}[$__rate_interval]) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) + prometheus.target(expr='changes(%s{%s}[$__rate_interval]) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=2) for metric in $._config.giteaStatMetrics ] ), From 124698819aee20c7a2232b85ca816606a0ab5e27 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Mon, 13 Dec 2021 15:17:12 +0300 Subject: [PATCH 04/22] gitea-mixin: fix changes panel, add aggregation interval for changes panel --- .../gitea-mixin/dashboards/overview.libsonnet | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index 33a67eeb70bc..4bca58829db9 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -93,12 +93,18 @@ local prometheus = grafana.prometheus; 'Gitea changes', datasource='$datasource', lines=false, - points=true + points=false, + bars=true, + stack=true, + interval="$agg_interval", + maxDataPoints=10000, + legend_values=true, + legend_total=true, ) - .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__rate_interval]) > 0' % [giteaSelector], legendFormat='Restart', intervalFactor=1)) + .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__interval])' % [giteaSelector], legendFormat='Restarts', intervalFactor=1)) .addTargets( [ - prometheus.target(expr='changes(%s{%s}[$__rate_interval]) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=2) + prometheus.target(expr='floor(increase(%s{%s}[$__interval]))' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) for metric in $._config.giteaStatMetrics ] ), @@ -154,6 +160,18 @@ local prometheus = grafana.prometheus; type: 'query', }, ) + .addTemplate( + { + hide: 0, + label: 'aggregation interval', + name: 'agg_interval', + current: 'auto', + auto_min: '1m', + auto: true, + query: '1m,10m,1h,1d,7d', + type: 'interval', + }, + ) .addPanel( grafana.row.new(title='General'), gridPos={ x: 0, From 6f6622ad7bd4469e3a64f27aac7c5382bbb1f1af Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Mon, 13 Dec 2021 16:17:27 +0300 Subject: [PATCH 05/22] gitea-mixin: add totals singlestat --- .../gitea-mixin/dashboards/overview.libsonnet | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index 4bca58829db9..bae5fda2bb69 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -90,7 +90,7 @@ local prometheus = grafana.prometheus; ), local giteaChangesPanel = grafana.graphPanel.new( - 'Gitea changes', + '', datasource='$datasource', lines=false, points=false, @@ -101,13 +101,38 @@ local prometheus = grafana.prometheus; legend_values=true, legend_total=true, ) - .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__interval])' % [giteaSelector], legendFormat='Restarts', intervalFactor=1)) + .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__interval]) > 0' % [giteaSelector], legendFormat='Restarts', intervalFactor=1)) .addTargets( [ - prometheus.target(expr='floor(increase(%s{%s}[$__interval]))' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) + prometheus.target(expr='floor(increase(%s{%s}[$__interval])) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) for metric in $._config.giteaStatMetrics ] ), + local giteaChangesPanelTotal = grafana.statPanel.new( + '', + datasource='-- Dashboard --', + reducerFunction='sum', + graphMode='none', + colorMode='value', + ) + + { + targets+: [ + { + panelId: 10, // id of giteaChangesPanel + refId: "A" + }, + ], + } + + { + fieldConfig+: { + defaults+: { + color: { + fixedColor: 'blue', + mode: 'fixed', + }, + }, + }, + }, 'gitea-overview.json': grafana.dashboard.new( @@ -233,11 +258,20 @@ local prometheus = grafana.prometheus; } ) .addPanel( - giteaChangesPanel, + giteaChangesPanelTotal, gridPos={ x: 0, - y: 10, - w: 24, + y: 12, + w: 6, + h: 8, + } + ) + .addPanel( + giteaChangesPanel, + gridPos={ + x: 6, + y: 12, + w: 18, h: 8, } ), From f4a07bd0187316890c8101d2b563d3b16b81d4e2 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Mon, 13 Dec 2021 17:04:51 +0300 Subject: [PATCH 06/22] gitea mixin: switch change graph to timeseries type --- .../gitea-mixin/dashboards/overview.libsonnet | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index bae5fda2bb69..226b8cc7ba4b 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -92,14 +92,9 @@ local prometheus = grafana.prometheus; local giteaChangesPanel = grafana.graphPanel.new( '', datasource='$datasource', - lines=false, - points=false, - bars=true, - stack=true, interval="$agg_interval", maxDataPoints=10000, - legend_values=true, - legend_total=true, + ) .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__interval]) > 0' % [giteaSelector], legendFormat='Restarts', intervalFactor=1)) .addTargets( @@ -107,7 +102,41 @@ local prometheus = grafana.prometheus; prometheus.target(expr='floor(increase(%s{%s}[$__interval])) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) for metric in $._config.giteaStatMetrics ] - ), + ) + + { + type: "timeseries", + options+: { + tooltip: { + mode: "multi" + }, + legend+: { + calcs+: [ + "sum" + ], + }, + }, + + fieldConfig+: { + defaults+: { + noValue: "0", + custom+: { + drawStyle: "bars", + barAlignment: -1, + fillOpacity: 50, + pointSize: 1, + lineWidth: 0, + stacking: { + group: "A", + mode: "normal" + }, + }, + } + }, + } + + + { + + }, local giteaChangesPanelTotal = grafana.statPanel.new( '', datasource='-- Dashboard --', From e70fd58ba39a63633c101c3eda0f0884794b208d Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Mon, 13 Dec 2021 19:04:59 +0300 Subject: [PATCH 07/22] add color overrides for issue labels --- contrib/gitea-mixin/config.libsonnet | 27 ++++ .../gitea-mixin/dashboards/overview.libsonnet | 151 ++++++++++++++++-- 2 files changed, 162 insertions(+), 16 deletions(-) diff --git a/contrib/gitea-mixin/config.libsonnet b/contrib/gitea-mixin/config.libsonnet index 823c2f8b51b8..68510f5b2089 100644 --- a/contrib/gitea-mixin/config.libsonnet +++ b/contrib/gitea-mixin/config.libsonnet @@ -43,5 +43,32 @@ description: 'Comments', }, ], + //set this for using label colors on graphs + issueLabels: [ + { + label: "bug", + color: "#ee0701" + }, + { + label: "duplicate", + color: "#cccccc" + }, + { + label: "invalid", + color: "#e6e6e6" + }, + { + label: "enhancement", + color: "#84b6eb" + }, + { + label: "help wanted", + color: "#128a0c" + }, + { + label: "question", + color: "#cc317c" + }, + ] }, } diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index 226b8cc7ba4b..e8b3e6a7aa77 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -1,6 +1,31 @@ local grafana = import 'github.com/grafana/grafonnet-lib/grafonnet/grafana.libsonnet'; local prometheus = grafana.prometheus; + +local addIssueLabelsOverrides(labels) = +{ + fieldConfig+: { + overrides+: [ + { + "matcher": { + "id": "byRegexp", + "options": label.label + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": label.color, + "mode": "fixed" + } + } + ] + } + for label in labels + ] + } +}; + { grafanaDashboards+:: { @@ -89,19 +114,11 @@ local prometheus = grafana.prometheus; }, ), - local giteaChangesPanel = grafana.graphPanel.new( + local giteaChangesPanelPrototype = grafana.graphPanel.new( '', datasource='$datasource', interval="$agg_interval", maxDataPoints=10000, - - ) - .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__interval]) > 0' % [giteaSelector], legendFormat='Restarts', intervalFactor=1)) - .addTargets( - [ - prometheus.target(expr='floor(increase(%s{%s}[$__interval])) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) - for metric in $._config.giteaStatMetrics - ] ) + { type: "timeseries", @@ -115,7 +132,6 @@ local prometheus = grafana.prometheus; ], }, }, - fieldConfig+: { defaults+: { noValue: "0", @@ -123,6 +139,7 @@ local prometheus = grafana.prometheus; drawStyle: "bars", barAlignment: -1, fillOpacity: 50, + gradientMode: "hue", pointSize: 1, lineWidth: 0, stacking: { @@ -132,11 +149,17 @@ local prometheus = grafana.prometheus; }, } }, - } - + - { + }, + + local giteaChangesPanelAll = giteaChangesPanelPrototype + .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__interval]) > 0' % [giteaSelector], legendFormat='Restarts', intervalFactor=1)) + .addTargets( + [ + prometheus.target(expr='floor(increase(%s{%s}[$__interval])) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) + for metric in $._config.giteaStatMetrics + ] + ), - }, local giteaChangesPanelTotal = grafana.statPanel.new( '', datasource='-- Dashboard --', @@ -163,6 +186,66 @@ local prometheus = grafana.prometheus; }, }, + local giteaChangesByRepositories = giteaChangesPanelPrototype + .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_repository{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ repository }}', intervalFactor=1)), + + local giteaChangesByRepositoriesTotal = grafana.statPanel.new( + '', + datasource='-- Dashboard --', + reducerFunction='sum', + graphMode='none', + colorMode='value', + ) + + { + targets+: [ + { + panelId: 12, // id of giteaChangesPanel + refId: "A" + }, + ], + } + + { + fieldConfig+: { + defaults+: { + color: { + fixedColor: 'blue', + mode: 'fixed', + }, + }, + }, + }, + + local giteaChangesByLabel = giteaChangesPanelPrototype + .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_label{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ label }}', intervalFactor=1)) + + addIssueLabelsOverrides($._config.issueLabels), + + local giteaChangesByLabelTotal = grafana.statPanel.new( + '', + datasource='-- Dashboard --', + reducerFunction='sum', + graphMode='none', + colorMode='value', + ) + + addIssueLabelsOverrides($._config.issueLabels) + + { + targets+: [ + { + panelId: 14, // id of giteaChangesPanel + refId: "A" + }, + ], + } + + { + fieldConfig+: { + defaults+: { + color: { + fixedColor: 'blue', + mode: 'fixed', + }, + }, + }, + }, + 'gitea-overview.json': grafana.dashboard.new( '%s Overview' % $._config.dashboardNamePrefix, @@ -295,14 +378,50 @@ local prometheus = grafana.prometheus; h: 8, } ) - .addPanel( - giteaChangesPanel, + .addPanel( // id 10 + giteaChangesPanelAll, gridPos={ x: 6, y: 12, w: 18, h: 8, } + ) + .addPanel( // by repositories split + giteaChangesByRepositoriesTotal, + gridPos={ + x: 0, + y: 20, + w: 6, + h: 8, + } + ) + .addPanel( + giteaChangesByRepositories, // id 12 + gridPos={ + x: 6, + y: 20, + w: 18, + h: 8, + } + ) + .addPanel( // by labels split + giteaChangesByLabelTotal, + gridPos={ + x: 0, + y: 28, + w: 6, + h: 8, + } + ) + .addPanel( // id 14 + giteaChangesByLabel, + gridPos={ + x: 6, + y: 28, + w: 18, + h: 8, + } ), }, From 7ccd873e46bd779185874ba8c131948fd94d2cda Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Mon, 13 Dec 2021 19:32:53 +0300 Subject: [PATCH 08/22] bump grafonnet version --- contrib/gitea-mixin/jsonnetfile.lock.json | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/contrib/gitea-mixin/jsonnetfile.lock.json b/contrib/gitea-mixin/jsonnetfile.lock.json index 1b634a3f2aaa..0430b39fc367 100644 --- a/contrib/gitea-mixin/jsonnetfile.lock.json +++ b/contrib/gitea-mixin/jsonnetfile.lock.json @@ -1,16 +1,16 @@ { - "version": 1, - "dependencies": [ - { - "source": { - "git": { - "remote": "https://github.com/grafana/grafonnet-lib.git", - "subdir": "grafonnet" - } - }, - "version": "55cf4ee53ced2b6d3ce96ecce9fb813b4465be98", - "sum": "4/sUV0Kk+o8I+wlYxL9R6EPhL/NiLfYHk+NXlU64RUk=" - } - ], - "legacyImports": false - } \ No newline at end of file + "version": 1, + "dependencies": [ + { + "source": { + "git": { + "remote": "https://github.com/grafana/grafonnet-lib.git", + "subdir": "grafonnet" + } + }, + "version": "3626fc4dc2326931c530861ac5bebe39444f6cbf", + "sum": "gF8foHByYcB25jcUOBqP6jxk0OPifQMjPvKY0HaCk6w=" + } + ], + "legacyImports": false +} From 55023bd6c5a199415c3af8c4dc60da08b0d118a6 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Mon, 13 Dec 2021 23:50:50 +0300 Subject: [PATCH 09/22] gitea-mixin: convert graphs to timeseries --- .../gitea-mixin/dashboards/overview.libsonnet | 182 ++++++++++++++---- 1 file changed, 146 insertions(+), 36 deletions(-) diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index e8b3e6a7aa77..b9344327ebc0 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -76,43 +76,151 @@ local addIssueLabelsOverrides(labels) = }, local giteaMemoryPanel = grafana.graphPanel.new( - 'Memory(rss) usage', - datasource='$datasource', - format='decbytes', - lines=true, - fill=1, - legend_show=false - ) - .addTarget(prometheus.target(expr='process_resident_memory_bytes{%s}' % giteaSelector, intervalFactor=2)), + 'Memory usage', + datasource='$datasource') + .addTarget(prometheus.target(expr='process_resident_memory_bytes{%s}' % giteaSelector, intervalFactor=2)) + + { + type: "timeseries", + options+: { + tooltip: { + mode: "multi" + }, + legend+: { + displayMode: "hidden" + }, + }, + fieldConfig+: { + defaults+: { + custom+: { + lineInterpolation: "smooth", + fillOpacity: 15, + }, + color: { + fixedColor: 'green', + mode: 'fixed', + }, + unit: "decbytes" + }, + }, + }, local giteaCpuPanel = grafana.graphPanel.new( 'CPU usage', - datasource='$datasource', - format='percent', - lines=true, - fill=1, - legend_show=false - ) - .addTarget(prometheus.target(expr='rate(process_cpu_seconds_total{%s}[$__rate_interval])*100' % giteaSelector, intervalFactor=2)), + datasource='$datasource' + ) + .addTarget(prometheus.target(expr='rate(process_cpu_seconds_total{%s}[$__rate_interval])*100' % giteaSelector, intervalFactor=2)) + + { + type: "timeseries", + options+: { + tooltip: { + mode: "multi" + }, + legend+: { + displayMode: "hidden" + }, + }, + fieldConfig+: { + defaults+: { + custom+: { + lineInterpolation: "smooth", + gradientMode: "scheme", + fillOpacity: 15, + axisSoftMin: 0, + axisSoftMax: 0 + }, + color: { + //mode: "continuous-BlYlRd" // from blue to red (100%) + "mode": "continuous-GrYlRd" + }, + unit: "percent" + }, + overrides: [ + { + "matcher": { + "id": "byRegexp", + "options": ".+" + }, + "properties": [ + { + "id": "max", + "value": 100 + }, + { + "id": "min", + "value": 0 + } + ] + } + ] + }, + }, local giteaFileDescriptorsPanel = grafana.graphPanel.new( 'File descriptors usage', datasource='$datasource', - format='', - lines=true, - fill=1, - legend_show=false - ) - .addTarget(prometheus.target(expr='process_open_fds{%s}' % giteaSelector, intervalFactor=2)) - .addTarget(prometheus.target(expr='process_max_fds{%s}' % giteaSelector, intervalFactor=2)) - .addSeriesOverride( - { - alias: '/process_max_fds.+/', - color: '#F2495C', // red - dashes: true, - fill: 0, - }, - ), + ) + .addTarget(prometheus.target(expr='process_open_fds{%s}' % giteaSelector, intervalFactor=2)) + .addTarget(prometheus.target(expr='process_max_fds{%s}' % giteaSelector, intervalFactor=2)) + .addSeriesOverride( + { + alias: '/process_max_fds.+/', + color: '#F2495C', // red + dashes: true, + fill: 0, + }, + ) + + { + type: "timeseries", + options+: { + tooltip: { + mode: "multi" + }, + legend+: { + displayMode: "hidden" + }, + }, + fieldConfig+: { + defaults+: { + custom+: { + lineInterpolation: "smooth", + gradientMode: "scheme", + fillOpacity: 0, + }, + color: { + fixedColor: 'green', + mode: 'fixed', + }, + unit: "" + }, + "overrides": [ + { + "matcher": { + "id": "byFrameRefID", + "options": "B" + }, + "properties": [ + { + "id": "custom.lineStyle", + "value": { + "fill": "dash", + "dash": [ + 10, + 10 + ] + } + }, + { + "id": "color", + "value": { + "mode": "fixed", + "fixedColor": "red" + } + } + ] + } + ] + }, + }, local giteaChangesPanelPrototype = grafana.graphPanel.new( '', @@ -165,6 +273,7 @@ local addIssueLabelsOverrides(labels) = datasource='-- Dashboard --', reducerFunction='sum', graphMode='none', + textMode="value_and_name", colorMode='value', ) + { @@ -179,8 +288,7 @@ local addIssueLabelsOverrides(labels) = fieldConfig+: { defaults+: { color: { - fixedColor: 'blue', - mode: 'fixed', + mode: "palette-classic" }, }, }, @@ -194,9 +302,11 @@ local addIssueLabelsOverrides(labels) = datasource='-- Dashboard --', reducerFunction='sum', graphMode='none', + textMode="value_and_name", colorMode='value', ) + { + title: "Issues by repository", targets+: [ { panelId: 12, // id of giteaChangesPanel @@ -208,8 +318,7 @@ local addIssueLabelsOverrides(labels) = fieldConfig+: { defaults+: { color: { - fixedColor: 'blue', - mode: 'fixed', + mode: "palette-classic" }, }, }, @@ -224,10 +333,12 @@ local addIssueLabelsOverrides(labels) = datasource='-- Dashboard --', reducerFunction='sum', graphMode='none', + textMode="value_and_name", colorMode='value', ) + addIssueLabelsOverrides($._config.issueLabels) + { + title: "Issues by labels", targets+: [ { panelId: 14, // id of giteaChangesPanel @@ -239,8 +350,7 @@ local addIssueLabelsOverrides(labels) = fieldConfig+: { defaults+: { color: { - fixedColor: 'blue', - mode: 'fixed', + mode: "palette-classic" }, }, }, From 1dcc1419ea6f331a8db2c5c9b50d31fae3c3da77 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Tue, 14 Dec 2021 15:09:23 +0300 Subject: [PATCH 10/22] gitea-mixin: make fmt --- .../gitea-mixin/dashboards/overview.libsonnet | 538 +++++++++--------- 1 file changed, 274 insertions(+), 264 deletions(-) diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index b9344327ebc0..8a09ae50e603 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -1,163 +1,167 @@ local grafana = import 'github.com/grafana/grafonnet-lib/grafonnet/grafana.libsonnet'; local prometheus = grafana.prometheus; - -local addIssueLabelsOverrides(labels) = -{ - fieldConfig+: { - overrides+: [ - { - "matcher": { - "id": "byRegexp", - "options": label.label - }, - "properties": [ - { - "id": "color", - "value": { - "fixedColor": label.color, - "mode": "fixed" - } - } - ] - } - for label in labels - ] +local addIssueLabelsOverrides(labels) = + { + fieldConfig+: { + overrides+: [ + { + matcher: { + id: 'byRegexp', + options: label.label, + }, + properties: [ + { + id: 'color', + value: { + fixedColor: label.color, + mode: 'fixed', + }, + }, + ], } -}; + for label in labels + ], + }, + }; { grafanaDashboards+:: { local giteaSelector = 'job="$job", instance="$instance"', - local giteaStatsPanel = grafana.statPanel.new( - 'Gitea stats', - datasource='$datasource', - reducerFunction='last', - graphMode='none', - colorMode='value', - ) - .addTargets( - [ - prometheus.target(expr='%s{%s}' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=10) - for metric in $._config.giteaStatMetrics - ] - ) - + { - fieldConfig+: { - defaults+: { - color: { - fixedColor: 'blue', - mode: 'fixed', - }, - }, - }, - }, + local giteaStatsPanel = + grafana.statPanel.new( + 'Gitea stats', + datasource='$datasource', + reducerFunction='last', + graphMode='none', + colorMode='value', + ) + .addTargets( + [ + prometheus.target(expr='%s{%s}' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=10) + for metric in $._config.giteaStatMetrics + ] + ) + + { + fieldConfig+: { + defaults+: { + color: { + fixedColor: 'blue', + mode: 'fixed', + }, + }, + }, + }, - local giteaUptimePanel = grafana.statPanel.new( - 'Uptime', - datasource='$datasource', - reducerFunction='last', - graphMode='area', - colorMode='value', - ) - .addTarget(prometheus.target(expr='time()-process_start_time_seconds{%s}' % giteaSelector, intervalFactor=1)) - + { - fieldConfig+: { - defaults+: { - color: { - fixedColor: 'blue', - mode: 'fixed', - }, - unit: 's', - }, - }, - }, + local giteaUptimePanel = + grafana.statPanel.new( + 'Uptime', + datasource='$datasource', + reducerFunction='last', + graphMode='area', + colorMode='value', + ) + .addTarget(prometheus.target(expr='time()-process_start_time_seconds{%s}' % giteaSelector, intervalFactor=1)) + + { + fieldConfig+: { + defaults+: { + color: { + fixedColor: 'blue', + mode: 'fixed', + }, + unit: 's', + }, + }, + }, - local giteaMemoryPanel = grafana.graphPanel.new( - 'Memory usage', - datasource='$datasource') + local giteaMemoryPanel = + grafana.graphPanel.new( + 'Memory usage', + datasource='$datasource' + ) .addTarget(prometheus.target(expr='process_resident_memory_bytes{%s}' % giteaSelector, intervalFactor=2)) + { - type: "timeseries", + type: 'timeseries', options+: { tooltip: { - mode: "multi" + mode: 'multi', }, legend+: { - displayMode: "hidden" + displayMode: 'hidden', }, }, fieldConfig+: { defaults+: { custom+: { - lineInterpolation: "smooth", + lineInterpolation: 'smooth', fillOpacity: 15, }, color: { fixedColor: 'green', mode: 'fixed', - }, - unit: "decbytes" + }, + unit: 'decbytes', }, }, }, - local giteaCpuPanel = grafana.graphPanel.new( - 'CPU usage', - datasource='$datasource' + local giteaCpuPanel = + grafana.graphPanel.new( + 'CPU usage', + datasource='$datasource' ) .addTarget(prometheus.target(expr='rate(process_cpu_seconds_total{%s}[$__rate_interval])*100' % giteaSelector, intervalFactor=2)) + { - type: "timeseries", + type: 'timeseries', options+: { tooltip: { - mode: "multi" + mode: 'multi', }, legend+: { - displayMode: "hidden" + displayMode: 'hidden', }, }, fieldConfig+: { defaults+: { custom+: { - lineInterpolation: "smooth", - gradientMode: "scheme", + lineInterpolation: 'smooth', + gradientMode: 'scheme', fillOpacity: 15, axisSoftMin: 0, - axisSoftMax: 0 + axisSoftMax: 0, }, color: { - //mode: "continuous-BlYlRd" // from blue to red (100%) - "mode": "continuous-GrYlRd" + mode: 'continuous-GrYlRd', // from green to red (100%) }, - unit: "percent" + unit: 'percent', }, overrides: [ { - "matcher": { - "id": "byRegexp", - "options": ".+" + matcher: { + id: 'byRegexp', + options: '.+', }, - "properties": [ + properties: [ { - "id": "max", - "value": 100 + id: 'max', + value: 100, }, { - "id": "min", - "value": 0 - } - ] - } - ] + id: 'min', + value: 0, + }, + ], + }, + ], }, }, - local giteaFileDescriptorsPanel = grafana.graphPanel.new( - 'File descriptors usage', - datasource='$datasource', + local giteaFileDescriptorsPanel = + grafana.graphPanel.new( + 'File descriptors usage', + datasource='$datasource', ) .addTarget(prometheus.target(expr='process_open_fds{%s}' % giteaSelector, intervalFactor=2)) .addTarget(prometheus.target(expr='process_max_fds{%s}' % giteaSelector, intervalFactor=2)) @@ -170,96 +174,98 @@ local addIssueLabelsOverrides(labels) = }, ) + { - type: "timeseries", - options+: { - tooltip: { - mode: "multi" - }, - legend+: { - displayMode: "hidden" - }, + type: 'timeseries', + options+: { + tooltip: { + mode: 'multi', + }, + legend+: { + displayMode: 'hidden', + }, + }, + fieldConfig+: { + defaults+: { + custom+: { + lineInterpolation: 'smooth', + gradientMode: 'scheme', + fillOpacity: 0, + }, + color: { + fixedColor: 'green', + mode: 'fixed', + }, + unit: '', + }, + overrides: [ + { + matcher: { + id: 'byFrameRefID', + options: 'B', }, - fieldConfig+: { - defaults+: { - custom+: { - lineInterpolation: "smooth", - gradientMode: "scheme", - fillOpacity: 0, + properties: [ + { + id: 'custom.lineStyle', + value: { + fill: 'dash', + dash: [ + 10, + 10, + ], }, - color: { - fixedColor: 'green', - mode: 'fixed', - }, - unit: "" }, - "overrides": [ - { - "matcher": { - "id": "byFrameRefID", - "options": "B" - }, - "properties": [ - { - "id": "custom.lineStyle", - "value": { - "fill": "dash", - "dash": [ - 10, - 10 - ] - } - }, - { - "id": "color", - "value": { - "mode": "fixed", - "fixedColor": "red" - } - } - ] - } - ] - }, + { + id: 'color', + value: { + mode: 'fixed', + fixedColor: 'red', + }, + }, + ], }, - - local giteaChangesPanelPrototype = grafana.graphPanel.new( - '', - datasource='$datasource', - interval="$agg_interval", - maxDataPoints=10000, - ) - + { - type: "timeseries", - options+: { - tooltip: { - mode: "multi" - }, - legend+: { - calcs+: [ - "sum" ], }, }, - fieldConfig+: { - defaults+: { - noValue: "0", - custom+: { - drawStyle: "bars", - barAlignment: -1, - fillOpacity: 50, - gradientMode: "hue", - pointSize: 1, - lineWidth: 0, - stacking: { - group: "A", - mode: "normal" + + local giteaChangesPanelPrototype = + grafana.graphPanel.new( + '', + datasource='$datasource', + interval='$agg_interval', + maxDataPoints=10000, + ) + + { + type: 'timeseries', + options+: { + tooltip: { + mode: 'multi', + }, + legend+: { + calcs+: [ + 'sum', + ], + }, + }, + fieldConfig+: { + defaults+: { + noValue: '0', + custom+: { + drawStyle: 'bars', + barAlignment: -1, + fillOpacity: 50, + gradientMode: 'hue', + pointSize: 1, + lineWidth: 0, + stacking: { + group: 'A', + mode: 'normal', + }, }, }, - } + }, }, - }, - local giteaChangesPanelAll = giteaChangesPanelPrototype + local giteaChangesPanelAll = + giteaChangesPanelPrototype .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__interval]) > 0' % [giteaSelector], legendFormat='Restarts', intervalFactor=1)) .addTargets( [ @@ -269,92 +275,96 @@ local addIssueLabelsOverrides(labels) = ), local giteaChangesPanelTotal = grafana.statPanel.new( - '', - datasource='-- Dashboard --', - reducerFunction='sum', - graphMode='none', - textMode="value_and_name", - colorMode='value', - ) - + { - targets+: [ - { - panelId: 10, // id of giteaChangesPanel - refId: "A" - }, - ], - } - + { - fieldConfig+: { - defaults+: { - color: { - mode: "palette-classic" - }, - }, - }, - }, + '', + datasource='-- Dashboard --', + reducerFunction='sum', + graphMode='none', + textMode='value_and_name', + colorMode='value', + ) + + { + targets+: [ + { + panelId: 10, // id of giteaChangesPanel + refId: 'A', + }, + ], + } + + { + fieldConfig+: { + defaults+: { + color: { + mode: 'palette-classic', + }, + }, + }, + }, - local giteaChangesByRepositories = giteaChangesPanelPrototype + local giteaChangesByRepositories = + giteaChangesPanelPrototype .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_repository{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ repository }}', intervalFactor=1)), - local giteaChangesByRepositoriesTotal = grafana.statPanel.new( - '', - datasource='-- Dashboard --', - reducerFunction='sum', - graphMode='none', - textMode="value_and_name", - colorMode='value', - ) - + { - title: "Issues by repository", - targets+: [ - { - panelId: 12, // id of giteaChangesPanel - refId: "A" - }, - ], - } - + { - fieldConfig+: { - defaults+: { - color: { - mode: "palette-classic" - }, - }, - }, - }, + local giteaChangesByRepositoriesTotal = + grafana.statPanel.new( + '', + datasource='-- Dashboard --', + reducerFunction='sum', + graphMode='none', + textMode='value_and_name', + colorMode='value', + ) + + { + title: 'Issues by repository', + targets+: [ + { + panelId: 12, // id of giteaChangesPanel + refId: 'A', + }, + ], + } + + { + fieldConfig+: { + defaults+: { + color: { + mode: 'palette-classic', + }, + }, + }, + }, - local giteaChangesByLabel = giteaChangesPanelPrototype + local giteaChangesByLabel = + giteaChangesPanelPrototype .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_label{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ label }}', intervalFactor=1)) + addIssueLabelsOverrides($._config.issueLabels), - local giteaChangesByLabelTotal = grafana.statPanel.new( - '', - datasource='-- Dashboard --', - reducerFunction='sum', - graphMode='none', - textMode="value_and_name", - colorMode='value', - ) - + addIssueLabelsOverrides($._config.issueLabels) - + { - title: "Issues by labels", - targets+: [ - { - panelId: 14, // id of giteaChangesPanel - refId: "A" - }, - ], - } - + { - fieldConfig+: { - defaults+: { - color: { - mode: "palette-classic" - }, - }, - }, - }, + local giteaChangesByLabelTotal = + grafana.statPanel.new( + '', + datasource='-- Dashboard --', + reducerFunction='sum', + graphMode='none', + textMode='value_and_name', + colorMode='value', + ) + + addIssueLabelsOverrides($._config.issueLabels) + + { + title: 'Issues by labels', + targets+: [ + { + panelId: 14, // id of giteaChangesPanel + refId: 'A', + }, + ], + } + + { + fieldConfig+: { + defaults+: { + color: { + mode: 'palette-classic', + }, + }, + }, + }, 'gitea-overview.json': grafana.dashboard.new( @@ -407,7 +417,7 @@ local addIssueLabelsOverrides(labels) = type: 'query', }, ) - .addTemplate( + .addTemplate( { hide: 0, label: 'aggregation interval', @@ -488,8 +498,8 @@ local addIssueLabelsOverrides(labels) = h: 8, } ) - .addPanel( // id 10 - giteaChangesPanelAll, + .addPanel( // id 10 + giteaChangesPanelAll, gridPos={ x: 6, y: 12, @@ -507,7 +517,7 @@ local addIssueLabelsOverrides(labels) = } ) .addPanel( - giteaChangesByRepositories, // id 12 + giteaChangesByRepositories, // id 12 gridPos={ x: 6, y: 20, @@ -524,7 +534,7 @@ local addIssueLabelsOverrides(labels) = h: 8, } ) - .addPanel( // id 14 + .addPanel( // id 14 giteaChangesByLabel, gridPos={ x: 6, From dc51d8f59a90b727aacfda1d47720554dfc6b949 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Tue, 14 Dec 2021 15:09:42 +0300 Subject: [PATCH 11/22] gitea-mixin: add .PHONE in Makefile --- contrib/gitea-mixin/Makefile | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/contrib/gitea-mixin/Makefile b/contrib/gitea-mixin/Makefile index 72eea0ca8da7..429dfc4686f7 100644 --- a/contrib/gitea-mixin/Makefile +++ b/contrib/gitea-mixin/Makefile @@ -1,16 +1,20 @@ JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 1 --string-style s --comment-style s -default: vendor build dashboards_out +.PHONY: all +all: build dashboards_out -all: fmt build - -vendor: +vendor: jsonnetfile.json jb install +.PHONY: build +build: vendor + +.PHONY: fmt fmt: find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ xargs -n 1 -- $(JSONNET_FMT) -i +.PHONY: lint lint: build find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ while read f; do \ @@ -22,4 +26,6 @@ dashboards_out: mixin.libsonnet config.libsonnet $(wildcard dashboards/*) @mkdir -p dashboards_out jsonnet -J vendor -m dashboards_out lib/dashboards.jsonnet -build: vendor +.PHONY: clean +clean: + rm -rf dashboards_out From 7739dcbf7e65291d0e974de210a9dce67edcef03 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Tue, 14 Dec 2021 16:00:53 +0300 Subject: [PATCH 12/22] gitea-mixin: add time configration --- contrib/gitea-mixin/config.libsonnet | 4 ++++ contrib/gitea-mixin/dashboards/overview.libsonnet | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/contrib/gitea-mixin/config.libsonnet b/contrib/gitea-mixin/config.libsonnet index 68510f5b2089..a65cf22955e7 100644 --- a/contrib/gitea-mixin/config.libsonnet +++ b/contrib/gitea-mixin/config.libsonnet @@ -3,6 +3,10 @@ local c = self, dashboardNamePrefix: 'Gitea', dashboardTags: ['gitea'], + dashboardPeriod: 'now-1h', + dashboardTimezone: 'utc', + dashboardRefresh: '1m', + // add or remove metrics from dashboard giteaStatMetrics: [ diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index 8a09ae50e603..155052d19e4d 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -369,11 +369,11 @@ local addIssueLabelsOverrides(labels) = 'gitea-overview.json': grafana.dashboard.new( '%s Overview' % $._config.dashboardNamePrefix, - time_from='now-1h', + time_from='%s' % $._config.dashboardPeriod, editable=false, tags=($._config.dashboardTags), - timezone='utc', - refresh='1m', + timezone='%s' % $._config.dashboardTimezone, + refresh='%s' % $._config.dashboardRefresh, graphTooltip='shared_crosshair', uid='gitea-overview' ) From 15c17ac771055c12b4bd807ca275c41b5af85afc Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Tue, 14 Dec 2021 16:11:06 +0300 Subject: [PATCH 13/22] gitea-mixin: make fmt and collapse addPanel grid --- contrib/gitea-mixin/config.libsonnet | 30 +-- .../gitea-mixin/dashboards/overview.libsonnet | 178 ++++-------------- 2 files changed, 54 insertions(+), 154 deletions(-) diff --git a/contrib/gitea-mixin/config.libsonnet b/contrib/gitea-mixin/config.libsonnet index a65cf22955e7..77c000fe846b 100644 --- a/contrib/gitea-mixin/config.libsonnet +++ b/contrib/gitea-mixin/config.libsonnet @@ -47,32 +47,32 @@ description: 'Comments', }, ], - //set this for using label colors on graphs - issueLabels: [ + //set this for using label colors on graphs + issueLabels: [ { - label: "bug", - color: "#ee0701" + label: 'bug', + color: '#ee0701', }, { - label: "duplicate", - color: "#cccccc" + label: 'duplicate', + color: '#cccccc', }, { - label: "invalid", - color: "#e6e6e6" + label: 'invalid', + color: '#e6e6e6', }, { - label: "enhancement", - color: "#84b6eb" + label: 'enhancement', + color: '#84b6eb', }, { - label: "help wanted", - color: "#128a0c" + label: 'help wanted', + color: '#128a0c', }, { - label: "question", - color: "#cc317c" + label: 'question', + color: '#cc317c', }, - ] + ], }, } diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index 155052d19e4d..4b9122e8a784 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -274,31 +274,32 @@ local addIssueLabelsOverrides(labels) = ] ), - local giteaChangesPanelTotal = grafana.statPanel.new( - '', - datasource='-- Dashboard --', - reducerFunction='sum', - graphMode='none', - textMode='value_and_name', - colorMode='value', - ) - + { - targets+: [ - { - panelId: 10, // id of giteaChangesPanel - refId: 'A', - }, - ], - } - + { - fieldConfig+: { - defaults+: { - color: { - mode: 'palette-classic', - }, - }, - }, - }, + local giteaChangesPanelTotal = + grafana.statPanel.new( + '', + datasource='-- Dashboard --', + reducerFunction='sum', + graphMode='none', + textMode='value_and_name', + colorMode='value', + ) + + { + targets+: [ + { + panelId: 10, // id of giteaChangesPanel + refId: 'A', + }, + ], + } + + { + fieldConfig+: { + defaults+: { + color: { + mode: 'palette-classic', + }, + }, + }, + }, local giteaChangesByRepositories = giteaChangesPanelPrototype @@ -429,120 +430,19 @@ local addIssueLabelsOverrides(labels) = type: 'interval', }, ) - .addPanel( - grafana.row.new(title='General'), gridPos={ - x: 0, - y: 0, - w: 0, - h: 0, - }, - ) - .addPanel( - giteaStatsPanel, gridPos={ - x: 0, - y: 0, - w: 16, - h: 4, - } - ) - .addPanel( - giteaUptimePanel, gridPos={ - x: 16, - y: 0, - w: 8, - h: 4, - } - ) - .addPanel( - giteaMemoryPanel, gridPos={ - x: 0, - y: 4, - w: 8, - h: 6, - } - ) - .addPanel( - giteaCpuPanel, gridPos={ - x: 8, - y: 4, - w: 8, - h: 6, - } - ) - .addPanel( - giteaFileDescriptorsPanel, gridPos={ - x: 16, - y: 4, - w: 8, - h: 6, - } - ) - .addPanel( - grafana.row.new( - title='Changes', - collapse=false - ), - gridPos={ - x: 0, - y: 10, - w: 24, - h: 8, - } - ) - .addPanel( - giteaChangesPanelTotal, - gridPos={ - x: 0, - y: 12, - w: 6, - h: 8, - } - ) - .addPanel( // id 10 - giteaChangesPanelAll, - gridPos={ - x: 6, - y: 12, - w: 18, - h: 8, - } - ) - .addPanel( // by repositories split - giteaChangesByRepositoriesTotal, - gridPos={ - x: 0, - y: 20, - w: 6, - h: 8, - } - ) - .addPanel( - giteaChangesByRepositories, // id 12 - gridPos={ - x: 6, - y: 20, - w: 18, - h: 8, - } - ) - .addPanel( // by labels split - giteaChangesByLabelTotal, - gridPos={ - x: 0, - y: 28, - w: 6, - h: 8, - } - ) - .addPanel( // id 14 - giteaChangesByLabel, - gridPos={ - x: 6, - y: 28, - w: 18, - h: 8, - } - ), + .addPanel(grafana.row.new(title='General'), gridPos={ x: 0, y: 0, w: 0, h: 0 },) + .addPanel(giteaStatsPanel, gridPos={ x: 0, y: 0, w: 16, h: 4 }) + .addPanel(giteaUptimePanel, gridPos={ x: 16, y: 0, w: 8, h: 4 }) + .addPanel(giteaMemoryPanel, gridPos={ x: 0, y: 4, w: 8, h: 6 }) + .addPanel(giteaCpuPanel, gridPos={ x: 8, y: 4, w: 8, h: 6 }) + .addPanel(giteaFileDescriptorsPanel, gridPos={ x: 16, y: 4, w: 8, h: 6 }) + .addPanel(grafana.row.new(title='Changes', collapse=false), gridPos={ x: 0, y: 10, w: 24, h: 8 }) + .addPanel(giteaChangesPanelTotal, gridPos={ x: 0, y: 12, w: 6, h: 8 }) + .addPanel(giteaChangesPanelAll, gridPos={ x: 6, y: 12, w: 18, h: 8 }) // id 10 + .addPanel(giteaChangesByRepositoriesTotal, gridPos={ x: 0, y: 20, w: 6, h: 8 }) // by repositories split + .addPanel(giteaChangesByRepositories, gridPos={ x: 6, y: 20, w: 18, h: 8 }) // id 12 + .addPanel(giteaChangesByLabelTotal, gridPos={ x: 0, y: 28, w: 6, h: 8 }) + .addPanel(giteaChangesByLabel, gridPos={ x: 6, y: 28, w: 18, h: 8 }), // id 14 }, } From c8b305f349dc39d277a3d35b8deee43f5f32f1b9 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Wed, 15 Dec 2021 14:09:16 +0300 Subject: [PATCH 14/22] gitea-mixin: add static ids for shared panels --- .../gitea-mixin/dashboards/overview.libsonnet | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index 4b9122e8a784..479fcd4c957d 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -272,7 +272,7 @@ local addIssueLabelsOverrides(labels) = prometheus.target(expr='floor(increase(%s{%s}[$__interval])) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) for metric in $._config.giteaStatMetrics ] - ), + ) + { id: 200 }, // some unique number, beyond the maximum number of panels in the dashboard, local giteaChangesPanelTotal = grafana.statPanel.new( @@ -286,7 +286,7 @@ local addIssueLabelsOverrides(labels) = + { targets+: [ { - panelId: 10, // id of giteaChangesPanel + panelId: giteaChangesPanelAll.id, refId: 'A', }, ], @@ -303,7 +303,8 @@ local addIssueLabelsOverrides(labels) = local giteaChangesByRepositories = giteaChangesPanelPrototype - .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_repository{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ repository }}', intervalFactor=1)), + .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_repository{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ repository }}', intervalFactor=1)) + + { id: 210 }, // some unique number, beyond the maximum number of panels in the dashboard, local giteaChangesByRepositoriesTotal = grafana.statPanel.new( @@ -318,7 +319,7 @@ local addIssueLabelsOverrides(labels) = title: 'Issues by repository', targets+: [ { - panelId: 12, // id of giteaChangesPanel + panelId: giteaChangesByRepositories.id, refId: 'A', }, ], @@ -336,7 +337,8 @@ local addIssueLabelsOverrides(labels) = local giteaChangesByLabel = giteaChangesPanelPrototype .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_label{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ label }}', intervalFactor=1)) - + addIssueLabelsOverrides($._config.issueLabels), + + addIssueLabelsOverrides($._config.issueLabels) + + { id: 220 }, // some unique number, beyond the maximum number of panels in the dashboard, local giteaChangesByLabelTotal = grafana.statPanel.new( @@ -352,7 +354,7 @@ local addIssueLabelsOverrides(labels) = title: 'Issues by labels', targets+: [ { - panelId: 14, // id of giteaChangesPanel + panelId: giteaChangesByLabel.id, refId: 'A', }, ], @@ -438,11 +440,17 @@ local addIssueLabelsOverrides(labels) = .addPanel(giteaFileDescriptorsPanel, gridPos={ x: 16, y: 4, w: 8, h: 6 }) .addPanel(grafana.row.new(title='Changes', collapse=false), gridPos={ x: 0, y: 10, w: 24, h: 8 }) .addPanel(giteaChangesPanelTotal, gridPos={ x: 0, y: 12, w: 6, h: 8 }) - .addPanel(giteaChangesPanelAll, gridPos={ x: 6, y: 12, w: 18, h: 8 }) // id 10 - .addPanel(giteaChangesByRepositoriesTotal, gridPos={ x: 0, y: 20, w: 6, h: 8 }) // by repositories split - .addPanel(giteaChangesByRepositories, gridPos={ x: 6, y: 20, w: 18, h: 8 }) // id 12 + .addPanel(giteaChangesByRepositoriesTotal, gridPos={ x: 0, y: 20, w: 6, h: 8 }) .addPanel(giteaChangesByLabelTotal, gridPos={ x: 0, y: 28, w: 6, h: 8 }) - .addPanel(giteaChangesByLabel, gridPos={ x: 6, y: 28, w: 18, h: 8 }), // id 14 + + + // use patching instead of .addPanel() to keep static ids + { + panels+: [ + giteaChangesPanelAll + { gridPos: { x: 6, y: 12, w: 18, h: 8 }}, + giteaChangesByLabel + {gridPos: { x: 6, y: 28, w: 18, h: 8 }}, + giteaChangesByRepositories + { gridPos: { x: 6, y: 20, w: 18, h: 8 }}, + ] + } }, } From 74c4a8d18f895969e9a0d6cf4841fbc32b9533a0 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Wed, 15 Dec 2021 15:46:12 +0300 Subject: [PATCH 15/22] gitea-mixin: add flags showIssuesByRepository, showIssuesByLabel to show/hide corresponding panels --- contrib/gitea-mixin/config.libsonnet | 5 +++ .../gitea-mixin/dashboards/overview.libsonnet | 36 +++++++++++-------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/contrib/gitea-mixin/config.libsonnet b/contrib/gitea-mixin/config.libsonnet index 77c000fe846b..47c91717bac9 100644 --- a/contrib/gitea-mixin/config.libsonnet +++ b/contrib/gitea-mixin/config.libsonnet @@ -7,6 +7,11 @@ dashboardTimezone: 'utc', dashboardRefresh: '1m', + // please see https://docs.gitea.io/en-us/config-cheat-sheet/#metrics-metrics + // Show issue by repository metrics with format gitea_issues_by_repository{repository="org/repo"} 5. Requires Gitea 1.16.0 with ENABLED_ISSUE_BY_REPOSITORY set to true. + showIssuesByRepository: true, + // Show graphs for issue by label metrics with format gitea_issues_by_label{label="bug"} 2. Requires Gitea 1.16.0 with ENABLED_ISSUE_BY_LABEL set to true. + showIssuesByLabel: false, // add or remove metrics from dashboard giteaStatMetrics: [ diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index 479fcd4c957d..3117259aa21d 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -272,7 +272,7 @@ local addIssueLabelsOverrides(labels) = prometheus.target(expr='floor(increase(%s{%s}[$__interval])) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) for metric in $._config.giteaStatMetrics ] - ) + { id: 200 }, // some unique number, beyond the maximum number of panels in the dashboard, + ) + { id: 200 }, // some unique number, beyond the maximum number of panels in the dashboard, local giteaChangesPanelTotal = grafana.statPanel.new( @@ -304,7 +304,7 @@ local addIssueLabelsOverrides(labels) = local giteaChangesByRepositories = giteaChangesPanelPrototype .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_repository{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ repository }}', intervalFactor=1)) - + { id: 210 }, // some unique number, beyond the maximum number of panels in the dashboard, + + { id: 210 }, // some unique number, beyond the maximum number of panels in the dashboard, local giteaChangesByRepositoriesTotal = grafana.statPanel.new( @@ -316,6 +316,7 @@ local addIssueLabelsOverrides(labels) = colorMode='value', ) + { + id: 211, title: 'Issues by repository', targets+: [ { @@ -338,7 +339,7 @@ local addIssueLabelsOverrides(labels) = giteaChangesPanelPrototype .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_label{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ label }}', intervalFactor=1)) + addIssueLabelsOverrides($._config.issueLabels) - + { id: 220 }, // some unique number, beyond the maximum number of panels in the dashboard, + + { id: 220 }, // some unique number, beyond the maximum number of panels in the dashboard, local giteaChangesByLabelTotal = grafana.statPanel.new( @@ -351,6 +352,7 @@ local addIssueLabelsOverrides(labels) = ) + addIssueLabelsOverrides($._config.issueLabels) + { + id: 221, title: 'Issues by labels', targets+: [ { @@ -440,17 +442,23 @@ local addIssueLabelsOverrides(labels) = .addPanel(giteaFileDescriptorsPanel, gridPos={ x: 16, y: 4, w: 8, h: 6 }) .addPanel(grafana.row.new(title='Changes', collapse=false), gridPos={ x: 0, y: 10, w: 24, h: 8 }) .addPanel(giteaChangesPanelTotal, gridPos={ x: 0, y: 12, w: 6, h: 8 }) - .addPanel(giteaChangesByRepositoriesTotal, gridPos={ x: 0, y: 20, w: 6, h: 8 }) - .addPanel(giteaChangesByLabelTotal, gridPos={ x: 0, y: 28, w: 6, h: 8 }) - + - // use patching instead of .addPanel() to keep static ids + + // use patching instead of .addPanel() to keep static ids { - panels+: [ - giteaChangesPanelAll + { gridPos: { x: 6, y: 12, w: 18, h: 8 }}, - giteaChangesByLabel + {gridPos: { x: 6, y: 28, w: 18, h: 8 }}, - giteaChangesByRepositories + { gridPos: { x: 6, y: 20, w: 18, h: 8 }}, - ] - } - + panels+: std.flattenArrays([ + [ + giteaChangesPanelAll { gridPos: { x: 6, y: 12, w: 18, h: 8 } }, + ], + if $._config.showIssuesByRepository then + [ + giteaChangesByRepositoriesTotal { gridPos: { x: 0, y: 20, w: 6, h: 8 } }, + giteaChangesByRepositories { gridPos: { x: 6, y: 20, w: 18, h: 8 } }, + ] else [], + if $._config.showIssuesByLabel then + [ + giteaChangesByLabelTotal { gridPos: { x: 0, y: 28, w: 6, h: 8 } }, + giteaChangesByLabel { gridPos: { x: 6, y: 28, w: 18, h: 8 } }, + ] else [], + ]), + }, }, } From 3b32e1965a4d70cada4cc1dba1591d8cd62413c6 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Wed, 15 Dec 2021 16:34:53 +0300 Subject: [PATCH 16/22] gitea-mixin: update aggregation interval --- contrib/gitea-mixin/dashboards/overview.libsonnet | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index 3117259aa21d..a57ff2cf8228 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -427,7 +427,6 @@ local addIssueLabelsOverrides(labels) = hide: 0, label: 'aggregation interval', name: 'agg_interval', - current: 'auto', auto_min: '1m', auto: true, query: '1m,10m,1h,1d,7d', From e5496616be1cbec6ec4e194c730c9107d2ddfff6 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Wed, 15 Dec 2021 16:52:59 +0300 Subject: [PATCH 17/22] gitea-mixin: update defaults --- contrib/gitea-mixin/config.libsonnet | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/contrib/gitea-mixin/config.libsonnet b/contrib/gitea-mixin/config.libsonnet index 47c91717bac9..41b423911787 100644 --- a/contrib/gitea-mixin/config.libsonnet +++ b/contrib/gitea-mixin/config.libsonnet @@ -8,10 +8,12 @@ dashboardRefresh: '1m', // please see https://docs.gitea.io/en-us/config-cheat-sheet/#metrics-metrics - // Show issue by repository metrics with format gitea_issues_by_repository{repository="org/repo"} 5. Requires Gitea 1.16.0 with ENABLED_ISSUE_BY_REPOSITORY set to true. + // Show issue by repository metrics with format gitea_issues_by_repository{repository="org/repo"} 5. + // Requires Gitea 1.16.0 with ENABLED_ISSUE_BY_REPOSITORY set to true. showIssuesByRepository: true, - // Show graphs for issue by label metrics with format gitea_issues_by_label{label="bug"} 2. Requires Gitea 1.16.0 with ENABLED_ISSUE_BY_LABEL set to true. - showIssuesByLabel: false, + // Show graphs for issue by label metrics with format gitea_issues_by_label{label="bug"} 2. + // Requires Gitea 1.16.0 with ENABLED_ISSUE_BY_LABEL set to true. + showIssuesByLabel: true, // add or remove metrics from dashboard giteaStatMetrics: [ From 493b4d6646ba6cdfff1d63bd82873e2309a0b7cb Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Wed, 15 Dec 2021 17:31:57 +0300 Subject: [PATCH 18/22] gitea-mixin: update panel names --- contrib/gitea-mixin/dashboards/overview.libsonnet | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-mixin/dashboards/overview.libsonnet index a57ff2cf8228..2c6cde993e62 100644 --- a/contrib/gitea-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-mixin/dashboards/overview.libsonnet @@ -34,7 +34,7 @@ local addIssueLabelsOverrides(labels) = grafana.statPanel.new( 'Gitea stats', datasource='$datasource', - reducerFunction='last', + reducerFunction='lastNotNull', graphMode='none', colorMode='value', ) @@ -276,7 +276,7 @@ local addIssueLabelsOverrides(labels) = local giteaChangesPanelTotal = grafana.statPanel.new( - '', + 'Changes', datasource='-- Dashboard --', reducerFunction='sum', graphMode='none', @@ -308,7 +308,7 @@ local addIssueLabelsOverrides(labels) = local giteaChangesByRepositoriesTotal = grafana.statPanel.new( - '', + 'Issues by repository', datasource='-- Dashboard --', reducerFunction='sum', graphMode='none', @@ -317,7 +317,6 @@ local addIssueLabelsOverrides(labels) = ) + { id: 211, - title: 'Issues by repository', targets+: [ { panelId: giteaChangesByRepositories.id, @@ -343,7 +342,7 @@ local addIssueLabelsOverrides(labels) = local giteaChangesByLabelTotal = grafana.statPanel.new( - '', + 'Issues by labels', datasource='-- Dashboard --', reducerFunction='sum', graphMode='none', @@ -353,7 +352,6 @@ local addIssueLabelsOverrides(labels) = + addIssueLabelsOverrides($._config.issueLabels) + { id: 221, - title: 'Issues by labels', targets+: [ { panelId: giteaChangesByLabel.id, From 8d4406880cdf2fe1719d300a2358fd30bfeaf103 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Wed, 15 Dec 2021 17:32:57 +0300 Subject: [PATCH 19/22] rename dir to gitea-monitoring-mixin --- contrib/{gitea-mixin => gitea-monitoring-mixin}/.gitignore | 0 contrib/{gitea-mixin => gitea-monitoring-mixin}/Makefile | 0 contrib/{gitea-mixin => gitea-monitoring-mixin}/README.md | 0 contrib/{gitea-mixin => gitea-monitoring-mixin}/config.libsonnet | 0 .../dashboards/dashboards.libsonnet | 0 .../dashboards/overview.libsonnet | 0 contrib/{gitea-mixin => gitea-monitoring-mixin}/jsonnetfile.json | 0 .../{gitea-mixin => gitea-monitoring-mixin}/jsonnetfile.lock.json | 0 .../{gitea-mixin => gitea-monitoring-mixin}/lib/alerts.jsonnet | 0 .../lib/dashboards.jsonnet | 0 contrib/{gitea-mixin => gitea-monitoring-mixin}/lib/rules.jsonnet | 0 contrib/{gitea-mixin => gitea-monitoring-mixin}/mixin.libsonnet | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/.gitignore (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/Makefile (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/README.md (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/config.libsonnet (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/dashboards/dashboards.libsonnet (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/dashboards/overview.libsonnet (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/jsonnetfile.json (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/jsonnetfile.lock.json (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/lib/alerts.jsonnet (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/lib/dashboards.jsonnet (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/lib/rules.jsonnet (100%) rename contrib/{gitea-mixin => gitea-monitoring-mixin}/mixin.libsonnet (100%) diff --git a/contrib/gitea-mixin/.gitignore b/contrib/gitea-monitoring-mixin/.gitignore similarity index 100% rename from contrib/gitea-mixin/.gitignore rename to contrib/gitea-monitoring-mixin/.gitignore diff --git a/contrib/gitea-mixin/Makefile b/contrib/gitea-monitoring-mixin/Makefile similarity index 100% rename from contrib/gitea-mixin/Makefile rename to contrib/gitea-monitoring-mixin/Makefile diff --git a/contrib/gitea-mixin/README.md b/contrib/gitea-monitoring-mixin/README.md similarity index 100% rename from contrib/gitea-mixin/README.md rename to contrib/gitea-monitoring-mixin/README.md diff --git a/contrib/gitea-mixin/config.libsonnet b/contrib/gitea-monitoring-mixin/config.libsonnet similarity index 100% rename from contrib/gitea-mixin/config.libsonnet rename to contrib/gitea-monitoring-mixin/config.libsonnet diff --git a/contrib/gitea-mixin/dashboards/dashboards.libsonnet b/contrib/gitea-monitoring-mixin/dashboards/dashboards.libsonnet similarity index 100% rename from contrib/gitea-mixin/dashboards/dashboards.libsonnet rename to contrib/gitea-monitoring-mixin/dashboards/dashboards.libsonnet diff --git a/contrib/gitea-mixin/dashboards/overview.libsonnet b/contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet similarity index 100% rename from contrib/gitea-mixin/dashboards/overview.libsonnet rename to contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet diff --git a/contrib/gitea-mixin/jsonnetfile.json b/contrib/gitea-monitoring-mixin/jsonnetfile.json similarity index 100% rename from contrib/gitea-mixin/jsonnetfile.json rename to contrib/gitea-monitoring-mixin/jsonnetfile.json diff --git a/contrib/gitea-mixin/jsonnetfile.lock.json b/contrib/gitea-monitoring-mixin/jsonnetfile.lock.json similarity index 100% rename from contrib/gitea-mixin/jsonnetfile.lock.json rename to contrib/gitea-monitoring-mixin/jsonnetfile.lock.json diff --git a/contrib/gitea-mixin/lib/alerts.jsonnet b/contrib/gitea-monitoring-mixin/lib/alerts.jsonnet similarity index 100% rename from contrib/gitea-mixin/lib/alerts.jsonnet rename to contrib/gitea-monitoring-mixin/lib/alerts.jsonnet diff --git a/contrib/gitea-mixin/lib/dashboards.jsonnet b/contrib/gitea-monitoring-mixin/lib/dashboards.jsonnet similarity index 100% rename from contrib/gitea-mixin/lib/dashboards.jsonnet rename to contrib/gitea-monitoring-mixin/lib/dashboards.jsonnet diff --git a/contrib/gitea-mixin/lib/rules.jsonnet b/contrib/gitea-monitoring-mixin/lib/rules.jsonnet similarity index 100% rename from contrib/gitea-mixin/lib/rules.jsonnet rename to contrib/gitea-monitoring-mixin/lib/rules.jsonnet diff --git a/contrib/gitea-mixin/mixin.libsonnet b/contrib/gitea-monitoring-mixin/mixin.libsonnet similarity index 100% rename from contrib/gitea-mixin/mixin.libsonnet rename to contrib/gitea-monitoring-mixin/mixin.libsonnet From b7b822c7c7a7be7af0b3a31178558032d5979c7e Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Wed, 15 Dec 2021 19:48:44 +0300 Subject: [PATCH 20/22] gitea-mixin: add gitea_issues_open, gitea_issues_closed metrics --- .../gitea-monitoring-mixin/config.libsonnet | 94 +++++++++++-------- .../dashboards/overview.libsonnet | 2 +- 2 files changed, 55 insertions(+), 41 deletions(-) diff --git a/contrib/gitea-monitoring-mixin/config.libsonnet b/contrib/gitea-monitoring-mixin/config.libsonnet index 41b423911787..55297949e4ab 100644 --- a/contrib/gitea-monitoring-mixin/config.libsonnet +++ b/contrib/gitea-monitoring-mixin/config.libsonnet @@ -4,56 +4,70 @@ dashboardNamePrefix: 'Gitea', dashboardTags: ['gitea'], dashboardPeriod: 'now-1h', - dashboardTimezone: 'utc', + dashboardTimezone: 'default', dashboardRefresh: '1m', // please see https://docs.gitea.io/en-us/config-cheat-sheet/#metrics-metrics - // Show issue by repository metrics with format gitea_issues_by_repository{repository="org/repo"} 5. + // Show issue by repository metrics with format gitea_issues_by_repository{repository="org/repo"} 5. // Requires Gitea 1.16.0 with ENABLED_ISSUE_BY_REPOSITORY set to true. showIssuesByRepository: true, // Show graphs for issue by label metrics with format gitea_issues_by_label{label="bug"} 2. // Requires Gitea 1.16.0 with ENABLED_ISSUE_BY_LABEL set to true. showIssuesByLabel: true, + // Requires Gitea 1.16.0. + showIssuesOpenClose: true, + // add or remove metrics from dashboard - giteaStatMetrics: [ - { - name: 'gitea_organizations', - description: 'Organizations', - }, - { - name: 'gitea_teams', - description: 'Teams', - }, - { - name: 'gitea_users', - description: 'Users', - }, - { - name: 'gitea_repositories', - description: 'Repositories', - }, - { - name: 'gitea_milestones', - description: 'Milestones', - }, - { - name: 'gitea_stars', - description: 'Stars', - }, - { - name: 'gitea_releases', - description: 'Releases', - }, - { - name: 'gitea_issues', - description: 'Issues', - }, - { - name: 'gitea_comments', - description: 'Comments', - }, - ], + giteaStatMetrics: + [ + { + name: 'gitea_organizations', + description: 'Organizations', + }, + { + name: 'gitea_teams', + description: 'Teams', + }, + { + name: 'gitea_users', + description: 'Users', + }, + { + name: 'gitea_repositories', + description: 'Repositories', + }, + { + name: 'gitea_milestones', + description: 'Milestones', + }, + { + name: 'gitea_stars', + description: 'Stars', + }, + { + name: 'gitea_releases', + description: 'Releases', + }, + ] + + + if c.showIssuesOpenClose then + [ + { + name: 'gitea_issues_open', + description: 'Issues opened', + }, + { + name: 'gitea_issues_closed', + description: 'Issues closed', + }, + ] else + [ + { + name: 'gitea_issues', + description: 'Issues', + }, + ], //set this for using label colors on graphs issueLabels: [ { diff --git a/contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet b/contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet index 2c6cde993e62..a4b8db60e5a5 100644 --- a/contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet @@ -269,7 +269,7 @@ local addIssueLabelsOverrides(labels) = .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__interval]) > 0' % [giteaSelector], legendFormat='Restarts', intervalFactor=1)) .addTargets( [ - prometheus.target(expr='floor(increase(%s{%s}[$__interval])) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) + prometheus.target(expr='floor(delta(%s{%s}[$__interval])) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) for metric in $._config.giteaStatMetrics ] ) + { id: 200 }, // some unique number, beyond the maximum number of panels in the dashboard, From 2a14ebae9513ca8ec9fc92243c6652afb3eae2c9 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Thu, 16 Dec 2021 01:11:35 +0300 Subject: [PATCH 21/22] gitea-mixin: update visible name for datasource --- contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet b/contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet index a4b8db60e5a5..3e2513c4cfca 100644 --- a/contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet +++ b/contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet @@ -387,7 +387,7 @@ local addIssueLabelsOverrides(labels) = value: 'Prometheus', }, hide: 0, - label: null, + label: 'Data Source', name: 'datasource', options: [], query: 'prometheus', From a75b139dde262496e62f7773c3d8c06d4a2b231b Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Thu, 16 Dec 2021 01:41:02 +0300 Subject: [PATCH 22/22] gitea-mixin: update README --- contrib/gitea-monitoring-mixin/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/gitea-monitoring-mixin/README.md b/contrib/gitea-monitoring-mixin/README.md index 30bd3d7e3a2b..2e11706651d6 100644 --- a/contrib/gitea-monitoring-mixin/README.md +++ b/contrib/gitea-monitoring-mixin/README.md @@ -7,8 +7,8 @@ Gitea Mixin is a set of configurable Grafana dashboards based on the metrics exp You can manually generate dashboards, but first you should install some tools: ```bash -go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb -go get github.com/google/go-jsonnet/cmd/jsonnet +go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest +go install github.com/google/go-jsonnet/cmd/jsonnet@latest # or in brew: brew install go-jsonnet ``` @@ -16,8 +16,8 @@ For linting and formatting, you would also need `mixtool` and `jsonnetfmt` insta have a working Go development environment, it's easiest to run the following: ```bash -go get github.com/monitoring-mixins/mixtool/cmd/mixtool -go get github.com/google/go-jsonnet/cmd/jsonnetfmt +go install github.com/monitoring-mixins/mixtool/cmd/mixtool@latest +go install github.com/google/go-jsonnet/cmd/jsonnetfmt@latest ``` The files in `dashboards_out` need to be imported