Gradle + Kamon + Prometheus: A Complete Guide

I hope you have read my coworker’s post about DevOps tools and it raised your interest. My post has some in common with that one. I’ll tell you some DevOps stuff also, but only with a specific build tool (Gradle) and a specific monitoring toolkit (Kamon + Prometheus).

Okay, so you can find the solution how to use Kamon with Gradle (or even SBT or Mavenin the official tutorial. You just import it into your project, add the necessary lines so Kamon can gather information about your application, add your favourite reporter (as I mentioned before we’ll use Prometheus), and you are done.

But what if you want to add the automatized kamon-akka? If you go to the official website, it says ‘You must start your application with the AspectJ Weaver agent when using any Akka module.’ Okay let’s do this… Adding AspectJ for SBT and Play applications is as easy as you see it here. But what about Gradle? 

First, let’s create our actors. We’ll have two pretty simple actors, PingActor, and PongActor.

If you run this application, you can see the Ping-Pong actors sending messages to each other, and logging stuff to the console, like how long the operation took. No big deal. Okay, next let’s track our messages with Kamon.

First, you need to add the gradle dependencies…

… and before initializing the actors in the main function, let’s initialize Kamon with the following function call.


So now if you start your application, you can see logs at http://localhost:9095/

Since it was pretty easy, now comes the tricky ‘You must start your application with the AspectJ Weaver agent when using any Akka module.’ part. I googled a lot, tried out a lot of suggestions on how I should start my application with the AspectJ Weaver, but none of them worked (more specially none of them was full). If you do the following, it works though! Trust me, I’m an engineer 😀

First, you have to add the aspectj plugin by adding the following lines to your build.gradle

The next thing you have to do is add the AspectJ Weaver as a Java Agent by adding this to your build.gradle file.

As you see the passes an argument to the JVM with the full path to the AspectJ Weaver jar. The only thing you have to do is download the ‘aspectjweaver-1.9.1.jar’ (for example from my example code)

And lastly, you should add the Akka Kamon dependency (with the akka slf4j) to your build.gradle file, and configure it

After doing this, if you run your application and go to http://localhost:9095/, you can see the logs generated by Akka Kamon

That’s all, I hope you found this useful.

Also I’m planning to release a post about Maven + Kamon + Prometheus, but I didn’t have enough time to figure out how it works 😀 So stay tuned until my next post!

See you later!

Wanari is a custom software development company, established in 2000. We love exploring new technologies and working on challenging projects. And, as you can see, sometimes we even share some of our code with the world. Follow us on Insta or Facebook to never miss a post.