Enabling discovery

Lightbend Console relies on Prometheus discovery for finding your application metric data. The following sections describe how to do this:

Lightbend Orchestration

Follow these steps to enable discovery of an application that you are building with Lightbend Orchestration tools:

  1. Set up your project with sbt-reactive-plugin as described in the Lightbend Orchestration documentation.

  2. Add the following annotations to build.sbt:

    annotations := Map(
      // enable scraping
      "prometheus.io/scrape" -> "true",
    )
    
  3. Also in build.sbt, expose the cinnamon-metrics port for Lightbend Telemetry, without which Prometheus will be unable to scrape metrics from your application:

    endpoints += TcpEndpoint("cinnamon-metrics", 9001, None)
    
  4. Follow the reactive-cli docs to generate the k8s resource definitions.

It’s also possible to customize the annotations further, if needed:

annotations := Map(
  // enable scraping
  "prometheus.io/scrape" -> "true",
  // set scheme - defaults to "http"
  "prometheus.io/scheme" -> "http",
  // set path - defaults to "/metrics"
  "prometheus.io/path" -> "/metrics",
  // force a single metrics port - by default, any named port ending in suffix metrics will be scraped
  "prometheus.io/port" -> "9001"
)

Running on Minikube

Before you build and deploy your application, make sure you are using minikube’s docker:

eval $( minikube docker-env )

Now build your application docker image with:

sbt docker:publishLocal

Next, generate your Kubernetes deployment descriptor with reactive-cli:

rp generate-kubernetes-resources --generate-all "<appName>:<version>"  > deployment.yaml

Inspect and customize the descriptor to your liking. Make sure the cinnamon port 9001 is exposed as described above.

spec:
  template:
    spec:
      containers:
      - name: iotapp
        ports:
        - containerPort: 9001
          name: metrics

Once you’re done customizing, you can deploy to minikube via:

kubectl apply -f deployment.yaml

Kubernetes annotations

If you are not using Lightbend Orchestration, you need to modify the PodSpec of the Kubernetes Deployment or similar resource so that Prometheus can determine how to scrape the metrics. Prometheus will scrape all named ports on a pod where the port name ends with metrics. This is the preferred approach.

Named ports annotation example

Note that:

  • the port names end in metrics
  • the prometheus.io/port annotation is unset
  • the prometheus.io/scrape annotation is set to the string "true"
spec:
  template:
    metadata:
      annotations:
        prometheus.io/scrape: 'true'
    spec:
      containers:
      - name: multiple-metric-ports
        ports:
        - containerPort: 9001
          name: first-metrics
        - containerPort: 9002
          name: second-metrics

You can also use the prometheus.io/port annotation to tell Prometheus to scrape the port(s). In this case the port name doesn’t matter.

prometheus.io/port annotation example

spec:
  template:
    metadata:
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/port: '9001'