Adding Grafana plugins and configuring data sources in BKPR

Grafana is an open source metric analytics and visualization suite, commonly used for visualizing time series data. It includes built-in support to various types of data sources, such as Prometheus, Elasticsearch and so on. By using plugins its functionality can be further extended. Plugins can not only add support for additional data sources, but also add support for various types of panels and apps.

In this blog post, you will learn how to install Grafana plugins in BKPR followed by setting up a new Grafana data source by customizing th:e BKPR jsonnet manifests.

Installing plugins

The Grafana Plugins page lists the available official and community-built plugins, including the plugins that come installed by default in Grafana.

To show you how to install plugins into your Grafana instance, I will use as an example, the Pie Chart plugin. Follow these instructions:

  • Visit the Grafana plugin page and select the Installation tab. You will find the command you need to install the plugin using the grafana-cli tool.

Pie Chart Plugin

  • Write down the plugin name from this command: "grafana-piechart-panel" in this case. All you need to do now is specify the plugin name in the BKPR jsonnet manifests.
  • Open the kubeprod-manifests.jsonnet file and specify the plugin name in the Grafana "plugins" array as shown in the snippet below:
(import "./manifests/platforms/gke.jsonnet") {
    config:: import "kubeprod-autogen.json",
    grafana+: {
        plugins+: [
            "grafana-piechart-panel",
        ],
    },
}

To apply these changes, re-run the kubeprod install command you used to install BKPR on your cluster. Alternatively, you can use the kubecfg tool:

kubecfg update kubeprod-manifest.jsonnet --ignore-unknown --gc-tag kube_prod_runtime

While applying this change, the Grafana "ConfigMap" is updated, triggering a reload of the Grafana Pods. The reload initiates the restart of the Grafana instance. It will be offline for a moment.

TIP: To learn more about how BKPR triggers a reload of Grafana, read our post on Rolling Updates for ConfigMap Objects.

After the Grafana pods are back online, you should find the Pie Chart plugin listed in the Grafana UI:

Pie Chart Plugin

Additionally, you can specify more than one plugin in the "plugins" array if you want to install multiple plugins. Check the kubeprod-manifests.jsonnet snippet below:

(import "./manifests/platforms/gke.jsonnet") {
    config:: import "kubeprod-autogen.json",
    grafana+: {
        plugins+: [
            "grafana-piechart-panel",
            "grafana-worldmap-panel",
        ],
    },
}

That's all it takes to add Grafana plugins in BKPR!

Setting up a data source

You can use the Grafana UI to manage data sources. Since Grafana v5.0 it's possible to manage Grafana data sources by specifying it in its config files. Refer to the Grafana Docs to learn about it.

In this section you will learn about how to set up a Grafana data source in the config files. This makes it possible for you to manage the configuration as a human-readable config file making easier to share and maintain it.

IMPORTANT: The tricky part about setting up a data source in config files is determining all the config parameters for the data source. Ideally, these should be published in the plugin documentation. If this is not the case, you may have to inspect the plugin source code to retrieve this information.

To demonstrate how to set up a Grafana data source, you need first to set up an Azure Monitor datasource. Follow the instructions described in the Azure Monitor Plugin Guide to set up the access to the Azure monitor service and the Application Insights API. You can configure access to one or both of these services.

  • To start the configuration of the Azure Monitor datasource for Grafana, open the kubeprod-manifest.jsonnet file and specify the configuration as shown in the snippet below. Remember to replace Azure account placeholders with the corresponding information:
(import "./manifests/platforms/gke.jsonnet") {
    config:: import "kubeprod-autogen.json",
    grafana+: {
    datasources+: {
      datasources+: {
        "Azure Monitor": {
          type: "grafana-azure-monitor-datasource",
          access: "proxy",
          jsonData: {
            azureLogAnalyticsSameAs: false,
            cloudName: "azuremonitor",
            subscriptionId: "<AZURE_SUBSCRIPTION_ID>",
            tenantId: "<AZURE_ACTIVE_DIRECTORY_TENANT_ID>",
            clientId: "<AZURE_MONITOR_API_CLIENT_ID>",
            logAnalyticsSubscriptionId: "<AZURE_SUBSCRIPTION_ID>",
            logAnalyticsTenantId: "<AZURE_ACTIVE_DIRECTORY_TENANT_ID>",
            logAnalyticsClientId: "<AZURE_LOG_ANALYTICS_API_CLIENT_ID>",
            appInsightsAppId: "<AZURE_APPLICATION_INSIGHTS_CLIENT_ID>",
          },
          secureJsonData: {
            clientSecret: "<AZURE_MONITOR_API_CLIENT_SECRET>",
            logAnalyticsClientSecret: "<AZURE_LOG_ANALYTICS_API_CLIENT_SECRET>",
            appInsightsApiKey: "<AZURE_APPLICATION_INSIGHTS_CLIENT_SECRET>",
          },
        },
      },
    },
  },
}
  • Apply the changes by re-running the kubeprod install command or by using the kubecfg tool as described in the above section.
  • You should see a new datasource listed in the Grafana UI and you can utilize this datasource to visualize the data in your dashboards:

Azure Monitor Datasource

The following articles and documentation might be of your interest: