Package org.opensaml.core.metrics.impl
Class HTTPReporter
java.lang.Object
com.codahale.metrics.ScheduledReporter
org.opensaml.core.metrics.impl.HTTPReporter
- All Implemented Interfaces:
com.codahale.metrics.Reporter,Closeable,AutoCloseable,Component,InitializableComponent
public class HTTPReporter
extends com.codahale.metrics.ScheduledReporter
implements InitializableComponent
A metrics reporter that runs at scheduled times and posts a JSON feed of metrics to a designated endpoint.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringURL to the collection point.private StringFormatting string forDateFormatfields.static final StringDefault date/time format string.private final TimeUnitDuration unit.private org.apache.hc.client5.http.classic.HttpClientHTTP Client used to post the data.private HttpClientSecurityParametersHTTP client security parameters.private booleanWhether this component has been initialized.private com.fasterxml.jackson.databind.ObjectMapperJSON object mapper to produce output.private final org.slf4j.LoggerClass logger.private final com.codahale.metrics.MetricFilterFilter to apply.private final com.codahale.metrics.MetricRegistryRegistry of metrics.private final TimeUnitRate unit. -
Constructor Summary
ConstructorsConstructorDescriptionHTTPReporter(com.codahale.metrics.MetricRegistry registry, String name, com.codahale.metrics.MetricFilter filter) Constructor.HTTPReporter(com.codahale.metrics.MetricRegistry registry, String name, com.codahale.metrics.MetricFilter filter, TimeUnit rUnit, TimeUnit dUnit) Constructor.HTTPReporter(com.codahale.metrics.MetricRegistry registry, String name, com.codahale.metrics.MetricFilter filter, TimeUnit rUnit, TimeUnit dUnit, ScheduledExecutorService executor) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate org.apache.hc.client5.http.protocol.HttpClientContextbuildHttpContext(org.apache.hc.core5.http.HttpRequest request) Build theHttpClientContextinstance to be used by the HttpClient.private final voidHelper for a setter method to check the standard preconditions.voidbooleanvoidreport()voidreport(SortedMap<String, com.codahale.metrics.Gauge> gauges, SortedMap<String, com.codahale.metrics.Counter> counters, SortedMap<String, com.codahale.metrics.Histogram> histograms, SortedMap<String, com.codahale.metrics.Meter> meters, SortedMap<String, com.codahale.metrics.Timer> timers) voidsetCollectorURL(String url) Set the collection point to supply the data to.voidsetDateTimeFormat(String format) Set theDateFormatformatting string to apply when writingDateFormat-valued fields.voidsetHttpClient(org.apache.hc.client5.http.classic.HttpClient client) Set theHttpClientto use.voidSet the optional client security parameters.voidstop()Methods inherited from class com.codahale.metrics.ScheduledReporter
close, convertDuration, convertRate, getDisabledMetricAttributes, getDurationUnit, getRateUnit, getScheduledFuture, getScheduledFuture, isShutdownExecutorOnStop, start, start
-
Field Details
-
DEFAULT_DT_FORMAT
Default date/time format string.- See Also:
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
metricRegistry
@Nonnull private final com.codahale.metrics.MetricRegistry metricRegistryRegistry of metrics. -
metricFilter
@Nonnull private final com.codahale.metrics.MetricFilter metricFilterFilter to apply. -
rateUnit
Rate unit. -
durationUnit
Duration unit. -
httpClient
HTTP Client used to post the data. -
collectorURL
URL to the collection point. -
httpClientSecurityParameters
HTTP client security parameters. -
jsonMapper
JSON object mapper to produce output. -
dateTimeFormat
Formatting string forDateFormatfields. -
isInitialized
private boolean isInitializedWhether this component has been initialized.
-
-
Constructor Details
-
HTTPReporter
public HTTPReporter(@Nonnull @ParameterName(name="registry") com.codahale.metrics.MetricRegistry registry, @Nonnull @NotEmpty @ParameterName(name="name") String name, @Nullable @ParameterName(name="filter") com.codahale.metrics.MetricFilter filter) Constructor.- Parameters:
registry- the registry of metrics to reportname- the reporter namefilter- filter to apply
-
HTTPReporter
public HTTPReporter(@Nonnull @ParameterName(name="registry") com.codahale.metrics.MetricRegistry registry, @Nonnull @NotEmpty @ParameterName(name="name") String name, @Nullable @ParameterName(name="filter") com.codahale.metrics.MetricFilter filter, @Nonnull @ParameterName(name="rUnit") TimeUnit rUnit, @Nonnull @ParameterName(name="dUnit") TimeUnit dUnit) Constructor.- Parameters:
registry- the registry of metrics to reportname- the reporter namefilter- filter to applyrUnit- unit to apply to rate informationdUnit- unit to apply to duration information
-
HTTPReporter
public HTTPReporter(@Nonnull @ParameterName(name="registry") com.codahale.metrics.MetricRegistry registry, @Nonnull @NotEmpty @ParameterName(name="name") String name, @Nullable @ParameterName(name="filter") com.codahale.metrics.MetricFilter filter, @Nonnull @ParameterName(name="rUnit") TimeUnit rUnit, @Nonnull @ParameterName(name="dUnit") TimeUnit dUnit, @Nonnull @ParameterName(name="executor") ScheduledExecutorService executor) Constructor.- Parameters:
registry- the registry of metrics to reportname- the reporter namefilter- filter to applyrUnit- unit to apply to rate informationdUnit- unit to apply to duration informationexecutor- task scheduler
-
-
Method Details
-
setHttpClient
public void setHttpClient(@Nonnull org.apache.hc.client5.http.classic.HttpClient client) Set theHttpClientto use.- Parameters:
client- client to use
-
setCollectorURL
Set the collection point to supply the data to.- Parameters:
url- URL to post data to
-
setHttpClientSecurityParameters
Set the optional client security parameters.- Parameters:
params- the new client security parameters
-
setDateTimeFormat
Set theDateFormatformatting string to apply when writingDateFormat-valued fields.- Parameters:
format- formatting string
-
doSetterPreconditions
private final void doSetterPreconditions()Helper for a setter method to check the standard preconditions. -
isInitialized
public boolean isInitialized()- Specified by:
isInitializedin interfaceInitializableComponent
-
initialize
- Specified by:
initializein interfaceInitializableComponent- Throws:
ComponentInitializationException
-
stop
public void stop()- Overrides:
stopin classcom.codahale.metrics.ScheduledReporter
-
report
public void report()- Overrides:
reportin classcom.codahale.metrics.ScheduledReporter
-
report
public void report(SortedMap<String, com.codahale.metrics.Gauge> gauges, SortedMap<String, com.codahale.metrics.Counter> counters, SortedMap<String, com.codahale.metrics.Histogram> histograms, SortedMap<String, com.codahale.metrics.Meter> meters, SortedMap<String, com.codahale.metrics.Timer> timers) - Specified by:
reportin classcom.codahale.metrics.ScheduledReporter
-
buildHttpContext
@Nonnull private org.apache.hc.client5.http.protocol.HttpClientContext buildHttpContext(@Nonnull org.apache.hc.core5.http.HttpRequest request) Build theHttpClientContextinstance to be used by the HttpClient.- Parameters:
request- the HTTP client request- Returns:
- the client context instance
-