public class MonitoringCenter extends Object
MonitoringCenter is a wrapper around Dropwizard's MetricRegistry and HealthCheckRegistry.
This class must be configured before any application code using it is executed. Thus, it is recommended to run
configure(MonitoringCenterConfig) as the first statement in the ContextListener or the main() method
(perhaps, right after configuring your logging framework). Please note that MonitoringCenter will configure
itself automatically upon calls to getMetricCollector(String, String...) or
registerHealthCheck(String, HealthCheck). When configured automatically, the MonitoringCenter will
use the default config file as explained in Configurator.defaultConfigFile().
This class is thread-safe.
| Modifier and Type | Method and Description |
|---|---|
static void |
configure(MonitoringCenterConfig config)
Configures the MonitoringCenter.
|
static AppInfo |
getAppInfo()
Retrieves information about the application, including the application name and build context.
|
static SortedMap<String,com.codahale.metrics.Counter> |
getCountersByNames()
Retrieves a sorted map of counters by names.
|
static SortedMap<String,com.codahale.metrics.Counter> |
getCountersByNames(boolean appendPrefix)
Retrieves a sorted map of counters by names.
|
static SortedMap<String,com.codahale.metrics.Counter> |
getCountersByNames(boolean appendPrefix,
String[] startsWithFilters)
Retrieves a sorted map of counters by names.
|
static MetricCollector |
getDatabaseMetricCollector(String... additionalNamespaces)
Retrieves a MetricCollector, whose main namespace is "dbs".
|
static SortedMap<String,com.codahale.metrics.Gauge> |
getGaugesByNames()
Retrieves a sorted map of gauges by names.
|
static SortedMap<String,com.codahale.metrics.Gauge> |
getGaugesByNames(boolean appendPrefix)
Retrieves a sorted map of gauges by names.
|
static SortedMap<String,com.codahale.metrics.Gauge> |
getGaugesByNames(boolean appendPrefix,
String[] startsWithFilters)
Retrieves a sorted map of gauges by names.
|
static SortedMap<String,com.codahale.metrics.Histogram> |
getHistogramsByNames()
Retrieves a sorted map of histograms by names.
|
static SortedMap<String,com.codahale.metrics.Histogram> |
getHistogramsByNames(boolean appendPrefix)
Retrieves a sorted map of histograms by names.
|
static SortedMap<String,com.codahale.metrics.Histogram> |
getHistogramsByNames(boolean appendPrefix,
String[] startsWithFilters)
Retrieves a sorted map of histograms by names.
|
static SortedMap<String,com.codahale.metrics.Meter> |
getMetersByNames()
Retrieves a sorted map of meters by names.
|
static SortedMap<String,com.codahale.metrics.Meter> |
getMetersByNames(boolean appendPrefix)
Retrieves a sorted map of meters by names.
|
static SortedMap<String,com.codahale.metrics.Meter> |
getMetersByNames(boolean appendPrefix,
String[] startsWithFilters)
Retrieves a sorted map of meters by names.
|
static MetricCollector |
getMetricCollector(Class<?> clazz,
String... namespaces)
Retrieves a
MetricCollector with a given namespace. |
static MetricCollector |
getMetricCollector(String mainNamespace,
String... additionalNamespaces)
Retrieves a
MetricCollector with a given namespace. |
static SortedMap<String,com.codahale.metrics.Metric> |
getMetricsByNames()
Retrieves a sorted map of metrics by names.
|
static SortedMap<String,com.codahale.metrics.Metric> |
getMetricsByNames(boolean appendPrefix)
Retrieves a sorted map of metrics by names.
|
static SortedMap<String,com.codahale.metrics.Metric> |
getMetricsByNames(boolean appendPrefix,
String[] startsWithFilters)
Retrieves a sorted map of metrics by names.
|
static NodeInfo |
getNodeInfo()
Retrieves information about this network node.
|
static SystemInfo |
getSystemInfo()
Retrieves information about the operating system and the JVM.
|
static SystemStatus |
getSystemStatus()
Retrieves the current system status, consisting of the operating system and JVM statuses.
|
static SortedMap<String,com.codahale.metrics.Timer> |
getTimersByNames()
Retrieves a sorted map of timers by names.
|
static SortedMap<String,com.codahale.metrics.Timer> |
getTimersByNames(boolean appendPrefix)
Retrieves a sorted map of timers by names.
|
static SortedMap<String,com.codahale.metrics.Timer> |
getTimersByNames(boolean appendPrefix,
String[] startsWithFilters)
Retrieves a sorted map of timers by names.
|
static TomcatStatus |
getTomcatStatus()
Retrieves the current status for Tomcat's executors and connectors.
|
static void |
registerHealthCheck(String name,
com.codahale.metrics.health.HealthCheck healthCheck)
Registers a health check.
|
protected static void |
reloadConfig() |
static void |
removeAllHealthChecks()
Removes all registered health checks.
|
static void |
removeAllMetrics()
Removes all registered metrics.
|
static void |
removeHealthCheck(String name)
Removes a health check, effectively voiding its registration with the MonitoringCenter.
|
static void |
reportMetricsToConsole()
Outputs all registered metrics to the standard output stream (System.out).
|
static void |
reportMetricsToLogger(org.slf4j.Logger logger)
Outputs all registered metrics to an SLF4J logger.
|
static com.codahale.metrics.health.HealthCheck.Result |
runHealthCheck(String name)
Executes a health check and returns its result.
|
static SortedMap<String,com.codahale.metrics.health.HealthCheck.Result> |
runHealthChecks()
Executes all registered health checks and returns their results.
|
static void |
shutdown()
Shuts the MonitoringCenter down, causing a cascading shutdown on all objects owned by this class.
|
public static void configure(MonitoringCenterConfig config)
Configurator. This method should be called prior to any other calls to this class.config - MonitoringCenter configuration.IllegalStateException - if the MonitoringCenter has already been configured.public static MetricCollector getMetricCollector(Class<?> clazz, String... namespaces)
MetricCollector with a given namespace. The metric collector's namespace will be constructed
from the simple name of the provided class and the optional additional namespaces.
MetricNamingUtil.join(String, String...).
configure(MonitoringCenterConfig)
has not been called explicitly.clazz - class, whose simple name will serve as the main namespace for the metric collector.namespaces - supplementary namespaces to use for the metric collector.NullPointerException - if clazz is null.public static MetricCollector getMetricCollector(String mainNamespace, String... additionalNamespaces)
MetricCollector with a given namespace. The metric collector's namespace will be constructed
from the main namespace and the optional additional namespaces.
MetricNamingUtil.sanitize(String). Plus, it
cannot be one of the reserved namespaces: "system" and "tomcat". The additional namespaces will be sanitized as
described in MetricNamingUtil.join(String, String...).
configure(MonitoringCenterConfig)
has not been called explicitly.mainNamespace - main namespace.additionalNamespaces - supplementary namespaces to use for the metric collector.IllegalArgumentException - if mainNamespace is blank.public static MetricCollector getDatabaseMetricCollector(String... additionalNamespaces)
MetricNamingUtil.join(String, String...).
configure(MonitoringCenterConfig)
has not been called explicitly.additionalNamespaces - supplementary namespaces to use for the metric collector.public static SortedMap<String,com.codahale.metrics.Counter> getCountersByNames()
public static SortedMap<String,com.codahale.metrics.Counter> getCountersByNames(boolean appendPrefix)
appendPrefix - whether to append the node-specific prefix to names of metrics or not.public static SortedMap<String,com.codahale.metrics.Counter> getCountersByNames(boolean appendPrefix, String[] startsWithFilters)
MetricNamingUtil.SEPARATOR and multiple wildcards
denoted as *.
appendPrefix - whether to append the node-specific prefix to names of metrics or not.startsWithFilters - an array of filters to apply to names of metrics.public static SortedMap<String,com.codahale.metrics.Meter> getMetersByNames()
public static SortedMap<String,com.codahale.metrics.Meter> getMetersByNames(boolean appendPrefix)
appendPrefix - whether to append the node-specific prefix to names of metrics or not.public static SortedMap<String,com.codahale.metrics.Meter> getMetersByNames(boolean appendPrefix, String[] startsWithFilters)
MetricNamingUtil.SEPARATOR and multiple wildcards
denoted as *.
appendPrefix - whether to append the node-specific prefix to names of metrics or not.startsWithFilters - an array of filters to apply to names of metrics.public static SortedMap<String,com.codahale.metrics.Histogram> getHistogramsByNames()
public static SortedMap<String,com.codahale.metrics.Histogram> getHistogramsByNames(boolean appendPrefix)
appendPrefix - whether to append the node-specific prefix to names of metrics or not.public static SortedMap<String,com.codahale.metrics.Histogram> getHistogramsByNames(boolean appendPrefix, String[] startsWithFilters)
MetricNamingUtil.SEPARATOR and multiple wildcards
denoted as *.
appendPrefix - whether to append the node-specific prefix to names of metrics or not.startsWithFilters - an array of filters to apply to names of metrics.public static SortedMap<String,com.codahale.metrics.Timer> getTimersByNames()
public static SortedMap<String,com.codahale.metrics.Timer> getTimersByNames(boolean appendPrefix)
appendPrefix - whether to append the node-specific prefix to names of metrics or not.public static SortedMap<String,com.codahale.metrics.Timer> getTimersByNames(boolean appendPrefix, String[] startsWithFilters)
MetricNamingUtil.SEPARATOR and multiple wildcards
denoted as *.
appendPrefix - whether to append the node-specific prefix to names of metrics or not.startsWithFilters - an array of filters to apply to names of metrics.public static SortedMap<String,com.codahale.metrics.Gauge> getGaugesByNames()
public static SortedMap<String,com.codahale.metrics.Gauge> getGaugesByNames(boolean appendPrefix)
appendPrefix - whether to append the node-specific prefix to names of metrics or not.public static SortedMap<String,com.codahale.metrics.Gauge> getGaugesByNames(boolean appendPrefix, String[] startsWithFilters)
MetricNamingUtil.SEPARATOR and multiple wildcards
denoted as *.
appendPrefix - whether to append the node-specific prefix to names of metrics or not.startsWithFilters - an array of filters to apply to names of metrics.public static SortedMap<String,com.codahale.metrics.Metric> getMetricsByNames()
public static SortedMap<String,com.codahale.metrics.Metric> getMetricsByNames(boolean appendPrefix)
appendPrefix - whether to append the node-specific prefix to names of metrics or not.public static SortedMap<String,com.codahale.metrics.Metric> getMetricsByNames(boolean appendPrefix, String[] startsWithFilters)
MetricNamingUtil.SEPARATOR and multiple wildcards
denoted as *.
appendPrefix - whether to append the node-specific prefix to names of metrics or not.startsWithFilters - an array of filters to apply to names of metrics.public static void removeAllMetrics()
public static void reportMetricsToConsole()
public static void reportMetricsToLogger(org.slf4j.Logger logger)
logger - an SLF4J logger to output metrics to.public static void registerHealthCheck(String name, com.codahale.metrics.health.HealthCheck healthCheck)
NamingConfig.isAppendTypeToHealthCheckNames().
MetricNamingUtil.sanitize(String).
configure(MonitoringCenterConfig)
has not been called explicitly.name - name of the health check to register.healthCheck - a health check to register.NullPointerException - if healthCheck is null.IllegalArgumentException - if name is blank.public static SortedMap<String,com.codahale.metrics.health.HealthCheck.Result> runHealthChecks()
public static com.codahale.metrics.health.HealthCheck.Result runHealthCheck(String name)
NamingConfig.isAppendTypeToHealthCheckNames().
MetricNamingUtil.sanitize(String).name - name of the health check to execute.IllegalArgumentException - if name is blank.NoSuchElementException - if MonitoringCenter has not been configured or if health check could not be found.public static void removeAllHealthChecks()
public static void removeHealthCheck(String name)
NamingConfig.isAppendTypeToHealthCheckNames().
MetricNamingUtil.sanitize(String).name - name of the health check to remove.IllegalArgumentException - if name is blank.public static SystemStatus getSystemStatus()
public static TomcatStatus getTomcatStatus()
public static SystemInfo getSystemInfo()
public static NodeInfo getNodeInfo()
public static AppInfo getAppInfo()
public static void shutdown()
protected static void reloadConfig()
Copyright © 2016–2019. All rights reserved.