This app was initially created starting from the MicroProfile Starter and modified to use OpenTelemetry Metrics. This app helps illustrate the use of OpenTelemetry Metrics with:
- Liberty server with application instrumented with OpenTelemetry Metrics
- Prometheus
- Grafana with a dashboard built to show the app's metrics
-
set up a bridge network in docker to use for Liberty, Prometheus, Grafana
docker network create -d bridge mynet
-
run Prometheus, Grafana and OpenTelemetry Collector on mynet network
docker run -d --name prometheus --net mynet -p 9090:9090 -v $(pwd)/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus:v2.39.1
docker run -d --name grafana --net mynet -p 3000:3000 -v $(pwd)/prometheus/prometheus-datasource.yml:/etc/grafana/provisioning/datasources/prometheus-datasource.yml -v $(pwd)/grafana/grafana.ini:/etc/grafana/grafana.ini grafana/grafana:9.1.8-ubuntu
docker run -d --name collector --net mynet -p 8888:8888 -p 8889:8889 -v $(pwd)/collector/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml otel/opentelemetry-collector-contrib
-
run Liberty in dev mode with container support on mynet network. The Liberty Dockerfile builds FROM the daily Liberty build (openliberty/daily:full-java11-openj9)
cd liberty # note: liberty dev mode with containers requires an internet connection mvn liberty:devc -DserverStartTimeout=120 -DdockerRunOpts="--net=mynet --name=liberty1 -m 512MB"
-
import Grafana dashboard (use the dashboard import in the Grafana UI)
open http://localhost:3000 import dashboard from grafana/CarStats.json into Grafana
Use the app while showing the effect on the metrics in the Grafana dashboard.
-
open the app, Prometheus, Grafana from browser
# Liberty open http://localhost:9080 # Metrics from OpenTelemetry Collector open http://localhost:8889/metrics # Prometheus open http://localhost:9090 # Grafana open http://localhost:3000
-
open the following files in an IDE to show the metrics instrumentation
- CarController
- CarMetrics
-
click links in the app. Suggested flow:
- unlock the car
- start the car
- start driving
- stop driving
- stop the car
- lock the car
Uninstall the docker containers as follows:
docker stop prometheus grafana collector liberty1
docker rm prometheus grafana collector liberty1