Maven Example: Akka

Here are instructions for how to take a sample application and add telemetry to it for Maven. 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
  • Maven
  • git
  • Bintray credentials

Bintray credentials

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

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.

pom.xml

Add a pom.xml file with the following content:

<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>hello-akka</groupId>
    <artifactId>app</artifactId>
    <version>0.1-SNAPSHOT</version>

    <repositories>
      <repository>
        <id>lightbend-commercial</id>
        <name>Lightbend Commercial</name>
        <url>https://lightbend.bintray.com/commercial-releases</url>
      </repository>
    </repositories>

    <dependencies>
        <!-- Use Coda Hale Metrics and Akka instrumentation -->
        <dependency>
            <groupId>com.lightbend.cinnamon</groupId>
            <artifactId>cinnamon-chmetrics_2.11</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>com.lightbend.cinnamon</groupId>
            <artifactId>cinnamon-akka_2.11</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor_2.11</artifactId>
            <version>2.4.20</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                              <artifactItem>
                                <groupId>com.lightbend.cinnamon</groupId>
                                <artifactId>cinnamon-agent</artifactId>
                                <version>2.5.0</version>
                                <overWrite>true</overWrite>
                                <destFileName>cinnamon-agent.jar</destFileName>
                              </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
              <groupId>org.scala-tools</groupId>
              <artifactId>maven-scala-plugin</artifactId>
              <executions>
                <execution>
                  <goals>
                    <goal>compile</goal>
                    <goal>testCompile</goal>
                  </goals>
                </execution>
              </executions>
              <configuration>
                <jvmArgs>
                  <jvmArg>-Xms64m</jvmArg>
                  <jvmArg>-Xmx1024m</jvmArg>
                </jvmArgs>
              </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.5.0</version>
                <configuration>
                    <executable>java</executable>
                    <arguments>
                        <argument>-javaagent:${project.build.directory}/dependency/cinnamon-agent.jar</argument>
                        <argument>-classpath</argument>
                        <classpath />
                        <argument>HelloAkkaScala</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

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 Maven to run the application:

> mvn compile package exec:exec

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.