Search

Part III. Accessing Prometheus

download PDF
Note

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

Important

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: https://github.com/openshift/ansible-service-broker
  • When you start OpenShift, use the --service-catalog option.

2. Installing Prometheus

The Ansible Playbook Bundle uses an image of Prometheus: https://github.com/ansibleplaybookbundle/prometheus-apb

  1. 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
  2. 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.

  3. 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
Environment VariableDescriptionDefault

AB_PROMETHEUS_HOST

The host address to bind.

0.0.0.0

AB_PROMETHEUS_OFF

If set, disables the activation of Prometheus (echoes an empty value).

Prometheus is enabled.

AB_PROMETHEUS_PORT

The Port to use.

9779

AB_JMX_EXPORTER_CONFIG

Uses the file (including path) as the Prometheus configuration file.

The /opt/prometheus/prometheus-config.yml file with Camel metrics

AB_JMX_EXPORTER_OPTS

Additional options to append to the JMX exporter configuration.

Not applicable.

4. Controlling the metrics that Prometheus monitors and collects

By default, Prometheus uses a configuration file ( https://raw.githubusercontent.com/jboss-fuse/application-templates/master/prometheus/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:

  1. Create a custom Prometheus configuration file. You can use the contents of the default file (prometheus-config.yml https://raw.githubusercontent.com/jboss-fuse/application-templates/master/prometheus/prometheus-config.yml) as a guide for the format.

    You can use any name for the custom configuration file, for example: my-prometheus-config.yml

  2. Add your prometheus configuration file (for example, my-prometheus-config.yml) to your application’s src/main/fabric8-includes directory.
  3. Create a src/main/fabric8/deployment.xml file 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.

  4. 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:

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:

https://access.redhat.com/documentation/en-us/red_hat_cloudforms/4.6/html/monitoring_alerts_and_reporting/integrating_prometheus_alerts

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.