Rechercher

Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 2. Monitoring Camel K integrations

download PDF

Red Hat Integration - Camel K monitoring is based on the OpenShift monitoring system. This chapter explains how to use the available options for monitoring Red Hat Integration - Camel K integrations at runtime. You can use the Prometheus Operator that is already deployed as part of OpenShift Monitoring to monitor your own applications.

2.1. Enabling user workload monitoring in OpenShift

OpenShift 4.3 or higher includes an embedded Prometheus Operator already deployed as part of OpenShift Monitoring. This section explains how to enable monitoring of your own application services in OpenShift Monitoring. This option avoids the additional overhead of installing and managing a separate Prometheus instance.

Prerequisites

  • You must have cluster administrator access to an OpenShift cluster on which the Camel K Operator is installed. See Installing Camel K.

Procedure

  1. Enter the following command to check if the cluster-monitoring-config ConfigMap object exists in the openshift-monitoring project:

    $ oc -n openshift-monitoring get configmap cluster-monitoring-config
  2. Create the cluster-monitoring-config ConfigMap if this does not already exist:

    $ oc -n openshift-monitoring create configmap cluster-monitoring-config
  3. Edit the cluster-monitoring-config ConfigMap:

    $ oc -n openshift-monitoring edit configmap cluster-monitoring-config
  4. Under data:config.yaml:, set enableUserWorkload to true:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: cluster-monitoring-config
      namespace: openshift-monitoring
    data:
      config.yaml: |
        enableUserWorkload: true

2.2. Configuring Camel K integration metrics

You can configure monitoring of Camel K integrations automatically using the Camel K Prometheus trait at runtime. This automates the configuration of dependencies and integration Pods to expose a metrics endpoint, which is then discovered and displayed by Prometheus. The Camel Quarkus MicroProfile Metrics extension automatically collects and exposes the default Camel K metrics in the OpenMetrics format.

Prerequisites

Procedure

  1. Enter the following command to run your Camel K integration with the Prometheus trait enabled:

    kamel run myIntegration.java -t prometheus.enabled=true

    Alternatively, you can enable the Prometheus trait globally once, by updating the integration platform as follows:

    $ oc patch ip camel-k --type=merge -p '{"spec":{"traits":{"prometheus":{"configuration":{"enabled":true}}}}}'
  2. View monitoring of Camel K integration metrics in Prometheus. For example, for embedded Prometheus, select Monitoring > Metrics in the OpenShift administrator or developer web console.
  3. Enter the Camel K metric that you want to view. For example, in the Administrator console, under Insert Metric at Cursor, enter application_camel_context_uptime_seconds, and click Run Queries.
  4. Click Add Query to view additional metrics.

Default Camel Metrics provided by PROMETHEUS TRAIT

Some Camel specific metrics are available out of the box.

NameTypeDescription

application_camel_message_history_processing

timer

Sample of performance of each node in the route when message history is enabled

application_camel_route_count

gauge

Number of routes added

application_camel_route_running_count

gauge

Number of routes runnning

application_camel_[route or context]_exchanges_inflight_count

gauge

Route inflight messages for a CamelContext or a route

application_camel_[route or context]_exchanges_total

counter

Total number of processed exchanges for a CamelContext or a route

application_camel_[route or context]_exchanges_completed_total

counter

Number of successfully completed exchange for a CamelContext or a route

application_camel_[route or context]_exchanges_failed_total

counter

Number of failed exchanges for a CamelContext or a route

application_camel_[route or context]_failuresHandled_total

counter

Number of failures handled for a CamelContext or a route

application_camel_[route or context]_externalRedeliveries_total

counter

Number of external initiated redeliveries (such as from JMS broker) for a CamelContext or a route

application_camel_context_status

gauge

The status of the Camel Context

application_camel_context_uptime_seconds

gauge

The amount of time since the Camel Context was started

application_camel_[route or exchange]processing[rate_per_second or one_min_rate_per_second or five_min_rate_per_second or fifteen_min_rate_per_second or min_seconds or max_seconds or mean_second or stddev_seconds]

gauge

Exchange message or route processing with multiple options

application_camel_[route or exchange]_processing_seconds

summary

Exchange message or route processing metric

