Skip to content

Simple Java metrics for counting and publishing metrics from Java applications

License

Notifications You must be signed in to change notification settings

j256/simplemetrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Java Metrics

This package provides some Java classes to help with the providing application metrics.

Enjoy. Gray Watson

Little Sample Program

I've checked in a little example program.

Getting Started

Here's a quick code sample showing how to get started.

// create our metrics manager which controls everything
MetricsManager metricsManager = new MetricsManager();

// create and register a persister, you will probably want to write your own for your own logging
LoggingMetricsPersister persister = new LoggingMetricsPersister();
metricsManager.setMetricValuesPersisters(new MetricValuesPersister[] { persister });

// create and register one (or many) metrics
ControlledMetricAccum hitCounter =
	new ControlledMetricAccum("example", null, "hits", "number of hits to the cache", null);
metricsManager.registerMetric(hitCounter);

// optionally start a persister thread to persist the metrics every minute (60000 millis)
MetricsPersisterJob persisterThread = new MetricsPersisterJob(manager, 60000, 60000, true);

// now the metric can be incremented whenever a "hit" occurs
hitCounter.increment();
// or maybe we need to account for a bunch of hits
hitCounter.add(23);
// ...

// the persister will log the value of hitCounter every 60 seconds automatically

Maven Configuration

<dependencies>
	<dependency>
		<groupId>com.j256.simplemetrics</groupId>
		<artifactId>simplemetrics</artifactId>
		<!-- NOTE: change the version to the most recent release version from the repo -->
		<version>1.10</version>
	</dependency>
</dependencies>

ChangeLog Release Notes

See the ChangeLog.txt file.