Interface MonitoringStatistics
public interface MonitoringStatistics
Monitoring statistics return statistic information about application run like number of requests received,
duration of request processing, number of successfully processed requests, statistical information about
execution of methods and resources, information about matching.
Monitoring statistics is the main interface from which all statistic information can be retrieved. Statistics
can be retried in two ways: these can be injected or received from registered callback
interface
MonitoringStatisticsListener
. The following is the example of statistic injection:
@Path("resource") public static class StatisticsTest { @Inject Provider<MonitoringStatistics> statistics; @GET public long getTotalExceptionMappings() throws InterruptedException { final MonitoringStatistics monitoringStatistics = statistics.get(); final long totalExceptionMappings = monitoringStatistics.getExceptionMapperStatistics().getTotalMappings(); return totalExceptionMappings; } }Note usage of
Provider
to retrieve statistics. Statistics change over time and this will
inject the latest statistics. In the case of singleton resources usage of Provider
is the only way how
to inject statistics that are up to date.
Retrieving statistics by MonitoringStatisticsListener
is convenient in cases when there is a need
to take an action only when new statistics are calculated which occurs in not defined irregular intervals
(once per second for example).
The contract does not mandate MonitoringStatistics
to be immutable. Implementation of monitoring statistics
might be mutable, which means that an instance of MonitoringStatistics
might change its internal state over time. In order to get immutable snapshot of statistics
the method snapshot()
must be called to get a snapshot of the statistics that guarantees
that data to be immutable and consistent. Nested statistics interfaces contain also snapshot
method which
can be used in the same way.
Note that a snapshot of MonitoringStatistics
performs a deep snapshot of nested statistics object too, so there
is no need to call the snapshot
method again on nested statistics components.
The implementation of this interface may be mutable and change it's state by an external event, however it is guaranteed to be thread-safe.
- Author:
- Miroslav Fuksa
-
Method Summary
Modifier and TypeMethodDescriptionGet statistics about registeredexception mappers
.Get the global application statistics of request execution.Get the statistics for each resourceClass
that is deployed in the application.Get global application response statistics.Get the statistics for each URI that is exposed in the application.snapshot()
Deprecated.implementing class is immutable hence snapshot creation is not needed anymore
-
Method Details
-
getUriStatistics
Map<String,ResourceStatistics> getUriStatistics()Get the statistics for each URI that is exposed in the application. Keys of returned map are String URIs (for example "/bookstore/users/admin") and values areresource statistics
that contain information about execution of resource methods available on the URI. The map contain URIs that are available in application without URIs available in sub resource locators and URIs that are available trough sub resource locators and were already matched by any request.- Returns:
- Map with URI keys and resource statistics values.
-
getResourceClassStatistics
Map<Class<?>,ResourceStatistics> getResourceClassStatistics()Get the statistics for each resourceClass
that is deployed in the application. Keys of returned map are classes of resources and values areresource statistics
that contain information about execution of resource methods available in the resource class. Note that one resource class can serve request matched to different URIs. By default the map will contain resource classes which are registered in the resource model plus resource classes of sub resources returned from sub resource locators.- Returns:
- Map with resource class keys and resource statistics values.
-
getRequestStatistics
ExecutionStatistics getRequestStatistics()Get the global application statistics of request execution. The statistics are not bound any specific resource or resource method and contains information about all requests that application handles.- Returns:
- Application request execution statistics.
-
getResponseStatistics
ResponseStatistics getResponseStatistics()Get global application response statistics. The statistics are not bound any specific resource or resource method and contains information about all responses that application creates.- Returns:
- Application response statistics.
-
getExceptionMapperStatistics
ExceptionMapperStatistics getExceptionMapperStatistics()Get statistics about registeredexception mappers
.- Returns:
- Exception mapper statistics.
-
snapshot
Deprecated.implementing class is immutable hence snapshot creation is not needed anymoreGet the immutable consistent snapshot of the monitoring statistics. Working with snapshots might have negative performance impact as snapshot must be created but ensures consistency of data over time. However, the usage of snapshot is encouraged to avoid working with inconsistent data. Not all statistics must be updated in the same time on mutable version of statistics.- Returns:
- Snapshot of monitoring statistics.
-