Grafana
- Canonical Observability
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/stable | 117 | 10 Sep 2024 | |
latest/candidate | 117 | 28 Jun 2024 | |
latest/beta | 122 | 19 Nov 2024 | |
latest/edge | 126 | 29 Nov 2024 | |
1.0/stable | 93 | 12 Dec 2023 | |
1.0/candidate | 93 | 22 Nov 2023 | |
1.0/beta | 93 | 22 Nov 2023 | |
1.0/edge | 93 | 22 Nov 2023 |
juju deploy grafana-k8s --channel beta
Deploy Kubernetes operators easily with Juju, the Universal Operator Lifecycle Manager. Need a Kubernetes cluster? Install MicroK8s to create a full CNCF-certified Kubernetes system in under 60 seconds.
Platform:
Create a new dashboard for an existing charm
Introduction
By the end of this tutorial you will have a grafana dashboard for self-monitoring prometheus, with juju topology drop-downs.
Deploy the apps
First, deploy grafana and prometheus:
juju deploy --trust --channel=edge grafana-k8s grafana
juju deploy --trust --channel=edge prometheus-k8s prometheus
Next, relate the two charms so grafana could see some metrics:
juju relate prom grafana:metrics-endpoint
juju relate prom:grafana-source grafana
juju relate prom:grafana-dashboard grafana
Open grafana’s dashboard creation web ui
First, obtain the admin password:
juju run grafana/0 get-admin-password
Next
- Navigate with your browser to grafana’s unit ip, and log in with “admin”, and the password you just obtained.
- Familiarize yourself with the dashboard creation process from the official docs and head over to
http://GRAFANA_UNIT_IP:3000/dashboard/new
.
Create a new dashboard for prometheus
- Add a new panel and set
juju_..._prometheus_0
as the data source. - Switch from “Builder” to “Code”.
- In the PromQL query, type
go_threads
and press Shift+Enter. You should see two lines, one for prometheus and one for grafana itself (grafana will be automatically filtered-out in a later step). Click “Apply”. - Add another panel with the following query:
sum by (handler) (rate(prometheus_http_request_duration_seconds_sum[$__rate_interval]))
. Switch the visualization type to “Heatmap”. Click “Apply”. - Save the dashboard.
Export dashboard
- Click “Share dashboard or panel” at the top left.
- Go to “Export” tab and deselect
Export for sharing externally
. Save to file.
Before proceeding to the next steps, delete the dashboard from grafana to avoid collision.
Manually modify the exported dashboard
First, replace all datasource
entries in the dashboard json file with ${prometheusds}
.
For grafana versions older than 9 it should look like this:
"datasource": "${prometheusds}",
For recent grafana versions it should look like this:
"datasource": {
"type": "prometheus",
"uid": "${prometheusds}"
},
Next, add juju topology label selectors to all expressions, escaping the quotation marks. For example:
"expr": "go_threads{juju_model_uuid=~\"$juju_model_uuid\", juju_model=~\"$juju_model\",juju_application=~\"$juju_application\", juju_unit=~\"$juju_unit\"}"
and
"expr": sum by (handler) (rate(prometheus_http_request_duration_seconds_sum{juju_model_uuid=~\"$juju_model_uuid\", juju_model=~\"$juju_model\",juju_application=~\"$juju_application\", juju_unit=~\"$juju_unit\"}[$__rate_interval]))
Add dashboard to the prometheus charm
To include the exported dashboard in the collection of built-in prometheus dashboards:
- Place the dashboard under the
grafana_dashboards
folder, pack and refresh the charm. - In the browser, refresh the list of dashboards,
http://GRAFANA_UNIT_IP:3000/dashboards
. - In your new dashboard you should now see selectable drop-down menus that affect the content displayed on the graphs.