Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Latest commit

 

History

History
61 lines (44 loc) · 1.83 KB

README.md

File metadata and controls

61 lines (44 loc) · 1.83 KB

Metrics Schema

Travis Maven Central Javadocs

Define your Metrics in a JSON file so you can keep track of what you're expecting and what's actually going out.

Installation

Maven

Add this dependency to your pom.xml. Update the version to the one you want.

<dependency>
    <groupId>io.jahed</groupId>
    <artifactId>metrics-schema</artifactId>
    <version>1.0</version>
</dependency>

Usage

Create a JSON to define your schema.

{
  "application": {
    "metric-meter": "com.codahale.metrics.Meter",
    "metric-timer": "com.codahale.metrics.Timer"
  }
}

Here we're saying that we expect 2 metrics to be used. A Meter called application.metric-meter and a Timer called application.metric-timer.

The Metric must be a full canonical name of a class which implements com.codahale.metrics.Metric.

Once you've defined your schema, you can use it to validate your MetricRegistry.

MetricRegistry registry = new MetricRegistry();
MetricSchema schema = MetricSchemaFactory.createFromResource("/resource/path/to/your/schema.json");
new MetricRegistryValidator(schema, registry)
    .onSuccess(success -> logger.debug(success.getMessage()))
    .onFailure(failure -> logger.warn(failure.getMessage()))
    .startValidating();

If you ever want to stop validating, you can do the following:

validator.stopValidating();

License

See LICENSE file.