:warning: As of September 2021, this project's maintainer, @raskasa, has not been able to use this project in production for a number of years. As a result, active development has stalled; it will likely remain stalled moving forward unless the opportunity arises again for the maintainer to use it in production.
An OkHttp HTTP client wrapper providing Metrics instrumentation of connection pools, request durations and rates, and other useful information.
Metrics Integration for OkHttp provides InstrumentedOkHttpClients
, a static
factory class for instrumenting OkHttp HTTP clients.
You can create an instrumented OkHttpClient
by doing the following:
MetricRegistry registry = ...;
OkHttpClient client = InstrumentedOkHttpClients.create(registry);
If you wish to provide your own OkHttpClient
instance, you can do that as well:
MetricRegistry registry = ...;
OkHttpClient rawClient = ...;
OkHttpClient client = InstrumentedOkHttpClients.create(registry, rawClient);
If you use more than one OkHttpClient instance in your application, you may want to provide a custom name when instrumenting the clients in order to properly distinguish them:
MetricRegistry registry = ...;
OkHttpClient client = InstrumentedOkHttpClients.create(registry, "custom-name");
MetricRegistry registry = ...;
OkHttpClient rawClient = ...;
OkHttpClient client = InstrumentedOkHttpClients.create(registry, rawClient, "custom-name");
An instrumented OkHttp HTTP client provides the following metrics:
okhttp3.EventListener.calls-duration
okhttp3.EventListener.calls-end
okhttp3.EventListener.calls-failed
okhttp3.EventListener.calls-start
okhttp3.EventListener.connections-acquired
okhttp3.EventListener.connections-duration
okhttp3.EventListener.connections-end
okhttp3.EventListener.connections-failed
okhttp3.EventListener.connections-released
okhttp3.EventListener.connections-start
okhttp3.EventListener.dns-duration
okhttp3.EventListener.dns-end
okhttp3.EventListener.dns-start
okhttp3.OkHttpClient.cache-request-count
okhttp3.OkHttpClient.cache-hit-count
okhttp3.OkHttpClient.cache-network-count
okhttp3.OkHttpClient.cache-current-size
okhttp3.OkHttpClient.cache-max-size
okhttp3.OkHttpClient.cache-size
okhttp3.OkHttpClient.cache-write-success-count
okhttp3.OkHttpClient.cache-write-abort-count
okhttp3.OkHttpClient.connection-pool-count
okhttp3.OkHttpClient.connection-pool-count-http
okhttp3.OkHttpClient.connection-pool-count-multiplexed
okhttp3.OkHttpClient.connection-pool-idle-count
okhttp3.OkHttpClient.connection-pool-total-count
okhttp3.OkHttpClient.network-requests-completed
okhttp3.OkHttpClient.network-requests-duration
okhttp3.OkHttpClient.network-requests-running
okhttp3.OkHttpClient.network-requests-submitted
If you provide a custom name for the instrumented client (i.e. custom-name
),
the metrics will have the following format:
...
okhttp3.OkHttpClient.custom-name.cache-write-success-count
okhttp3.OkHttpClient.custom-name.cache-write-abort-count
okhttp3.OkHttpClient.custom-name.connection-pool-count
...
Metrics Integration for OkHttp is currently under development. The API is not stable and neither is the feature set.
Download the latest jar or depend on Maven:
<dependency>
<groupId>com.raskasa.metrics</groupId>
<artifactId>metrics-okhttp</artifactId>
<version>0.5.0</version>
</dependency>
or Gradle:
compile 'com.raskasa.metrics:metrics-okhttp:0.5.0'
Snapshots of the development version are available in
Sonatype's snapshots
repository.
Copyright 2015 Ras Kasa Williams
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.