jenkinsgrafanaprometheus

Grafana - Updated all graphs on dashboard from metric selection


I have a prometheus node which collects job data from Jenkins and stores it e.g.:

jenkins_job_last_completed_build_queuing_duration_seconds{jobname="j1"} 0.01
jenkins_job_last_completed_build_timestamp_seconds{jobname="j1"} 1489006588.334

etc.

In grafana I want ot have a dashboard with a bunch of graphs for the different metrics and some way of choosing which job to display on the graphs.
e.g. I log onto the dashboard and select j1 somehow and all the graphs show the data for j1. Then I change my selection to j2 and all the graphs update to show j2 data.

I know I can do this on a per graph basis by clicking in the legend, but I want to do them all at once.

Is this possible?

Cheers


Solution

  • Yes! You can make a template query in grafana that is populated with a label value. Docs are here: http://docs.grafana.org/features/datasources/prometheus/#templated-queries

    We do something similar to select a namespace in a dashboard to see the memory & CPU consumption of the services in that namespace. Our dashboard looks like this:

    enter image description here

    And the queries look like:

    namespace_name:container_cpu_usage_seconds_total:sum_rate{namespace=\"$namespace\"}

    I don't know how to make the variable with the UI, I generate the config with our grafanalib project (https://github.com/weaveworks/grafanalib) and it looks like this:

    "templating": {
        "list": [
          {
            "allValue": null,
            "current": {
              "tags": [],
              "text": "default",
              "value": "default"
            },
            "datasource": "Scope-as-a-Service Prometheus",
            "hide": 0,
            "includeAll": false,
            "label": "Namespace",
            "multi": false,
            "name": "namespace",
            "options": [],
            "query": "label_values(k8s_pod_status_ready, namespace)",
            "refresh": 1,
            "regex": "",
            "sort": 1,
            "tagValuesQuery": null,
            "tagsQuery": null,
            "type": "query"
          }
        ]
      },