Create custom dashboards
In the lab Using custom metrics we created a Workload with a ServiceMonitor so the Team's Prometheus can scrape our custom metrics. In this lab we are going to create a custom Grafana dashboard and add the dashboard to a Configmap so the Team's Grafana will automatically load the dashboard.
Create a dashboard in Grafana
-
In the left menu, click on
Apps
and openGrafana
. -
Go to the Grafana dashboard homepage.
-
In the top right click on
New
and thenNew Dashboard
. -
Click
+ Add visualization
. -
In the
Query
tab selectPrometheus (default)
. -
In the
A
collapsible section, select a metric from theMetric
drop-down list. In our example we use theapplication_greetings_total
metric. -
Click
Run queries
. -
You should now see a
Time series
graph like this:
- Save the dashboard in Grafana.
Make the dashboard persistent
Now you know how to create a dashboard in Grafana for your custom metrics. You could now save the dashboard, but if Grafana would get re-started, the dashboard will be gone. To make the dashboard persistent we need to add it to a configmap.
-
Go to
apps
and openGitea
. -
In the list of repositories there is a repository called
otomi/team-<team-name>-argocd
. Go to this repository. -
Click
Add File
and thenNew File
. -
Name the file
my-custom-dashboard.yaml
. -
Add the following manifest to the file:
apiVersion: v1
kind: ConfigMap
metadata:
name: my-custom-dashboard
labels:
grafana_dashboard: "1"
release: grafana-dashboards-labs # change labs to the name of your team
data:
my-dashboard.json: |-
# paste your dashboard json here
-
Before commiting changes, go back to Grafana.
-
Click on
Dashboard settings
(in the top right). -
In the left menu click
JSON model
. -
Copy the JSON model and paste it into the ConfigMap. Make sure to indent with 4.
-
Delete the dashboard created in Grafana.
-
Commit changes in Gitea.
The dashboard will now automatically be loaded into the Team's Grafana instance.