Gradle Example: Akka

Here are instructions for how to take a sample application and add telemetry to it for Gradle. In this example you will add Cinnamon and a Coda Hale Console reporter will be used to print telemetry output to the terminal window.

Prerequisites

The following must be installed for these instructions to work:

  • Java
  • Gradle
  • git
  • Bintray credentials

Bintray credentials

Follow these instructions to set up your Bintray credentials for Gradle.

Sample application

We are going to use Hello Akka as the sample application.

Open up a terminal window and execute the following:

> git clone https://github.com/typesafehub/activator-hello-akka.git
> cd activator-hello-akka

Modifications

The modifications below are required to enable telemetry.

build.gradle

Add a build.gradle file with the following content:

apply plugin: 'scala'

repositories {
    mavenLocal()
}

repositories {
    maven {
      credentials {
        username 'your username'
        password 'your password'
      }
      mavenCentral()
      url = 'https://repo.lightbend.com/commercial-releases'
    }
}

// Add the agent to a separate configuration so it doesn't add to the normal class path
configurations {
  agent
}

def cinnamonVersion = '2.6.2'

dependencies {
  agent group: 'com.lightbend.cinnamon', name: 'cinnamon-agent', version: cinnamonVersion
  // Use Coda Hale Metrics and Akka instrumentation
  compile group: 'com.lightbend.cinnamon', name: 'cinnamon-chmetrics_2.11', version: cinnamonVersion
  compile group: 'com.lightbend.cinnamon', name: 'cinnamon-akka_2.11', version: cinnamonVersion
  compile group: 'com.typesafe.akka', name: 'akka-actor_2.11', version: '2.5.6'
}

apply plugin:'application'
mainClassName = "HelloAkkaScala"

run.doFirst {
  jvmArgs "-javaagent:${configurations.agent.singleFile}"
}

test.doFirst {
  jvmArgs "-javaagent:${configurations.agent.singleFile}"
}

application.conf

Add a application.conf file to the folder src/main/resources with the following content:

cinnamon.application = "hello-akka"

cinnamon.akka {
  actors {
    "/user/*" {
      report-by = class
    }
  }
}
cinnamon.chmetrics {
  reporters += "console-reporter"
}

Running

When you have modified the files above you simply use Gradle to run the application:

> gradle run

The output should look something like this:

...
[info] Greeting: hello, akka
[info] Greeting: hello, lightbend
[info] hello, lightbend
[info] hello, lightbend
[info] hello, lightbend
[info] hello, lightbend
[info] hello, lightbend
[info] 5/13/16 11:30:25 AM ============================================================
[info]
[info] -- Counters --------------------------------------------------------------------
[info] metrics.akka.systems.helloakka.dispatchers.akka_actor_default-dispatcher.actors.GreetPrinter.running-actors
[info]              count = 1
[info] metrics.akka.systems.helloakka.dispatchers.akka_actor_default-dispatcher.actors.Greeter.running-actors
[info]              count = 1
[info]
[info] -- Histograms ------------------------------------------------------------------
[info] metrics.akka.systems.helloakka.dispatchers.akka_actor_default-dispatcher.actors.GreetPrinter.mailbox-size
...

That is how easy it is to get started! You can find more information about configuration, plugins, etc. in the rest of this documentation.