2.3. Adding custom Camel K integration metrics

You can add custom metrics to your Camel K integrations by using Camel MicroProfile Metrics component and annotations in your Java code. These custom metrics will then be automatically discovered and displayed by Prometheus.

This section shows examples of adding Camel MicroProfile Metrics annotations to Camel K integration and service implementation code.

Prerequisites

Procedure

  1. Register the custom metrics in your Camel integration code using Camel MicroProfile Metrics component annotations. The following example shows a Metrics.java integration:

    // camel-k: language=java trait=prometheus.enabled=true dependency=mvn:org.my/app:1.0 1
    
    import org.apache.camel.Exchange;
    import org.apache.camel.LoggingLevel;
    import org.apache.camel.builder.RouteBuilder;
    import org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants;
    
    import javax.enterprise.context.ApplicationScoped;
    
    @ApplicationScoped
    public class Metrics extends RouteBuilder {
    
       @Override
       public void configure() {
            onException()
                .handled(true)
                .maximumRedeliveries(2)
                .logStackTrace(false)
                .logExhausted(false)
                .log(LoggingLevel.ERROR, "Failed processing ${body}")
                // Register the 'redelivery' meter
                .to("microprofile-metrics:meter:redelivery?mark=2")
                // Register the 'error' meter
                .to("microprofile-metrics:meter:error"); 2
    
            from("timer:stream?period=1000")
                .routeId("unreliable-service")
                .setBody(header(Exchange.TIMER_COUNTER).prepend("event #"))
                .log("Processing ${body}...")
                // Register the 'generated' meter
                .to("microprofile-metrics:meter:generated") 3
                // Register the 'attempt' meter via @Metered in Service.java
                .bean("service") 4
                .filter(header(Exchange.REDELIVERED))
                    .log(LoggingLevel.WARN, "Processed ${body} after ${header.CamelRedeliveryCounter} retries")
                    .setHeader(MicroProfileMetricsConstants.HEADER_METER_MARK, header(Exchange.REDELIVERY_COUNTER))
                    // Register the 'redelivery' meter
                    .to("microprofile-metrics:meter:redelivery") 5
                .end()
                .log("Successfully processed ${body}")
                // Register the 'success' meter
                .to("microprofile-metrics:meter:success"); 6
        }
    }
    1
    Uses the Camel K modeline to automatically configure the Prometheus trait and Maven dependencies
    2
    error: Metric for the number of errors corresponding to the number of events that have not been processed
    3
    generated: Metric for the number of events to be processed
    4
    attempt: Metric for the number of calls made to the service bean to process incoming events
    5
    redelivery: Metric for the number of retries made to process the event
    6
    success: Metric for the number of events successfully processed
  2. Add Camel MicroProfile Metrics annotations to any implementation files as needed. The following example shows the service bean called by the Camel K integration, which generates random failures:

    package com.redhat.integration;
    
    import java.util.Random;
    
    import org.apache.camel.Exchange;
    import org.apache.camel.RuntimeExchangeException;
    
    import org.eclipse.microprofile.metrics.Meter;
    import org.eclipse.microprofile.metrics.annotation.Metered;
    import org.eclipse.microprofile.metrics.annotation.Metric;
    
    import javax.inject.Named;
    import javax.enterprise.context.ApplicationScoped;
    
    @Named("service")
    @ApplicationScoped
    @io.quarkus.arc.Unremovable
    
    public class Service {
    
       //Register the attempt meter
       @Metered(absolute = true)
       public void attempt(Exchange exchange) { 1
          Random rand = new Random();
             if (rand.nextDouble() < 0.5) {
                 throw new RuntimeExchangeException("Random failure", exchange); 2
          }
       }
     }
    1
    The @Metered MicroProfile Metrics annotation declares the meter and the name is automatically generated based on the metrics method name, in this case, attempt.
    2
    This example fails randomly to help generate errors for metrics.
  3. Follow the steps in Configuring Camel K integration metrics to run the integration and view the custom Camel K metrics in Prometheus.

    In this case, the example already uses the Camel K modeline in Metrics.java to automatically configure Prometheus and the required Maven dependencies for Service.java.

Red Hat logoGithubRedditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez leBlog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

© 2024 Red Hat, Inc.