A small Javalin application demonstrating requests, HTTP errors, average latency, JVM heap, process CPU, application health, and restart history:
Javalin → Micrometer → tiny statlite-metrics/v1 adapter → StatLite
It uses SimpleMeterRegistry and Javalin's Micrometer plugin. No Prometheus
dependency or server is required. StatLiteMetrics.java
is the helper published in the official Javalin integration guide.
See the tutorial for a
walkthrough of this example and the integration guide for adapter details. The application owns its adapter and readiness
signal; StatLite consumes the generic metrics contract.
Prerequisites: Java 17+, Maven, Python 3, and a StatLite binary. The example pins Javalin 7.2.3, its Micrometer plugin (Micrometer 1.17.0), and Jackson Databind 2.22.1. The tutorial was checked with StatLite v0.6.0. Clone this repository and start the app:
git clone https://github.com/javalin/javalin-statlite-example.git
cd javalin-statlite-exampleFrom the repository root:
mvn compile exec:javaIn a second terminal, from this directory, start StatLite:
mkdir -p runtime
statlite --config statlite.yamlIn a third terminal, generate traffic:
python3 probe.pyOpen http://127.0.0.1:19087. The probe sends 48 requests: 12 each to /hello,
/slow (120 ms), an unmatched /missing (404), and /error (500). It checks
counter increases and waits for the expected metrics in StatLite, allowing up
to 90 seconds each for initial collection and collection after traffic. Repeat
it to add history; avoid other application traffic during its exact-count checks.
Both services bind to loopback. The app uses port 18087 and exposes
/statlite/metrics; StatLite uses port 19087. History is stored in
runtime/statlite.sqlite. Stop each service with Ctrl-C.
The supplied configuration polls every 30 seconds, the recommended minimum interval for monitoring. The request timeout uses StatLite's default of ten seconds.
Health starts at UP. The demo control route changes the application-owned
readiness value without running dependency checks:
curl -X POST http://127.0.0.1:18087/demo/health/DOWN
# Wait for a poll, view the dashboard, then restore readiness:
curl -X POST http://127.0.0.1:18087/demo/health/UPThe health-control requests count as application traffic; only the metrics
route is excluded by the shared helper. Restore UP before running the probe,
which checks healthy collection. This control route is local demo code.
To see a restart, keep StatLite running, stop the Java app, and run
mvn compile exec:java again. Rerun python3 probe.py; the JVM start time
changes and StatLite records the new run without deriving deltas across it.