Monitoring Camel K applications using Prometheus and Grafana

Sadhana Nandakumar
4 min readApr 27, 2022

Camel K is a lightweight integration framework built from Apache Camel to run natively on Kubernetes. It is specifically designed for serverless and microservices-based architectures.

Prometheus, a Cloud Native Computing Foundation project, is a systems and service monitoring system. It collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts when specified conditions are observed. In this article, we will explore how you can monitor Camel-K applications on Openshift using Prometheus and visualize them using a graphical tool like Grafana.

Let us first start by creating a namespace on Openshift.

oc new-project camel-k-monitoring

Next, let us install the Camel K operator. Check out the documentation to learn more about how to set up the Kamel binary CLI.

kamel install

Starting OpenShift 4.3, the Prometheus Operator, that’s already deployed as part of the monitoring stack, can be used to monitor application services.

Let us now enable the user workload monitoring setting as below:

oc -n openshift-monitoring create configmap cluster-monitoring-config
oc -n openshift-monitoring edit configmap cluster-monitoring-config

Modify by adding the config for enabling the user workload monitoring.

apiVersion: v1kind: ConfigMapmetadata:  name: cluster-monitoring-config  namespace: openshift-monitoringdata:  config.yaml: |    enableUserWorkload: true

Enabling the Prometheus Monitoring for individual integrations

The Prometheus trait automates the configuration of integration pods to expose a metrics endpoint, that can be discovered and scraped by a Prometheus server.

The Prometheus trait can be enabled when running an integration. Let us look at a simple integration.

// camel-k: language=javaimport org.apache.camel.builder.RouteBuilder;public class Basic extends RouteBuilder {  @Override  public void configure() throws Exception {    from("timer:java?period=1000")      .setHeader("example")      .constant("Java")     .setBody()     .simple("Hello World! Camel K route written in  ${header.example}.")    .log("${body}");  }}

We can enable the Prometheus trait as below,

kamel run Basic.java --trait prometheus.enabled=true

The Prometheus trait can be enabled using the Modeline comments as well.

// camel-k: language=java trait=prometheus.enabled=true

You should now start seeing Prometheus metrics show up on the Metrics view as below.

Enabling Prometheus Monitoring for Kamelets

Kamelets (Kamel route snippets) is a new concept introduced in Camel K that allows users to connect to external systems via a simplified interface, hiding all the low-level details about how those connections are implemented.

You can easily tune your KameletBinding with traits configuration by adding .metadata.annotations.

metadata: annotations:   trait.camel.apache.org/prometheus.enabled: "true"

Enabling the Prometheus Monitoring globally

The Prometheus trait can be enabled globally once, by updating the integration platform.

This can be done by running the following command

oc patch ip camel-k — type=merge -p '{"spec":{"traits":{"prometheus":{"configuration":{"enabled":true}}}}}'

This can also be enabled on the integration platform YAML as well.

Visualize metrics using Grafana

Check out this article to learn about you can configure Grafana to work off the user workload monitoring metrics.

We have set up a Grafana instance in the same namespace and added the Prometheus data source referring to the Thanos querier. Thanos querier is able to query metrics from the default Prometheus instance from openshift-monitoring as well as from the Prometheus instance of openshift-user-workload-monitoring.

We can now set up a dashboard to monitor the camel metrics that are exposed. A sample dashboard can be found here.

By enabling the monitoring across different services, we can visualize the health of the integrations effectively.

References:

https://camel.apache.org/camel-k/1.8.x/observability/monitoring.html

--

--

Sadhana Nandakumar

Sadhana is a Sr Technical Product Marketing Manager specializing in Salesforce Platform