Metrics Integration for OkHttp

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

Categories

Categories

Metrics Application Testing & Monitoring Monitoring
GroupId

GroupId

com.raskasa.metrics
ArtifactId

ArtifactId

metrics-okhttp
Last Version

Last Version

0.4.0
Release Date

Release Date

Type

Type

jar
Description

Description

Metrics Integration for OkHttp
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

Download metrics-okhttp

How to add to project

<!-- https://jarcasting.com/artifacts/com.raskasa.metrics/metrics-okhttp/ -->
<dependency>
    <groupId>com.raskasa.metrics</groupId>
    <artifactId>metrics-okhttp</artifactId>
    <version>0.4.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.raskasa.metrics/metrics-okhttp/
implementation 'com.raskasa.metrics:metrics-okhttp:0.4.0'
// https://jarcasting.com/artifacts/com.raskasa.metrics/metrics-okhttp/
implementation ("com.raskasa.metrics:metrics-okhttp:0.4.0")
'com.raskasa.metrics:metrics-okhttp:jar:0.4.0'
<dependency org="com.raskasa.metrics" name="metrics-okhttp" rev="0.4.0">
  <artifact name="metrics-okhttp" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.raskasa.metrics', module='metrics-okhttp', version='0.4.0')
)
libraryDependencies += "com.raskasa.metrics" % "metrics-okhttp" % "0.4.0"
[com.raskasa.metrics/metrics-okhttp "0.4.0"]

Dependencies

compile (2)

Group / Artifact Type Version
io.dropwizard.metrics : metrics-core jar 3.2.3
com.squareup.okhttp3 : okhttp jar 3.8.1

test (5)

Group / Artifact Type Version
com.google.guava : guava jar 22.0-android
junit : junit jar 4.12
org.assertj : assertj-core jar 2.8.0
org.mockito : mockito-core jar 1.10.19
com.squareup.okhttp3 : mockwebserver jar 3.8.1

Project Modules

There are no modules declared in this project.

Metrics Integration for OkHttp

An OkHttp HTTP client wrapper providing Metrics instrumentation of connection pools, request durations and rates, and other useful information.

Usage

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.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.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
...

Download

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.4.0</version>
</dependency>

or Gradle:

compile 'com.raskasa.metrics:metrics-okhttp:0.4.0'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

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.

Versions

Version
0.4.0
0.2.0
0.1.0