How to configure Prometheus inside Openshift to scrape necessary metrics for Applications Manager?

How to configure Prometheus inside Openshift to scrape necessary metrics for Applications Manager?

To setup Prometheus inside a Openshift Cluster and scrape metrics for monitoring the same in Applications Manager, kindly follow the steps given below:

  1. Create a new Project "monitor" inside the Desired Cluster to be monitored using the below command. You can use this project to deploy Applications Manager's monitoring stack for scraping Openshift metrics.
  1. #Command to create a new namespace monitor
  2. oc new-project monitor
  1. Applications Manager uses the official Kube-state-metrics deployment image to export Openshift Cluster metrics. Since this deployment uses Kubernetes API to collect and expose Openshift Cluster level metrics, you will need to configure certain Cluster roles and their corresponding Cluster role bindings to provide appropriate permissions.
  2. Download the cluster-role.yaml  and cluster-role-binding.yaml files attached in this article.
  3. Navigate to the namespace monitor that you just created and execute the following commands to create Cluster role and Cluster Role bindings required for monitoring,
  1. #Command to navigate to the namespace monitor
  2. oc project monitor
  3. #Command to create ClusterRole and ClusterRoleBinding using the files provided
  4. oc apply -f cluster-role.yaml
  5. oc apply -f cluster-role-binding.yaml
  1. This will create a monitor named ClusterRole that will be bound to the ServiceAccount default of the namespace monitor using the ClusterRoleBinding, which you just created.
  2. Now that the required Cluster roles and Cluster role bindings have been created successfully, you can proceed with installing the components required to expose Prometheus. The following components will be deployed in the namespace that you created earlier and assigned Cluster role and Cluster role bindings:
    1. Kube-state-metrics
    2. Prometheus
  3. To Deploy the above mentioned components, execute the below mentioned commands after logging into the Openshift CLI interface.
  1. #Command to navigate to namespace monitor
  2. oc project monitor
  3. #Command to deploy kube-state-metrics
  4. oc new-app bitnami/kube-state-metrics
  5. #Command to deploy prometheus
  6. oc new-app prom/prometheus
  1. Once this is done, and the components that you deployed are up and running, you need to configure Prometheus to discover Kube-state-metrics deployment as a target and scrape the metrics for monitoring in Applications Manager.
  2. Download the prometheus.yml file attached to this article.
  3. Navigate to the namespace monitor where Applications Manager's monitoring components are running and create a ConfigMap for the prometheus.yml configuration file using the below command,
  1. #Command to navigate to the namespace
  2. oc project monitor
  3. #Command to create a ConfigMap named prom-config for our prometheus configuration
  4. oc create configmap prom-config --from-file=prometheus.yml
  1. Now the ConfigMap has been created successfully. Note that the name of the file should not be changed since this is crucial for Applications Manager's Prometheus deployment to pick up the configuration file as you proceed with further steps.
  2. Execute the following command to open the DeploymentConfig for the Prometheus deployment.
  1. #Command to navigate to the namespace monitor
  2. oc project monitor
  3. #Command to edit DeploymentConfig for prometheus deployment
  4. oc edit dc prometheus
  1. This will open up the DeploymentConfig for the Prometheus deployment
  2. Now you have to create a Volume for the ConfigMap prom-config that you created earlier and mount it to /etc/prometheus/ path inside the deployment for Prometheus to pick up the Configuration changes.
  3. To create a new volume, find the volumes tag in the DeploymentConfig for Prometheus and add the below mentioned changes as required.
    The changes to be added are highlighted below,
  1. volumes:
    - emptyDir: {}
      name: prometheus-volume-1
    - configMap:
        defaultMode: 420
        name: prom-config
      name: prom-config-volume

  1. Now create a Volume mount to mount the prom-config-volume volume to /etc/prometheus/ path. To do this, find the volumeMounts tag and add the below mentioned changes as required. The changes to be added are highlighted below,
  1. volumeMounts:
    - mountPath: /prometheus
      name: prometheus-volume-1
    - mountPath: /etc/prometheus/
      name: prom-config-volume

  1. A sample DeploymentConfig is attached in this Article (Ref. DeplymentConfig.yaml).
  2. Now save and close the DeploymentConfig. Once this is done, the configuration will be picked up by the Prometheus deployment in no time and the kube-state-metrics target will be discovered as shown in the below image.


  1. The service Prometheus has to be exposed in order to configure it in Applications Manager. To do this, execute the below command,
  1. #Command to convert a required service's type to NodePort
  2. oc patch svc prometheus -p '{"spec":{"type": "NodePort"}}'
  1. Once this is done, Prometheus can be integrated in Applications Manager using the NodePort which can be obtained using the below command.
    The port required for integration is highlighted below.
  1. #Command to get the details of a service
  2. oc get svc prometheus
  3. #Output
  4. NAME             TYPE          CLUSTER-IP    EXTERNAL-IP   PORT(S)                    AGE
    prometheus   NodePort   172.30.6.154   <none>              9090:
    32486/TCP   6d

                  New to ADSelfService Plus?

                    • Related Articles

                    • Absence of data in the Pods tab or some tabs in the OpenShift monitor

                      To collect data for the OpenShift Monitor, Applications Manager uses the SSH protocol to connect to the OpenShift server and execute "oc" commands. However, a timeout issue may occur while collecting data if the environment has a large number of ...
                    • How to configure Tomcat Exporter to scrape metrics from Prometheus?

                      To setup exporter, follow the steps given below: Install a standalone Tomcat-sever or as a container as kubernetes cluster. Download the Tomcat exporter servlet file in .war format from here. Rename the file as metrics.war and deploy it in the ...
                    • OpenShift Monitoring in Rest API Mode

                      For the OpenShift monitor, data collection when carried out using SSH mode sometimes results in timeout exception due to the presence of large amount of data to be collected. To avoid this, an enhancement has been made and now data collection will ...
                    • Monitoring Capacity Entitlement in Applications Manager

                      Applications Manager is equipped to monitor processor capacity entitlement issues. To measure the average entitlement value during peak production times with a higher workload, you can use the following command: lparstat 1 20 > /tmp/apm_physc.txt && ...
                    • JDBC data not populated for tomcat added by Prometheus

                      To configure JDBC metrics in tomcat exporter 1) Open the below file from tomcat installation directory. $CATALINA_BASE/conf/server.xml 2) Add the following configuration under <GlobalNamingResources> tag in the server.xml file. <Resource ...