Class Metric
- java.lang.Object
-
- com.berryworks.jquantify.Metric
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
EventCounter,VMUsage
public abstract class Metric extends Object implements Serializable
Abstract superclass forEventCounter,SessionCounter, and other metric classes.Each
Metricis associated with a descriptive label that is used in reporting to suggest what is being counted.A
Metricviews 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 givenMetric. At any point in time, aMetricmaintains knowledge of the current interval, as anIntervalobject, as well as one or moreIntervals that have were noted in the history of this metric.Choosing the duration of an interval. Each instance of a
Metrichas 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 ofMetric. For example, anEventCounteris 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.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intintervalSecondsHow many seconds are in each intervalprotected longstartTimeWhen theMetricwas constructed or resetprotected longtotalIntervalsNumber of intervals that have occurred so far during the life of thisMetric
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd()Adds a single event.abstract voidadd(int count)Adds a number of events.floatgetAge()Gets the age of this metric in seconds.longgetAgeMillis()Gets the age of this metric in milliseconds.abstract longgetCount()Gets the total count of events.intgetIntervalSeconds()Gets the number of seconds in each interval.StringgetLabel()Gets the descriptive label associated with this Metric instance.longgetTotalIntervals()Gets number of intervals that have occurred during the life of thisMetric.voidreset()Reset thisMetricto its "zero" condition.voidsetLabel(String label)Sets the descriptive label associated with this Metric instance.static floatuptime()Return the uptime in hours, measured from when the Metric class was loaded into the VM by the classloader.
-
-
-
Constructor Detail
-
Metric
public Metric(String label, int intervalDurationInSeconds)
Constructs a new Metric.- Parameters:
label- descriptive label for this MetricintervalDurationInSeconds- number of seconds in each interval
-
Metric
public Metric(String label)
Constructs a new Metric with an interval duration of 1 second.- Parameters:
label- - descriptive label for this Metric
-
Metric
public Metric()
No-arg constructor necessary for serialization.
-
-
Method Detail
-
getIntervalSeconds
public int getIntervalSeconds()
Gets the number of seconds in each interval.- Returns:
- number of seconds in each interval
-
getLabel
public String getLabel()
Gets the descriptive label associated with this Metric instance.- Returns:
- descriptive label for this Metric
-
setLabel
public void setLabel(String label)
Sets the descriptive label associated with this Metric instance.- Parameters:
label- descriptive label for this Metric
-
getAgeMillis
public long getAgeMillis()
Gets the age of this metric in milliseconds.- Returns:
- age in milliseconds of this Metric
-
getAge
public float getAge()
Gets the age of this metric in seconds.- Returns:
- age of this Metric in seconds
-
add
public void add()
Adds a single event.Equivalent to add(1).
-
add
public abstract void add(int count)
Adds a number of events.All events are considered to have happened simultaneously.
- Parameters:
count- number of events counted by this call
-
getCount
public abstract long getCount()
Gets the total count of events.- Returns:
- count
-
getTotalIntervals
public long getTotalIntervals()
Gets number of intervals that have occurred during the life of thisMetric.- Returns:
- number of intervals
-
reset
public void reset()
Reset thisMetricto its "zero" condition.
-
uptime
public static float uptime()
Return the uptime in hours, measured from when the Metric class was loaded into the VM by the classloader.- Returns:
- Description of the Return Value
-
-