Skip to content

javadelight/delight-metrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Lightweight Java Metrics

This library provides a simple way to report metrics for Java applications based on the Dropwizard Metrics Project and the Async Properties library.

Why Other metric frameworks are often complex and feature-rich. This framework is composed of a small set of core classes; thus, it is easy to understand and plug into various environments.

Usage

Keeping a count

For instance: How many users are logged into the system concurrently?

PropertyNode m = Metrics.create();

m.record(Metrics.increment("users"));
m.record(Metrics.increment("users"));
m.record(Metrics.decrement("users"));

m.print();

m.stop().get();

Should result in the output:

{
    'users': '1'
}

Measure Operations per Second

For instance: How many times per second is a service called?

final PropertyNode m = Metrics.create();

m.record(Metrics.happened("serviceCalled"));
m.record(Metrics.happened("serviceCalled"));
m.record(Metrics.happened("serviceCalled"));

Thread.sleep(10000);

m.print();

m.stop().get();

Should result in the output:

{
    'serviceCalled': {
        'Total Events': '3',
        'Events per Second (last Minute)': '0.552026648777594',
        'Events per Second (last 5 Minutes)': '0.5900828722929705',
        'Events per Second (last 15 Minutes)': '0.5966759088029381'
    }
}

Calculate Statistics

For instance: How large are received requests in average?

final PropertyNode m = Metrics.create();

m.record(Metrics.value("requestSize", 300));
m.record(Metrics.value("requestSize", 100));
m.record(Metrics.value("requestSize", 200));

m.print();

m.stop().get();

Should result in.

{
    'requestSize': {
        'Mean': '200.0',
        'Standard Deviation': '100.0',
        'Max': '300',
        'Min': '100',
        '75% of Values Smaller Than': '300.0',
        '95% of Values Smaller Than': '300.0',
        '98% of Values Smaller Than': '300.0'
    }
}

Note: Statistics are by default calculated using so called Exponentially Decaying Reservoirs. These essentially will provide the values and averages for the last 5 minutes of application runtime.

Reporting

Metrics are turned into easily human-readable strings. What you do with these is up to you.

Retrieve Single Metric as String

PropertyNode m = ...

String metric = m.retrieve("metricId").get().toString()

Retrieve All Metrics as String

PropertyNode m = ...

String metrics = m.render().get();

Dependency

Just add the following dependency to your projects.

<dependency>
    <groupId>org.javadelight</groupId>
    <artifactId>delight-metrics</artifactId>
    <version>[insert latest version]</version>
</dependency>

This artifact is available on Maven Central and BinTray.

Maven Central

Compatibility

This project is compatible with the following environments:

  • Java 1.6+
  • GWT 2.5.0+
  • Android (any)
  • OSGi (any)

Performance and Multi-Threading

A significant part of the internal implementation in the library is based on the Dropwizard Metrics Project. Thus, some of the performance characteristics are inherited from this project.

However, this project uses a different approach to multi-threading. While in the Dropwizard Metrics Project every metric and operation is synchronized independently, the Lightweight Java Metrics project synchronizes all operations in one place (see SynchronizedMetricsNode.java).

Thus, more operations can be performed within the scope of one thread. This might lead to better performance as compared to the Dropwizard Metrics Project in some case and to worse performance in others.

Further Resources

About

Lightweight metrics for Java.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published