Add Telemetry

This section describes how to set up Lightbend Telemetry to take advantage of Lightbend Console’s built in monitors. The main steps include:

  1. Verify Lightbend credentials and add them to the project
  2. Add the Telemetry plugin and enable Prometheus metrics

Credentials

Lightbend Telemetry requires commercial credentials. You should have a ~/.lightbend/commercial.credentials file with the following contents (if necessary, log into https://portal.lightbend.com/ReactivePlatform/EnterpriseSuiteCredentials to obtain your username and password):

realm = Bintray
host = dl.bintray.com
user = <your username>
password = <your password>

In the Akka example’s project directory, create a lightbend.sbt file with the following contents:

credentials += Credentials(Path.userHome / ".lightbend" / "commercial.credentials")
resolvers += "com-mvn" at "https://repo.lightbend.com/commercial-releases/"
resolvers += Resolver.url("com-ivy",
url("https://repo.lightbend.com/commercial-releases/"))(Resolver.ivyStylePatterns)

Enable Telemetry and Prometheus metrics

To enable Telemetry and Prometheus, edit the following files:

First, open project/plugins.sbt and add the Telemetry sbt-cinnamon plugin:

addSbtPlugin("com.lightbend.cinnamon" % "sbt-cinnamon" % "2.9.3")
resolvers += Resolver.url("lightbend-commercial", url("https://repo.lightbend.com/commercial-releases"))(Resolver.ivyStylePatterns)

Next, add the following configuration to src/main/resources/application.conf:

cinnamon {
    application = "akka-cluster-example"

    // The following lines are specific to the tutorial example app.
    // Configuration details are at https://developer.lightbend.com/docs/telemetry/current/instrumentations/akka/actors.html#actor-settings.
    akka {
        actors {
            "/user/*" {
            report-by = class
            }
        }
    } 

    // Enable the prometheus exporter which will be scraped by Console.
    // Configuration details are at https://developer.lightbend.com/docs/telemetry/current/plugins/prometheus/prometheus.html#configuration.
    prometheus {
        exporters += http-server
        http-server {
            // Set this to listen on all interfaces, so it will listen on the container's external interface.
            host = "0.0.0.0"
            port = 9091
        }
    }
    // Log to stdout for debugging purposes.
    chmetrics {
        reporters += "console-reporter"
    }
}

Change exposed ports configuration in build.sbt to include port 9091 that will be used to export Prometheus metrics:

dockerExposedPorts ++= Seq(2552, 8080, 8558, 9091)

Now add this at the end of build.sbt file to enable Cinnamon plugin and add library dependencies:

// Enable Lightbend Telemetry `Cinnamon` plugin.
enablePlugins(Cinnamon)

// Group Cinnamon library dependencies.
lazy val cinnamonDependencies = Seq(
    Cinnamon.library.cinnamonCHMetrics,
    Cinnamon.library.cinnamonAkka,
    Cinnamon.library.cinnamonAkkaHttp,
    Cinnamon.library.cinnamonJvmMetricsProducer,
    Cinnamon.library.cinnamonPrometheus,
    Cinnamon.library.cinnamonPrometheusHttpServer
)

libraryDependencies ++= cinnamonDependencies

Finally, ensure the metric port is exposed. This should already be done for you if you copied the akka-cluster-example.yaml. This should be in the deployment spec:

ports:
  - name: metrics
    containerPort: 9091

And this in the service spec:

ports:
  - name: metrics
    port: 9091
    targetPort: 9091