docs/book/src/plugins/available/grafana-v1-alpha.md
grafana/v1-alpha)The Grafana plugin is an optional plugin that can be used to scaffold Grafana Dashboards to allow you to check out the default metrics which are exported by projects using controller-runtime.
<aside class="note"> <h1>Examples</h1>You can check its default scaffold by looking at the project-v4-with-plugins projects
under the testdata directory on the root directory of the Kubebuilder project.
prometheus-operator, this is similar as: http://prometheus-k8s.monitoring.svc:9090 )Check the metrics to know how to enable the metrics for your projects scaffold with Kubebuilder.
See that in the config/prometheus you will find the ServiceMonitor to enable the metrics in the default endpoint /metrics.
The Grafana plugin is attached to the init subcommand and the edit subcommand:
# Initialize a new project with grafana plugin
kubebuilder init --plugins grafana.kubebuilder.io/v1-alpha
# Enable grafana plugin to an existing project
kubebuilder edit --plugins grafana.kubebuilder.io/v1-alpha
The plugin will create a new directory and scaffold the JSON files under it (i.e. grafana/controller-runtime-metrics.json).
See an example of how to use the plugin in your project:
Copy the JSON file
Visit <your-grafana-url>/dashboard/import to import a new dashboard.
Paste the JSON content to Import via panel json, then press Load button
Select the data source for Prometheus metrics
Once the json is imported in Grafana, the dashboard is ready.
The Grafana plugin supports scaffolding manifests for custom metrics.
When the plugin is triggered for the first time, grafana/custom-metrics/config.yaml is generated.
---
customMetrics:
# - metric: # Raw custom metric (required)
# type: # Metric type: counter/gauge/histogram (required)
# expr: # Prom_ql for the metric (optional)
# unit: # Unit of measurement, examples: s,none,bytes,percent,etc. (optional)
You can enter multiple custom metrics in the file. For each element, you need to specify the metric and its type.
The Grafana plugin can automatically generate expr for visualization.
Alternatively, you can provide expr and the plugin will use the specified one directly.
---
customMetrics:
- metric: memcached_operator_reconcile_total # Raw custom metric (required)
type: counter # Metric type: counter/gauge/histogram (required)
unit: none
- metric: memcached_operator_reconcile_time_seconds_bucket
type: histogram
Once config.yaml is configured, you can run kubebuilder edit --plugins grafana.kubebuilder.io/v1-alpha again.
This time, the plugin will generate grafana/custom-metrics/custom-metrics-dashboard.json, which can be imported to Grafana UI.
See an example of how to visualize your custom metrics:
The Grafana plugin implements the following subcommands:
edit ($ kubebuilder edit [OPTIONS])
init ($ kubebuilder init [OPTIONS])
The following scaffolds will be created or updated by this plugin:
grafana/*.jsonserviceMonitor provided by kustomize plugin