public abstract class Metric extends Object implements Serializable
EventCounter, SessionCounter, and other metric classes.
Each Metric is associated with a descriptive label that is
used in reporting to suggest what is being counted.
A Metric views time as a
series of non-overlapping time intervals. The duration of an interval is a
number of seconds and does not vary for the intervals within a given
Metric. At any point in time, a Metric maintains
knowledge of the current interval, as an Interval object, as
well as one or more Intervals that have were noted in the
history of this metric.
Choosing the duration of an interval.
Each instance of a Metric has a fixed duration for each interval.
The choice of duration makes no difference in the actual count of event occurrences.
It may, however, influence other calculations relevant to a particular subclass
of Metric. For example, an EventCounter is able to report
the peak frequency of events. If you are counting train departures from a station,
it may be reasonable to configure the interval duration at one hour, and learn the peak frequency
rate in departures/hour. If you used the default duration of one second, the
peak frequency would probably never exceed 1.0 per second during even the busiest part of the day.
If, on the other hand, you are counting database commits, then a one second interval
may be appropriate, since detecting a spike at 100 per second might be very helpful
and could go unnoticed in a commits per hour rate.| Modifier and Type | Field and Description |
|---|---|
protected int |
intervalSeconds
How many seconds are in each interval
|
protected long |
startTime
When the
Metric was constructed or reset |
protected long |
totalIntervals
Number of intervals that have occurred so far during the life of this
Metric |
| Constructor and Description |
|---|
Metric()
No-arg constructor necessary for serialization.
|
Metric(String label)
Constructs a new Metric with an interval duration of 1 second.
|
Metric(String label,
int intervalDurationInSeconds)
Constructs a new Metric.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add()
Adds a single event.
|
abstract void |
add(int count)
Adds a number of events.
|
float |
getAge()
Gets the age of this metric in seconds.
|
long |
getAgeMillis()
Gets the age of this metric in milliseconds.
|
abstract long |
getCount()
Gets the total count of events.
|
int |
getIntervalSeconds()
Gets the number of seconds in each interval.
|
String |
getLabel()
Gets the descriptive label associated with this Metric instance.
|
long |
getTotalIntervals()
Gets number of intervals that have occurred during the life of this
Metric. |
void |
reset()
Reset this
Metric to its "zero" condition. |
void |
setLabel(String label)
Sets the descriptive label associated with this Metric instance.
|
static float |
uptime()
Return the uptime in hours, measured from when the Metric class was loaded
into the VM by the classloader.
|
protected long startTime
Metric was constructed or resetprotected int intervalSeconds
protected long totalIntervals
Metricpublic Metric(String label, int intervalDurationInSeconds)
label - descriptive label for this MetricintervalDurationInSeconds - number of seconds in each intervalpublic Metric(String label)
label - - descriptive label for this Metricpublic Metric()
public int getIntervalSeconds()
public String getLabel()
public void setLabel(String label)
label - descriptive label for this Metricpublic long getAgeMillis()
public float getAge()
public void add()
public abstract void add(int count)
count - number of events counted by this callpublic abstract long getCount()
public long getTotalIntervals()
Metric.public void reset()
Metric to its "zero" condition.public static float uptime()
Copyright © 2015. All rights reserved.