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

Fields
Modifier and Type
Field
Description
`private String`
`collectorURL`
URL to the collection point.
`private String`
`dateTimeFormat`
Formatting string for `DateFormat` fields.
`static final String`
`DEFAULT_DT_FORMAT`
Default date/time format string.
`private final TimeUnit`
`durationUnit`
Duration unit.
`private org.apache.hc.client5.http.classic.HttpClient`
`httpClient`
HTTP Client used to post the data.
`private HttpClientSecurityParameters`
`httpClientSecurityParameters`
HTTP client security parameters.
`private boolean`
`isInitialized`
Whether this component has been initialized.
`private com.fasterxml.jackson.databind.ObjectMapper`
`jsonMapper`
JSON object mapper to produce output.
`private final org.slf4j.Logger`
`log`
Class logger.
`private final com.codahale.metrics.MetricFilter`
`metricFilter`
Filter to apply.
`private final com.codahale.metrics.MetricRegistry`
`metricRegistry`
Registry of metrics.
`private final TimeUnit`
`rateUnit`
Rate unit.

## Constructor Summary

Constructors
Constructor
Description
`HTTPReporter(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 Type
Method
Description
`private org.apache.hc.client5.http.protocol.HttpClientContext`
`buildHttpContext(org.apache.hc.core5.http.HttpRequest request)`
Build the `HttpClientContext` instance to be used by the HttpClient.
`private final void`
`doSetterPreconditions()`
Helper for a setter method to check the standard preconditions.
`void`
`initialize()`
`boolean`
`isInitialized()`
`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 the `DateFormat` formatting string to apply when writing `DateFormat`-valued fields.
`void`
`setHttpClient(org.apache.hc.client5.http.classic.HttpClient client)`
Set the `HttpClient` to use.
`void`
`setHttpClientSecurityParameters(HttpClientSecurityParameters params)`
Set the optional client security parameters.
`void`
`stop()`

### Methods inherited from class com.codahale.metrics.ScheduledReporter

`close, convertDuration, convertRate, getDisabledMetricAttributes, getDurationUnit, getRateUnit, getScheduledFuture, getScheduledFuture, isShutdownExecutorOnStop, start, start`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_DT_FORMAT

@Nonnull @NotEmpty public static final String DEFAULT_DT_FORMAT
Default date/time format string.

See Also:
  - Constant Field Values

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

### metricRegistry

@Nonnull private final com.codahale.metrics.MetricRegistry metricRegistry
Registry of metrics.

### metricFilter

@Nonnull private final com.codahale.metrics.MetricFilter metricFilter
Filter to apply.

### rateUnit

@Nonnull private final TimeUnit rateUnit
Rate unit.

### durationUnit

@Nonnull private final TimeUnit durationUnit
Duration unit.

### httpClient

@NonnullAfterInit private org.apache.hc.client5.http.classic.HttpClient httpClient
HTTP Client used to post the data.

### collectorURL

@NonnullAfterInit @NotEmpty private String collectorURL
URL to the collection point.

### httpClientSecurityParameters

@Nullable private HttpClientSecurityParameters httpClientSecurityParameters
HTTP client security parameters.

### jsonMapper

@NonnullAfterInit private com.fasterxml.jackson.databind.ObjectMapper jsonMapper
JSON object mapper to produce output.

### dateTimeFormat

@Nullable private String dateTimeFormat
Formatting string for `DateFormat` fields.

### isInitialized

private boolean isInitialized
Whether 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 report
  `name` - the reporter name
  `filter` - 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 report
  `name` - the reporter name
  `filter` - filter to apply
  `rUnit` - unit to apply to rate information
  `dUnit` - 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 report
  `name` - the reporter name
  `filter` - filter to apply
  `rUnit` - unit to apply to rate information
  `dUnit` - unit to apply to duration information
  `executor` - task scheduler

## Method Details

### setHttpClient

public void setHttpClient(@Nonnull org.apache.hc.client5.http.classic.HttpClient client)
Set the `HttpClient` to use.

Parameters:
  `client` - client to use

### setCollectorURL

public void setCollectorURL(@Nonnull @NotEmpty String url)
Set the collection point to supply the data to.

Parameters:
  `url` - URL to post data to

### setHttpClientSecurityParameters

public void setHttpClientSecurityParameters(@Nullable HttpClientSecurityParameters params)
Set the optional client security parameters.

Parameters:
  `params` - the new client security parameters

### setDateTimeFormat

public void setDateTimeFormat(@Nullable @NotEmpty String format)
Set the `DateFormat` formatting string to apply when writing `DateFormat`-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:
  `isInitialized` in interface `InitializableComponent`

### initialize

public void initialize() throws ComponentInitializationException

Specified by:
  `initialize` in interface `InitializableComponent`
Throws:
  `ComponentInitializationException`

### stop

public void stop()

Overrides:
  `stop` in class `com.codahale.metrics.ScheduledReporter`

### report

public void report()

Overrides:
  `report` in class `com.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 class `com.codahale.metrics.ScheduledReporter`

### buildHttpContext

@Nonnull private org.apache.hc.client5.http.protocol.HttpClientContext buildHttpContext(@Nonnull org.apache.hc.core5.http.HttpRequest request)
Build the `HttpClientContext` instance to be used by the HttpClient.

Parameters:
  `request` - the HTTP client request
Returns:
  the client context instance