SimpleMetrics - Simple Metrics Java Package

This package provides some simple metrics and associated operations that allow for the recording of application metrics and persisting them to various different local or cloud storage/metric systems. You code registers metrics and then doesn't have to not worry about how they are managed or persisted.

Example Code

The following is a simple example program showing how SimpleMetrics works. For a full working example see the BasicExample class.

// 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 system 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

Free Spam Protection   Eggnog Recipe   Android ORM   Simple Java Magic   JMX using HTTP   OAuth 2.0 Simple Example   Great Eggnog Recipe