public class MetricsRetrievalService
extends com.google.common.util.concurrent.AbstractService
MetricsRetrievalService
is used as a headless, autonomous service
which encapsulates:
ExecutorService
for fulfilling remote metric URL requests
submitRequest(MetricSourceType, StreamProvider, String)
will be available.
Metric data is cached temporarily and is controlled by
Configuration.getMetricsServiceCacheTimeout()
.
In order to control throttling requests to the same endpoint,
Configuration.isMetricsServiceRequestTTLCacheEnabled()
can be enabled
to allow for a fixed interval of time to pass between requests.Modifier and Type | Class and Description |
---|---|
static class |
MetricsRetrievalService.MetricSourceType
The type of web service hosting the metrics.
|
Constructor and Description |
---|
MetricsRetrievalService()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doStart() |
protected void |
doStop() |
JMXMetricHolder |
getCachedJMXMetric(String jmxUrl)
Gets a cached JMX metric in the form of a
JMXMetricHolder . |
Map<String,String> |
getCachedRESTMetric(String restUrl)
Gets a cached REST metric in the form of a
Map . |
void |
setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor)
Testing method for setting a synchronous
ThreadPoolExecutor . |
void |
submitRequest(MetricsRetrievalService.MetricSourceType type,
StreamProvider streamProvider,
String url)
Submit a
Runnable for execution which retrieves metric data from
the supplied endpoint. |
protected void doStart()
doStart
in class com.google.common.util.concurrent.AbstractService
public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor)
ThreadPoolExecutor
.threadPoolExecutor
- protected void doStop()
doStop
in class com.google.common.util.concurrent.AbstractService
public void submitRequest(MetricsRetrievalService.MetricSourceType type, StreamProvider streamProvider, String url)
Runnable
for execution which retrieves metric data from
the supplied endpoint. This will run inside of an ExecutorService
to retrieve metric data from a URL endpoint and parse the result into a
cached value.
Once metric data is retrieved it is cached. Data in the cache can be
retrieved via getCachedJMXMetric(String)
or
getCachedRESTMetric(String)
, depending on the type of metric
requested.
Callers need not worry about invoking this multiple times for the same URL
endpoint. A single endpoint will only be enqueued once regardless of how
many times this method is called until it has been fully retrieved and
parsed. If the last endpoint request was too recent, then this method will
opt to not make another call until the TTL period expires.type
- the type of service hosting the metric (not null
).streamProvider
- the StreamProvider
to use to read from the remote
endpoint.url
- the URL to read fromgetCachedJMXMetric(String)
public JMXMetricHolder getCachedJMXMetric(String jmxUrl)
JMXMetricHolder
. If there
is no metric data cached for the given URL, then null
is returned.
The onky way this cache is populated is by requesting the data to be loaded
asynchronously via
submitRequest(MetricSourceType, StreamProvider, String)
with the
MetricsRetrievalService.MetricSourceType.JMX
type.jmxUrl
- the URL to retrieve cached data for (not null
).null
if none.public Map<String,String> getCachedRESTMetric(String restUrl)
Map
. If there is no
metric data cached for the given URL, then null
is returned.
The only way this cache is populated is by requesting the data to be loaded
asynchronously via
submitRequest(MetricSourceType, StreamProvider, String)
with the
MetricsRetrievalService.MetricSourceType.REST
type.restUrl
- the URL to retrieve cached data for (not null
).null
if none.Copyright © 2022 Apache Software Foundation. All rights reserved.