Class MetricsCollector
java.lang.Object
com.assemblyrobot.simulator.core.metrics.MetricsCollector
public class MetricsCollector
extends java.lang.Object
Generic metrics collector. Can be attached to any class to store metrics about various facets of
said class.
It's generally considered a good practice to attach a public enum with a record of the metrics any given class is collecting, for the sake of ease of use later in the application.
Example:
public class MyClass {
@RequiredArgsConstructor
public enum Metrics {
METRIC_NAME("collector_metric_name");
@Getter private final String metricName;
}
}
-
Constructor Summary
Constructors Constructor Description MetricsCollector(@NonNull java.lang.String hostName, @NonNull java.lang.String typeClassName)
-
Method Summary
Modifier and Type Method Description double
getMetric(@NonNull java.lang.String metricName)
Gets a metric by name.double
getMetric(@NonNull java.lang.String metricName, double defaultValue)
Gets a metric by name, specifying a default value to use when a metric by this name does not exist.void
incrementMetric(@NonNull java.lang.String metricName)
Increments a metric by 1.void
incrementMetric(@NonNull java.lang.String metricName, double measurement)
Increments a metric by wanted amount.void
putMetric(@NonNull java.lang.String metricName, double measurement)
Sets or updates a metric.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
MetricsCollector
public MetricsCollector(@NonNull @NonNull java.lang.String hostName, @NonNull @NonNull java.lang.String typeClassName)
-
-
Method Details
-
getMetric
public double getMetric(@NonNull @NonNull java.lang.String metricName) throws java.lang.NullPointerExceptionGets a metric by name.- Parameters:
metricName
- Metric name to get.- Returns:
Double
- Throws:
java.lang.NullPointerException
- If no metric by this name exists.
-
getMetric
public double getMetric(@NonNull @NonNull java.lang.String metricName, double defaultValue)Gets a metric by name, specifying a default value to use when a metric by this name does not exist.- Parameters:
metricName
- Metric name to get.defaultValue
- Default value to use in case no metric by this name exists.- Returns:
Double
-
putMetric
public void putMetric(@NonNull @NonNull java.lang.String metricName, double measurement)Sets or updates a metric.- Parameters:
metricName
- Metric name to set/update.measurement
- Metric value to set/update.
-
incrementMetric
public void incrementMetric(@NonNull @NonNull java.lang.String metricName)Increments a metric by 1.- Parameters:
metricName
- Metric name to increment.
-
incrementMetric
public void incrementMetric(@NonNull @NonNull java.lang.String metricName, double measurement)Increments a metric by wanted amount.- Parameters:
metricName
- Metric name to increment.measurement
- Amount to increment.
-