More Related Content Similar to Grafana Dashboards as Code
Similar to Grafana Dashboards as Code (20) Grafana Dashboards as Code5. Dashboards as JSON{
…
"panels": [
{
…
"id": 2,
"legend": {
….
}
"targets": [
{
"expr": "count(kube_deployment_created) by (namespace)",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{namespace}}",
"refId": "A"
}
],
…
"title": "Number of deployment count by namespace",
…
Export
Import/Provisioning
12. Dashboards as Jsonnet
local grafana = import 'grafonnet/grafana.libsonnet';
local dashboard = grafana.dashboard;
local graphPanel = grafana.graphPanel;
local prometheus = grafana.prometheus;
local resourcePanel(resource) =
graphPanel.new(
title='Number of %s count by namespace' % resource,
datasource='prometheus',
).addTarget(
prometheus.target(
expr='count(kube_%s_created) by (namespace)' % resource,
legendFormat='{{namespace}}',
)
);
local gridPos = {
x: 0,
y: 0,
w: 24,
h: 8,
};
dashboard.new(
'grafonnet: Kubernetes resource count',
)
.addPanel(resourcePanel('deployment'), gridPos)
.addPanel(resourcePanel('daemonset'), gridPos)
.addPanel(resourcePanel('job'), gridPos)
.addPanel(resourcePanel('cronjob'), gridPos)
.addPanel(resourcePanel('pod'), gridPos)
.addPanel(resourcePanel('configmap'), gridPos)
.addPanel(resourcePanel('secret'), gridPos)
.addPanel(resourcePanel('service'), gridPos)
.addPanel(resourcePanel('endpoint'), gridPos)
▶ import式で別ファイルの関数を使える
+ Grafonnet(grafana.libsonnet)を利⽤
▶ 共通部分を関数として定義可能
+ PromQLの⼀部(メトリクス名、ラベル)
を引数で置換
①
①
②
②
③
③
例: Kubernetesのリソース数を種類ごとに表示するダッシュボード
14. Duplicate ☺
local grafana = import 'grafonnet/grafana.libsonnet';
local dashboard = grafana.dashboard;
local graphPanel = grafana.graphPanel;
local prometheus = grafana.prometheus;
local resourcePanel(resource) =
graphPanel.new(
title='Number of %s count by namespace' % resource,
datasource='prometheus',
).addTarget(
prometheus.target(
expr='count(kube_%s_created) by (namespace)' % resource,
legendFormat='{{namespace}}',
)
);
local gridPos = {
x: 0,
y: 0,
w: 24,
h: 8,
};
dashboard.new(
'grafonnet: Kubernetes resource count',
)
.addPanel(resourcePanel('deployment'), gridPos)
.addPanel(resourcePanel('daemonset'), gridPos)
.addPanel(resourcePanel('job'), gridPos)
.addPanel(resourcePanel('cronjob'), gridPos)
.addPanel(resourcePanel('pod'), gridPos)
.addPanel(resourcePanel('configmap'), gridPos)
.addPanel(resourcePanel('secret'), gridPos)
.addPanel(resourcePanel('service'), gridPos)
.addPanel(resourcePanel('endpoint'), gridPos)
▶ 関数、importで共通化
▶ 複製したグラフも⼀括修正可能
17. Dashboards as Code
▶ Grafanaのダッシュボードはコードで管理すると便利
+ GitOps
▶ Jsonnet/Grafonnetを使うことでグラフの複製やレビュー効率を改善
+ グラフや設定の共通化
+ わかりやすい差分