Part III. Accessing Prometheus
For this release, Prometheus is only supported for Fuse on OpenShift. For documentation about Prometheus on OpenShift Container Platform, go to: https://access.redhat.com/documentation/en-us/openshift_container_platform/3.9/html/installation_and_configuration/install-config-cluster-metrics#openshift-prometheus
Prometheus on OpenShift Container Platform is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs), might not be functionally complete, and Red Hat does not recommend to use them for production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information on Red Hat Technology Preview features support scope, see https://access.redhat.com/support/offerings/techpreview/.
You can use Prometheus to monitor and store Fuse on OpenShift data by exposing an endpoint with your Fuse application’s data to Prometheus format. Prometheus stores the data so that you can use a graphical tool, such as Grafana, to visualize and run queries on the data.
1. OpenShift setup
To use Prometheus to monitor Fuse on OpenShift you must:
Install the Ansible Service Broker (ASB), which requires OpenShift v3.9 or later. To install the Ansible Service Broker, follow the instructions here:
- When you start OpenShift, use the --service-catalog option.
2. Installing Prometheus
The Ansible Playbook Bundle uses an image of Prometheus:
To install the Ansible Playbook Bundle (APB), run these commands:
wget https://raw.githubusercontent.com/openshift/ansible-service-broker/master/ scripts/run_latest_build.sh chmod +x run_latest_build.sh ./run_latest_build.sh
To give the developer account permissions to install, run the following commands:
oc create -n ansible-service-broker -f https://raw.githubusercontent.com/ansibleplaybookbundle/ansible-playbook-bundle/apb-1.1.6-1/templates/openshift-permissions.template.yaml
oc export cm/broker-config -n ansible-service-broker | sed 's/sandbox_role: .*/sandbox_role: \"admin\"/' | oc replace -f - cm/broker-config -n ansible-service-broker
The Prometheus APB should appear.
- Follow the provided instructions. Optionally, you can install Grafana.
For information about getting started with Prometheus, go to: https://prometheus.io/docs/prometheus/latest/getting_started/
3. Configuring Prometheus
You can set the following environment variables in OpenShift in order to configure your application’s Prometheus agent:
Table 3. Prometheus Environment Variables
| || |
The host address to bind.
| || |
If set, disables the activation of Prometheus (echoes an empty value).
Prometheus is enabled.
| || |
The Port to use.
| || |
Uses the file (including path) as the Prometheus configuration file.
The /opt/prometheus/prometheus-config.yml file with Camel metrics
| || |
Additional options to append to the JMX exporter configuration.
4. Controlling the metrics that Prometheus monitors and collects
By default, Prometheus uses a configuration file ( https://github.com/fabric8io-images/s2i/blob/master/java/images/rhel/prometheus-config.yml) that includes all possible metrics exposed by Camel.
If you have custom metrics within your application that you want Prometheus to monitor and collect (for example, the number of orders that your application processes), you can use your own configuration file. Note that the metrics that you can identify are limited to those supplied in JMX.
To use a custom configuration file to expose JMX beans that are not covered by the default configuration, follow these steps:
Create a custom Prometheus configuration file. You can use the contents of the default file (
prometheus-config.ymlhttps://github.com/fabric8io-images/s2i/blob/master/java/images/rhel/prometheus-config.yml) as a guide for the format.
You can use any name for the custom configuration file, for example:
Add your prometheus configuration file (for example,
my-prometheus-config.yml) to your application’s
src/main/fabric8/deployment.xmlfile within your application and add an entry for the AB_JMX_EXPORTER_CONFIG environment variable with its value set to your configuration file. For example:
env: name: AB_JMX_EXPORTER_CONFIG value: “my-prometheus-config.yml”
This environment variable applies to your application at the pod level.
- Rebuild and deploy your application.
5. Viewing Prometheus metrics with Grafana
Grafana is an analytics platform that allows you to query, visualize, alert on and understand your metrics using dashboards.
To view Prometheus metrics with Grafana, you need to:
Configure a prometheus data source in Grafana (see "Creating a Prometheus data source" :
Use Prometheus metrics in your own dashboards and graphs (see "Creating a Prometheus graph" :
6. Generating alerts
For an example of using Prometheus for OpenShift to generate alerts, see the Red Hat Cloud Forms Monitoring, Alerts, and Reporting guide: