Lightbend Console relies on Prometheus discovery for finding your application metric data. The following sections describe how to do this:
- When using Lightbend Orchestration (
- By annotating Kubernetes resources
Follow these steps to enable discovery of an application that you are building with Lightbend Orchestration tools:
Set up your project with
sbt-reactive-pluginas described in the Lightbend Orchestration documentation.
Add the following annotations to
annotations := Map( // enable scraping "prometheus.io/scrape" -> "true", )
build.sbt, expose the
cinnamon-metricsport for Lightbend Telemetry, without which Prometheus will be unable to scrape metrics from your application:
endpoints += TcpEndpoint("cinnamon-metrics", 9001, None)
- 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" )
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:
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
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.
- the port names end in
prometheus.io/portannotation is unset
prometheus.io/scrapeannotation is set to the string
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.
spec: template: metadata: annotations: prometheus.io/scrape: 'true' prometheus.io/port: '9001'