How to add a custom value in Grafana Legend?

by emerald.wunsch , in category: General Help , a month ago

How to add a custom value in Grafana Legend?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer


by cecelia , a month ago


To add a custom value in Grafana Legend, you can use the Templating feature. Here's a step-by-step guide:

  1. In Grafana, open the Dashboard you want to customize the Legend for.
  2. Click on the Settings (gear) icon in the top-right corner of the screen.
  3. From the dropdown menu, select "Templating."
  4. Click on the "+ New" button to create a new template variable.
  5. Set the Name for the variable, which will be displayed in the Legend.
  6. In the Query field, enter a query that will generate the custom value you want to add to the Legend. For example, you may use a Prometheus query or any other data source query to compute a desired value.
  7. Configure any other options you require, such as a custom Label or Default value for the variable.
  8. Click on the "Add" button to save the template variable.
  9. Go back to your Dashboard view.
  10. Edit the Panel for which you want to show the custom value in the Legend.
  11. In the Metrics tab, select the Legend format using the "Legend" dropdown option.
  12. When setting up the Legend format, you can use the newly created template variable as a metric label. Simply add the template variable within curly braces. For example, if your template variable is named "my_variable", you can use the "{my_variable}" placeholder in the Legend format.
  13. Save the Panel settings.
  14. Refresh the Dashboard, and you should see your custom value in the Legend.

By using the Templating feature, you can create dynamic custom values in the Legend that will update based on the selected template variable.