Class SharedMetricRegistries


  • public class SharedMetricRegistries
    extends Object
    SharedMetricRegistries is used to create/retrieve a MicroProfile Metric's MetricRegistry instance of a provided scope. For each "scope" there exists an individual MicroProfile Metric MetricRegistry which is associated to an "underlying" Micrometer Prometheus MeterRegistry. Each of these Prometheus Meter Registries are registered under the default Micrometer global composite meter registry. With this implementation any creation/retrieval is negotiated with the global composite meter registry. To ensure that the different "scoped" MetricRegistry to MeterRegistry contain their own appropriate metrics/meters a Meter Filter is provided to each Prometheus MeterRegistry. This filter makes use of a ThreadLocal<Boolean> to ensure that appropriate metrics/meters are registered/retrieved from the appropriate registry. The ThreadLocal<Boolean> will be set to false to gate registration/retrieval. And it will be set to true before interacting with the global registry. A Map<String, ThreadLocal<Boolean>> holds a mapping between the scope and ThreadLocal. This map is interrogated when the MP MetricRegistry shim interacts with the global registry.
    • Field Detail

      • SERVER_LEVEL_MPCONFIG_GLOBAL_TAGS

        protected static io.micrometer.core.instrument.Tag[] SERVER_LEVEL_MPCONFIG_GLOBAL_TAGS
        This static Tag[] represents the server level global tags retrieved from MP Config for mp.metrics.tags. This value will be 'null' when not initialized. If during initialization and no global tag has been resolved this will be to an array of size 0. Using an array of size 0 is to represent that an attempt on start up was made to resolve the value, but none was found. This prevents later instantiations of MetricRegistry to avoid attempting to resolve the MP Config value for the slight performance boon. This server level value will not change at all throughout the life time of the server as it is defined by env vars or sys props.
    • Constructor Detail

      • SharedMetricRegistries

        public SharedMetricRegistries()
    • Method Detail

      • getOrCreate

        public static org.eclipse.microprofile.metrics.MetricRegistry getOrCreate​(String scope)
      • getOrCreate

        public static org.eclipse.microprofile.metrics.MetricRegistry getOrCreate​(String scope,
                                                                                  ApplicationNameResolver appNameResolver)
      • drop

        public static void drop​(String scope)
        Drops a particular registry. If a reference to the same registry type is requested later, a new empty registry will be created for that purpose.
        Parameters:
        scope - The scope of registry that should be dropped.
      • dropAll

        public static void dropAll()
        Drops all registries. If a reference to a registry is requested later, a new empty registry will be created for that purpose.
      • doesScopeExist

        public static boolean doesScopeExist​(String scope)
        Returns true/false if registry with this scope exists
        Parameters:
        scope - name of scope
        Returns:
        true/false if registry with this scope exists