Apache Karaf Decanter 2.3.0, new Prometheus appender

As said in my previous post, Apache Karaf Decanter 2.3.0 is a major new release bringing fixes, improvements and new features.

We saw the new alerting service. In this blog post, we see another new feature: the Prometheus Appender.

Prometheus ?

Prometheus (https://prometheus.io/) is a popular metrics toolkit, especially for cloud ecosystem. It’s open-source and it’s part of the Cloud Native Computing Foundation.

If Karaf Decanter provides similar collecting and alerting features, it makes sense to use Decanter as collector that Prometheus can request. Then, the visualization and search can be performed on Prometheus.

Decanter Prometheus Appender

The preferred approach with Prometheus is to “expose” a HTTP endpoint providing metrics that the Prometheus platform can retrieve.

It’s what the Decanter Prometheus Appender is doing:

  • bind a Prometheus servlet that Prometheus can “poll”
  • get the incoming data from the Decanter Collectors
  • detects the numbers in the event data
  • creates Prometheus metrics and expose in the servlet

You just have to install the decanter-appender-prometheus feature:

karaf@root()> feature:install decanter-appender-prometheus

And that’s it ! By default, Decanter Prometheus appender is expose on /decanter/prometheus:

karaf@root()> http:list
ID │ Servlet        │ Servlet-Name   │ State       │ Alias                │ Url
───┼────────────────┼────────────────┼─────────────┼──────────────────────┼─────────────────────────
51 │ MetricsServlet │ ServletModel-2 │ Deployed    │ /decanter/prometheus │ [/decanter/prometheus/*]

Now, you can add collectors (like the JMX one) and you will have the metrics on /decanter/prometheus, ready to be polled by Prometheus. Here’s what we can see in a browser accessing http://localhost:8181/decanter/prometheus:

Adding metrics in your bundles

Another interesting feature provided by the Decanter Prometheus appender is easy way to add and expose your own metrics from your bundles.

Actually, the Decanter Prometheus appender exports the io.prometheus* packages. So, in your bundles, you just have to import the prometheus packages and your metrics will be automatically exposes in the Decanter Prometheus servlet.

For instance, your bundle MANIFEST.MF just has to contain:

...
Import-Package: io.prometheus.client;version="[0.8,1)"
...

Then in your bundle code, you can directly use the Prometheus client like this:

...
private static final Gauge gauge = Gauge.build().name("mygauge").help("mygauge").register();
...
gauge.set(200);
...

Then, when your bundle is running, you can see the metric exposed in the Decanter Prometheus HTTP servlet (on http://localhost:8181/decanter/prometheus):

Summary

We can see here why Apache Karaf is the perfect runtime for the cloud: it can integrate smoothly with cloud ecosystem.
Thanks to Apache Karaf, you have a flexible runtime for on prem and cloud without effort.

You May Also Like

About the Author: jbonofre

ASF Member, PMC for Apache Karaf, PMC for Apache ServiceMix, PMC for Apache Archiva, PMC for Apache Felix, PMC for Apache Camel, PMC for Apache Syncope, PMC for Apache Beam, PMC for Apache CarbonData, PMC for Apache Bahir, PMC for Apache Brooklyn, PMC for Apache Falcon, PMC for Apache Guacamole, PMC for Apache Lens, Committer for Apache ActiveMQ and much more ! Twitter: jbonofre IRC: jbonofre on #servicemix,#karaf,#camel,#cxf on Freenode