Skip to content

Commit 2cd1479

Browse files
v-zhuravlevlunnyzeripath
authored
Add grafana gitea-mixin (#17758)
This PR adds gitea-mixin, configurable Grafana dashboards (and potentially prometheus alerts+recording rules) based on Gitea [metrics](https://docs.gitea.io/en-us/config-cheat-sheet/#metrics-metrics). The overview dashboard is described using jsonnet and grafonnet library: https://grafana.github.io/grafonnet-lib/ Mixins help to define dashboard and alerts as code so they can be collaboratively improved by the users. ![image](https://user-images.githubusercontent.com/14870891/142862822-fe57b384-c74a-4103-8548-033e92f90751.png) __ ## Generate config files 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 # 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 files in `dashboards_out` need to be imported into your Grafana server. The exact details will be depending on your environment. Edit `config.libsonnet` (for example, list of Gitea metrics to be shown under stats can be adjusted). if required and then build JSON dashboard files for Grafana: ```bash make ``` For more about mixins, please see: https://github.com/monitoring-mixins/docs https://www.youtube.com/watch?v=GDdnL5R_l-Y* add gitea mixin * remove alerts/rules * gitea-mixin: add interval factor of 1/2 to remove duplicated change events * gitea-mixin: fix changes panel, add aggregation interval for changes panel * gitea-mixin: add totals singlestat * gitea mixin: switch change graph to timeseries type * add color overrides for issue labels * bump grafonnet version * gitea-mixin: convert graphs to timeseries * gitea-mixin: make fmt * gitea-mixin: add .PHONE in Makefile * gitea-mixin: add time configration * gitea-mixin: make fmt and collapse addPanel grid * gitea-mixin: add static ids for shared panels * gitea-mixin: add flags showIssuesByRepository, showIssuesByLabel to show/hide corresponding panels * gitea-mixin: update aggregation interval * gitea-mixin: update defaults * gitea-mixin: update panel names * rename dir to gitea-monitoring-mixin * gitea-mixin: add gitea_issues_open, gitea_issues_closed metrics * gitea-mixin: update visible name for datasource * gitea-mixin: update README Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: zeripath <[email protected]>
1 parent ff2fd08 commit 2cd1479

12 files changed

+668
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dashboards_out
2+
vendor
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 1 --string-style s --comment-style s
2+
3+
.PHONY: all
4+
all: build dashboards_out
5+
6+
vendor: jsonnetfile.json
7+
jb install
8+
9+
.PHONY: build
10+
build: vendor
11+
12+
.PHONY: fmt
13+
fmt:
14+
find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
15+
xargs -n 1 -- $(JSONNET_FMT) -i
16+
17+
.PHONY: lint
18+
lint: build
19+
find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
20+
while read f; do \
21+
$(JSONNET_FMT) "$$f" | diff -u "$$f" -; \
22+
done
23+
mixtool lint mixin.libsonnet
24+
25+
dashboards_out: mixin.libsonnet config.libsonnet $(wildcard dashboards/*)
26+
@mkdir -p dashboards_out
27+
jsonnet -J vendor -m dashboards_out lib/dashboards.jsonnet
28+
29+
.PHONY: clean
30+
clean:
31+
rm -rf dashboards_out
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Gitea Mixin
2+
3+
Gitea Mixin is a set of configurable Grafana dashboards based on the metrics exported by the Gitea built-in metrics endpoint.
4+
5+
## Generate config files
6+
7+
You can manually generate dashboards, but first you should install some tools:
8+
9+
```bash
10+
go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
11+
go install github.com/google/go-jsonnet/cmd/jsonnet@latest
12+
# or in brew: brew install go-jsonnet
13+
```
14+
15+
For linting and formatting, you would also need `mixtool` and `jsonnetfmt` installed. If you
16+
have a working Go development environment, it's easiest to run the following:
17+
18+
```bash
19+
go install github.com/monitoring-mixins/mixtool/cmd/mixtool@latest
20+
go install github.com/google/go-jsonnet/cmd/jsonnetfmt@latest
21+
```
22+
23+
The files in `dashboards_out` need to be imported
24+
into your Grafana server. The exact details will be depending on your environment.
25+
26+
Edit `config.libsonnet` if required and then build JSON dashboard files for Grafana:
27+
28+
```bash
29+
make
30+
```
31+
32+
For more advanced uses of mixins, see
33+
https://github.com/monitoring-mixins/docs.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
_config+:: {
3+
local c = self,
4+
dashboardNamePrefix: 'Gitea',
5+
dashboardTags: ['gitea'],
6+
dashboardPeriod: 'now-1h',
7+
dashboardTimezone: 'default',
8+
dashboardRefresh: '1m',
9+
10+
// please see https://docs.gitea.io/en-us/config-cheat-sheet/#metrics-metrics
11+
// Show issue by repository metrics with format gitea_issues_by_repository{repository="org/repo"} 5.
12+
// Requires Gitea 1.16.0 with ENABLED_ISSUE_BY_REPOSITORY set to true.
13+
showIssuesByRepository: true,
14+
// Show graphs for issue by label metrics with format gitea_issues_by_label{label="bug"} 2.
15+
// Requires Gitea 1.16.0 with ENABLED_ISSUE_BY_LABEL set to true.
16+
showIssuesByLabel: true,
17+
18+
// Requires Gitea 1.16.0.
19+
showIssuesOpenClose: true,
20+
21+
// add or remove metrics from dashboard
22+
giteaStatMetrics:
23+
[
24+
{
25+
name: 'gitea_organizations',
26+
description: 'Organizations',
27+
},
28+
{
29+
name: 'gitea_teams',
30+
description: 'Teams',
31+
},
32+
{
33+
name: 'gitea_users',
34+
description: 'Users',
35+
},
36+
{
37+
name: 'gitea_repositories',
38+
description: 'Repositories',
39+
},
40+
{
41+
name: 'gitea_milestones',
42+
description: 'Milestones',
43+
},
44+
{
45+
name: 'gitea_stars',
46+
description: 'Stars',
47+
},
48+
{
49+
name: 'gitea_releases',
50+
description: 'Releases',
51+
},
52+
]
53+
+
54+
if c.showIssuesOpenClose then
55+
[
56+
{
57+
name: 'gitea_issues_open',
58+
description: 'Issues opened',
59+
},
60+
{
61+
name: 'gitea_issues_closed',
62+
description: 'Issues closed',
63+
},
64+
] else
65+
[
66+
{
67+
name: 'gitea_issues',
68+
description: 'Issues',
69+
},
70+
],
71+
//set this for using label colors on graphs
72+
issueLabels: [
73+
{
74+
label: 'bug',
75+
color: '#ee0701',
76+
},
77+
{
78+
label: 'duplicate',
79+
color: '#cccccc',
80+
},
81+
{
82+
label: 'invalid',
83+
color: '#e6e6e6',
84+
},
85+
{
86+
label: 'enhancement',
87+
color: '#84b6eb',
88+
},
89+
{
90+
label: 'help wanted',
91+
color: '#128a0c',
92+
},
93+
{
94+
label: 'question',
95+
color: '#cc317c',
96+
},
97+
],
98+
},
99+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(import 'overview.libsonnet')

0 commit comments

Comments
 (0)