Package net.shibboleth.idp.metrics.impl
Class HTTPReporter
java.lang.Object
com.codahale.metrics.ScheduledReporter
net.shibboleth.idp.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 String
URL to the collection point.private String
Formatting string forDateFormat
fields.static final String
Default date/time format string.private final TimeUnit
Duration unit.private org.apache.http.client.HttpClient
HTTP Client used to post the data.private HttpClientSecurityParameters
HTTP client security parameters.private boolean
Whether this component has been initialized.private com.fasterxml.jackson.databind.ObjectMapper
JSON object mapper to produce output.private final org.slf4j.Logger
Class logger.private final com.codahale.metrics.MetricFilter
Filter to apply.private final com.codahale.metrics.MetricRegistry
Registry of metrics.private final TimeUnit
Rate 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.http.client.protocol.HttpClientContext
buildHttpContext
(org.apache.http.client.methods.HttpUriRequest request) Build theHttpClientContext
instance to be used by the HttpClient.void
boolean
void
report()
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) void
setCollectorURL
(String url) Set the collection point to supply the data to.void
setDateTimeFormat
(String format) Set theDateFormat
formatting string to apply when writingDateFormat
-valued fields.void
setHttpClient
(org.apache.http.client.HttpClient client) Set theHttpClient
to use.void
Set the optional client security parameters.void
stop()
Methods inherited from class com.codahale.metrics.ScheduledReporter
close, convertDuration, convertRate, getDisabledMetricAttributes, getDurationUnit, getRateUnit, 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 forDateFormat
fields. -
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.http.client.HttpClient client) Set theHttpClient
to 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 theDateFormat
formatting string to apply when writingDateFormat
-valued fields.- Parameters:
format
- formatting string
-
isInitialized
public boolean isInitialized()- Specified by:
isInitialized
in interfaceInitializableComponent
-
initialize
- Specified by:
initialize
in interfaceInitializableComponent
- Throws:
ComponentInitializationException
-
stop
public void stop()- Overrides:
stop
in classcom.codahale.metrics.ScheduledReporter
-
report
public void report()- Overrides:
report
in 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:
report
in classcom.codahale.metrics.ScheduledReporter
-
buildHttpContext
@Nonnull private org.apache.http.client.protocol.HttpClientContext buildHttpContext(@Nonnull org.apache.http.client.methods.HttpUriRequest request) Build theHttpClientContext
instance to be used by the HttpClient.- Parameters:
request
- the HTTP client request- Returns:
- the client context instance
-