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).
- Install the Grafana operator by using the OCP user interface. Select Operator Hub, search for Grafana operator, and then click Install.
- 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 - Connect Prometheus to Grafana and provide the required authentication by using the
following steps:
- Add the cluster role to the service account.
oc adm policy add-cluster-role-to-user cluster-monitoring-view -z txseries-grafana-sa - Generate the token for authentication by using the following command:
oc create token txseries-grafana-sa --duration=5184000s - 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 - Apply the YAML file by using the following command:
oc apply -f datasource.yaml
- Add the cluster role to the service account.
- 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 - Add the Grafana dashboard.
- After you deploy Grafana, open the user interface.
- From Dashboards on the left side, click New and select Import.
- Add the JSON file and click Load to view the dashboard.
- Select your namespace to view the data.
For a sample JSON file, see Sample JSON file for monitoring region metrics.