Installing and configuring Grafana on OCP

Grafana is an open platform for metrics visualization. It supports multiple data stores including Prometheus. Grafana enables you to query, visualize, alert on, and understand your metrics.

You can create a custom Grafana dashboard for use on Red Hat® OpenShift® Container Platform (OCP).

  1. Install the Grafana operator by using the OCP user interface. Select Operator Hub, search for Grafana operator, and then click Install.
  2. Create an instance of the Grafana operator by using the following YAML file. Accordingly, update the username and password.
    apiVersion: grafana.integreatly.org/v1beta1
    kind: Grafana
    metadata:
      name: txseries-grafana
      labels:
        dashboards: txseries-grafana
        folders: txseries-grafana
    spec:
      config:
        auth:
          disable_login_form: "false"
        log:
          mode: console
        security:
          admin_password: start
          admin_user: root
  3. Connect Prometheus to Grafana and provide the required authentication by using the following steps:
    1. Add the cluster role to the service account.
      oc adm policy add-cluster-role-to-user cluster-monitoring-view -z txseries-grafana-sa
    2. Generate the token for authentication by using the following command:
      oc create token txseries-grafana-sa --duration=5184000s
    3. Update the token and the Prometheus URL in the YAML file.
      kind: GrafanaDatasource
      apiVersion: grafana.integreatly.org/v1beta1
      metadata:
        name: txseries-grafana
      spec:
        datasource:
          access: proxy
          editable: true
          isDefault: true
          jsonData:
            httpHeaderName1: Authorization
            timeInterval: 3s
            tlsSkipVerify: true
          name: prometheus
          secureJsonData:
            httpHeaderValue1: "Bearer <TOKEN_UPDATE>"
          type: prometheus
          url: "https://thanos-querier.openshift-monitoring.svc.cluster.local:9091"
        instanceSelector:
          matchLabels:
            dashboards: txseries-grafana
    4. Apply the YAML file by using the following command:
      oc apply -f datasource.yaml
  4. Route the service that is created in Step 3 by using the following YAML file:
    kind: Route
    apiVersion: route.openshift.io/v1
    metadata:
      name: cics-tx-grafana-route
      labels: {}
    spec:
      to:
        kind: Service
        name: cics-tx-grafana-service
      tls: null
      path: /
      port:
        targetPort: grafana
  5. Add the Grafana dashboard.
    1. After you deploy Grafana, open the user interface.
    2. From Dashboards on the left side, click New and select Import.
    3. Add the JSON file and click Load to view the dashboard.
    4. Select your namespace to view the data.

    For a sample JSON file, see Sample JSON file for monitoring region metrics.