Class 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 Detail

      • MetricSourceManager

        public MetricSourceManager()
    • 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 @Reported and @Snapshot annotations
        tags - Tags to set for @Reported method calls.
      • 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 collector
        help - Help text for this collector
        collector - 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 properties
        methodName - 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 see addSource method.
        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 collector
        help - Help text for this collector
        supplier - 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 see addSource method.
        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 collector
        help - Help text for this collector
        supplier - 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 mock
        reporterClass - Reporter class
        Returns:
        Proxy instance of reprter class