Package org.kairosdb.metrics4j
Class MetricSourceManager
- java.lang.Object
-
- org.kairosdb.metrics4j.MetricSourceManager
-
public class MetricSourceManager extends Object
Need to put methods to set various components programmatically. In kairos I want to set the reporter as a plugin to kairos that sends events using the event bus, but the configuration will reference this reporter by name in config even though no class will be defined in config.
-
-
Constructor Summary
Constructors Constructor Description MetricSourceManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddSource(Object o, Map<String,String> tags)For registering a class to gather metrics from.static voidaddSource(String className, String methodName, Map<String,String> tags, String help, DoubleSupplier supplier)A helper method that lets you pass a lambda function as the MetricCollector seeaddSourcemethod.static voidaddSource(String className, String methodName, Map<String,String> tags, String help, LongSupplier supplier)A helper method that lets you pass a lambda function as the MetricCollector seeaddSourcemethod.static voidaddSource(String className, String methodName, Map<String,String> tags, String help, MetricCollector collector)In some cases it is more helpful to have the metrics code call into your code to gather the metric or state of the system at the time of collection.static voidclearConfig()For testing purposes, this clears out any config stored in the static variablesstatic MetricConfiggetMetricConfig()MetricsContextgetMetricsContext()static <T> TgetSource(Class<T> tClass)static Map<String,String>getSourceProps(String className, String methodName)Returns properties set in configuration for the given class name and method name.static voidremoveSource(String className, String methodName, Map<String,String> tags)static <T> TsetCollectorForSource(MetricCollector stats, Class<T> reporterClass)This method is provided for unit test purposes.static voidsetMetricConfig(MetricConfig config)For testing purposes only, not to be used in production
-
-
-
Method Detail
-
setMetricConfig
public static void setMetricConfig(MetricConfig config)
For testing purposes only, not to be used in production- Parameters:
config- MetricConfig object to set
-
clearConfig
public static void clearConfig()
For testing purposes, this clears out any config stored in the static variables
-
getMetricConfig
public static MetricConfig getMetricConfig()
-
getSource
public static <T> T getSource(Class<T> tClass)
-
addSource
public static void addSource(Object o, Map<String,String> tags)
For registering a class to gather metrics from. Methods annotated with Reported will be called- Parameters:
o- Ojbect on which to look for@Reportedand@Snapshotannotationstags- Tags to set for @Reported method calls.
-
removeSource
public static void removeSource(String className, String methodName, Map<String,String> tags)
-
addSource
public static void addSource(String className, String methodName, Map<String,String> tags, String help, MetricCollector collector)
In some cases it is more helpful to have the metrics code call into your code to gather the metric or state of the system at the time of collection. This method allows you to artificially create a MetricCollector that will be called when metrics are collected to be reported- Parameters:
className- The class name to identify this collector for configuration purposes.methodName- The method name to identify this collector for configuration purposes.tags- Tags associated with this collectorhelp- Help text for this collectorcollector- A instance that implements MetricCollector to be called when collecting metrics.
-
getSourceProps
public static Map<String,String> getSourceProps(String className, String methodName)
Returns properties set in configuration for the given class name and method name. This is the key value data that shows up under the _props key in the configuration file.- Parameters:
className- Class name used as context for looking up propertiesmethodName- Method name used as context for looking up properties- Returns:
- Combined properties for the context provided
-
addSource
public static void addSource(String className, String methodName, Map<String,String> tags, String help, LongSupplier supplier)
A helper method that lets you pass a lambda function as the MetricCollector seeaddSourcemethod.- Parameters:
className- The class name to identify this collector for configuration purposes.methodName- The method name to identify this collector for configuration purposes.tags- Tags associated with this collectorhelp- Help text for this collectorsupplier- Lambda function that returns a long value.
-
addSource
public static void addSource(String className, String methodName, Map<String,String> tags, String help, DoubleSupplier supplier)
A helper method that lets you pass a lambda function as the MetricCollector seeaddSourcemethod.- Parameters:
className- The class name to identify this collector for configuration purposes.methodName- The method name to identify this collector for configuration purposes.tags- Tags associated with this collectorhelp- Help text for this collectorsupplier- Lambda function that returns a double value.
-
setCollectorForSource
public static <T> T setCollectorForSource(MetricCollector stats, Class<T> reporterClass)
This method is provided for unit test purposes. It lets you define a collectors object for a specific metric call. See the unit tests in MetricSourceManagerTest to see how to use this method.- Type Parameters:
T- Returned collector as defined by reporterClass- Parameters:
stats- Metric collector that will be used in the code. For unit testing this will likely be a mockreporterClass- Reporter class- Returns:
- Proxy instance of reprter class
-
getMetricsContext
public MetricsContext getMetricsContext()
-
-