-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add grafana gitea-mixin #17758
Add grafana gitea-mixin #17758
Changes from 2 commits
7a32f37
9d7f1b6
8d78b7a
1246988
6f6622a
f4a07bd
e70fd58
7ccd873
55023bd
1dcc141
dc51d8f
7739dcb
15c17ac
c8b305f
74c4a8d
3b32e19
e549661
493b4d6
8d44068
b7b822c
2a14eba
a75b139
e628e20
102de09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dashboards_out | ||
vendor |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 1 --string-style s --comment-style s | ||
|
||
default: vendor build dashboards_out | ||
|
||
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 | ||
|
||
build: vendor | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Gitea Mixin | ||
|
||
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 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` 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}, | ||
], | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(import 'overview.libsonnet') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too much indentation? If libsonnet syntax does not require this, I would suggest follow 2-space indendation rule to make this much more readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, too much, it had been generated by jsonnetfmt so I made some adjustments to make sure |
||
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 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, | ||
} | ||
), | ||
|
||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"version": 1, | ||
"dependencies": [ | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/grafana/grafonnet-lib.git", | ||
"subdir": "grafonnet" | ||
} | ||
}, | ||
"version": "master" | ||
} | ||
], | ||
"legacyImports": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
std.manifestYamlDoc((import '../mixin.libsonnet').prometheusAlerts) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
local dashboards = (import '../mixin.libsonnet').grafanaDashboards; | ||
|
||
{ | ||
[name]: dashboards[name] | ||
for name in std.objectFields(dashboards) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
std.manifestYamlDoc((import '../mixin.libsonnet').prometheusRules) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(import 'dashboards/dashboards.libsonnet') + | ||
(import 'config.libsonnet') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Makefile is missing declaration of
.PHONY
targets.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, added .PHONY targets