The example of Dropwizard Metrics integration into an application built on Bootique.
For additional help/questions about this example send a message to
Bootique forum.
You can find different versions of framework in use at
* Java 1.8 or newer.
* Apache Maven.
* Docker
Here is how to build it:
git@github.com:bootique-examples/bootique-metrics-demo.git
cd bootique-metrics-demo
mvn package
First run Graphite:
docker run -d\
--name graphite\
--restart=always\
-p 80:80\
-p 2003-2004:2003-2004\
-p 2023-2024:2023-2024\
-p 8125:8125/udp\
-p 8126:8126\
graphiteapp/graphite-statsd
Check the options available in your app:
java -jar target/bootique-metrics-demo-1.0-SNAPSHOT.jar -h
OPTIONS
-c yaml_location, --config=yaml_location
Specifies YAML config location, which can be a file path or a URL.
-h, --help
Prints this message.
-H, --help-config
Prints information about application modules and their configuration options.
As a sample, let's measure the behavior of data sources. First, configure data sources
and metrics
in config.yml:
jdbc:
ds1:
url: jdbc:derby:target/derby/ds1;create=true
driverClassName: org.apache.derby.jdbc.EmbeddedDriver
initialSize: 1
ds2:
url: jdbc:derby:target/derby/ds2;create=true
driverClassName: org.apache.derby.jdbc.EmbeddedDriver
initialSize: 1
metrics:
reporters:
- type: slf4j
period: 5s
- type: graphite
Second, contribute DataSourceHealthCheckGroup
combining Health Checks
into a unit of work.
Third, inject MetricRegistry
in the code to create Meters,
Gauges,
Counters, Histograms,
Timers, etc. E.g. in the demo:
Gauges
are registered for connection pools.
Run the demo:
java -jar target/bootique-metrics-demo-1.0-SNAPSHOT.jar --config=config.yml
Result: the default command ds-check
runs all health checks, Slf4jReporter
prints Gauges
:
INFO [2017-09-19 12:42:29,536] main i.b.m.d.DataSourceHealthCheckCommand: ds2: OK
INFO [2017-09-19 12:42:29,537] main i.b.m.d.DataSourceHealthCheckCommand: ds1: OK
INFO [2017-09-19 12:42:30,142] metrics-logger-reporter-1-thread-1 metrics: type=GAUGE, name=io.bootique.metrics.demo.ds.InstrumentedLazyDataSourceFactory.ds1.active, value=0
INFO [2017-09-19 12:42:30,143] metrics-logger-reporter-1-thread-1 metrics: type=GAUGE, name=io.bootique.metrics.demo.ds.InstrumentedLazyDataSourceFactory.ds1.idle, value=1
INFO [2017-09-19 12:42:30,143] metrics-logger-reporter-1-thread-1 metrics: type=GAUGE, name=io.bootique.metrics.demo.ds.InstrumentedLazyDataSourceFactory.ds1.size, value=1
INFO [2017-09-19 12:42:30,143] metrics-logger-reporter-1-thread-1 metrics: type=GAUGE, name=io.bootique.metrics.demo.ds.InstrumentedLazyDataSourceFactory.ds1.waiting, value=0
INFO [2017-09-19 12:42:30,143] metrics-logger-reporter-1-thread-1 metrics: type=GAUGE, name=io.bootique.metrics.demo.ds.InstrumentedLazyDataSourceFactory.ds2.active, value=0
INFO [2017-09-19 12:42:30,143] metrics-logger-reporter-1-thread-1 metrics: type=GAUGE, name=io.bootique.metrics.demo.ds.InstrumentedLazyDataSourceFactory.ds2.idle, value=1
...
To look on Graphite report, go to http://localhost/dashboard