No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/main/java
.gitignore
.travis.yml
LICENSE
README.md
config.yml
pom.xml

README.md

Build Status

bootique-metrics-demo

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.

Prerequisites

* Java 1.8 or newer.
* Apache Maven.

Build the Demo

Here is how to build it:

git@github.com:bootique-examples/bootique-metrics-demo.git
cd bootique-metrics-demo
mvn package

Run the Demo

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: sl4j

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
...