org.kiwiproject.dropwizard.poller.metrics.ClientPollerStatistics Maven / Gradle / Ivy
Show all versions of dropwizard-client-poller Show documentation
package org.kiwiproject.dropwizard.poller.metrics;
import org.kiwiproject.dropwizard.poller.ClientPoller;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
/**
* Defines contract for collecting basic statistics on {@link ClientPoller} instances.
*/
//TODO: Do we want to enhance this to be stats per host?
public interface ClientPollerStatistics {
/**
* Adds a new latency measurement for how long a poll took.
*
* @param millis the latency measurement
*/
void addPollLatencyMeasurement(long millis);
/**
* The average number of milliseconds it takes per poll.
*
* @return the average number of milliseconds it takes per poll
*/
double averagePollLatencyInMillis();
/**
* Increment the number of attempted polls.
*/
void incrementCount();
/**
* Number of milliseconds since the epoch that the last poll attempt was made.
*
* @return the last attempt of a poll in milliseconds
*/
Optional lastAttemptTimeInMillis();
/**
* Increment the number of successful polls.
*/
void incrementSuccessCount();
/**
* Increment the number of times polling was skipped.
*/
void incrementSkipCount();
/**
* Number of milliseconds since the epoch that the last poll attempt was skipped.
*
* @return the number of milliseconds since the last skipped poll
*/
Optional lastSkipTimeInMillis();
/**
* Increment the number of failed polls.
*
* @param message the message to use when incrementing the failure count
*/
void incrementFailureCount(String message);
/**
* Increment the number of failed polls.
*
* @param exception the exception to use when incrementing the failure count
*/
void incrementFailureCount(Throwable exception);
/**
* Number of milliseconds since the epoch that the last failure occurred. Intended to be used for time-based
* health checking of a client poller.
*
* @return the number of milliseconds since the last failed poll
*/
Optional lastFailureTimeInMillis();
/**
* Returns a {@link Stream} over recent timestamps of poll failures.
*
* The implementation determines the limit of the number failures that may be retained and thus returned in the stream.
* Clients can use stream methods like {@link Stream#limit(long)} to specify a limit of their choosing, which may be
* smaller or larger than the implementation's internal maximum. See {@link #maxRecentFailureTimes()}.
*
* @return a stream of the most recent times the poll has failed
*/
Stream recentFailureTimesInMillis();
/**
* Returns a {@link Stream} of Map<String, Object> of error attributes for recent poll failures
*
* The implementation should return a number of failure details less than or equal to the number returned from
* recentFailureTimesInMillis. Clients can use stream methods like {@link Stream#limit(long)} to specify a limit
* of their choosing, which may be smaller or larger than the implementation's internal maximum.
* See {@link #maxRecentFailureTimes()}.
*
* @return a stream of the information about the most recent polling failures
*/
Stream