You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2022/04/08 12:15:15 UTC

[camel-k] branch main updated: Example to show usage of prometheus trait

This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new de90fa873 Example to show usage of prometheus trait
de90fa873 is described below

commit de90fa873227ec3480e224f997744d3eb6bfda17
Author: Subhasmita Swain <su...@gmail.com>
AuthorDate: Wed Mar 30 01:25:37 2022 +0530

    Example to show usage of prometheus trait
---
 examples/traits/prometheus/MyIntegration.java | 50 +++++++++++++++++++++++++++
 examples/traits/prometheus/README.md          | 27 +++++++++++++++
 2 files changed, 77 insertions(+)

diff --git a/examples/traits/prometheus/MyIntegration.java b/examples/traits/prometheus/MyIntegration.java
new file mode 100644
index 000000000..5b4ee4cab
--- /dev/null
+++ b/examples/traits/prometheus/MyIntegration.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+
+To execute this example, run: 
+kamel run -t prometheus.enabled=true MyIntegration.java
+
+*/
+
+import org.apache.camel.Exchange;
+import org.apache.camel.LoggingLevel;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants;
+
+public class MyIntegration extends RouteBuilder {
+
+    @Override
+    public void configure() {
+        onException()
+                .handled(true)
+                .maximumRedeliveries(2)
+                .logStackTrace(false)
+                .logExhausted(false)
+                .log(LoggingLevel.ERROR, "Failed processing ${body}")
+                .to("log:exception");
+
+        from("timer:foo?period=1000")
+                .routeId("unreliable-service")
+                .setBody(header(Exchange.TIMER_COUNTER).prepend("event #"))
+                .log("Processing ${body}...")
+                .bean("service", "process")
+                .log("Successfully processed ${body}")
+                .to("microprofile-metrics:meter:success");
+    }
+}
diff --git a/examples/traits/prometheus/README.md b/examples/traits/prometheus/README.md
new file mode 100644
index 000000000..ef6d15735
--- /dev/null
+++ b/examples/traits/prometheus/README.md
@@ -0,0 +1,27 @@
+# Camel K Prometheus Trait
+
+In this section you will find examples about fine tuning your `Integration` using **Prometheus** `trait` capability.
+
+
+A Prometheus-compatible endpoint is configured with the Prometheus trait. When utilising the Prometheus operator, it also generates a PodMonitor resource, which allows the endpoint to be scraped automatically.
+
+To get statistics about the number of events successfully handled by the `Integration`,execute the `MyIntegration.java` route via:
+
+    $ kamel run -t prometheus.enabled=true MyIntegration.java
+
+ In case the prometheus operator is not installed in your cluster, run: 
+    
+    $ kamel run -t prometheus.enabled=true pod-monitor=false MyIntegration.java
+
+You should be able to see the new integration running after a while via:
+
+    $ kamel get 
+
+The metrics can be retrieved by port-forwarding this service, e.g.:
+
+    $ kubectl port-forward svc/metrics-prometheus 8080:8080
+
+    $ curl http://localhost:8080/metrics
+
+Similarly other use cases can be to retrieve information on unprocessed events, number of retries made to process an event, etc. For more information on Integration monitoring refer to the [Camel K Integration Monitoring](https://camel.apache.org/camel-k/next/observability/monitoring/integration.html) documentation.
+