com.github.mwiede:metrics-feign

A decorator wrapping Feign client method handlers in order to provide metrics of calls to feign target interfaces.

Лицензия

Лицензия

Категории

Категории

Feign Сеть HTTP Clients Metrics Тестирование приложения и мониторинг Monitoring
Группа

Группа

com.github.mwiede
Идентификатор

Идентификатор

metrics-feign
Последняя версия

Последняя версия

3.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

com.github.mwiede:metrics-feign
A decorator wrapping Feign client method handlers in order to provide metrics of calls to feign target interfaces.
Ссылка на сайт

Ссылка на сайт

https://github.com/mwiede/metrics-feign
Система контроля версий

Система контроля версий

https://github.com/mwiede/metrics-feign

Скачать metrics-feign

Как подключить последнюю версию

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

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
io.dropwizard.metrics : metrics-core jar 4.1.2
io.dropwizard.metrics : metrics-annotation jar 4.1.2
io.github.openfeign : feign-core jar 10.12

test (4)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.13.1
org.mockito : mockito-core jar 2.27.0
com.github.tomakehurst : wiremock jar 2.23.2
io.github.openfeign : feign-gson jar 10.12

Модули Проекта

Данный проект не имеет модулей.

metrics-feign travis status Maven Central

A decorator wrapping Feign client method handlers in order to provide Dropwizard Metrics of calls to feign target interfaces.

Usage with Feign 10

Feign offers Metrics4Capability, which gives basic metrics, but in order to use metric annotations, add com.github.mwiede.metrics.feign.AnnotionMetricsCapability like this:

  @Timed
  @Metered
  @ExceptionMetered
  @ResponseMetered
  interface GitHub {
    @RequestLine("GET /repos/{owner}/{repo}/contributors")
    List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
  }

  static class Contributor {
    String login;
    int contributions;
  }

  public static void main(final String... args) {

    final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate("feign");

    final ConsoleReporter reporter =
        ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).build();

    final GitHub github =
        Feign.builder().decoder(new GsonDecoder())
                .addCapability(new AnnotionMetricsCapability(metricRegistry))
            .target(GitHub.class, "https://api.github.com");
    try {
      // Fetch and print a list of the contributors to this library.
      final List<Contributor> contributors = github.contributors("mwiede", "metrics-feign");
      for (final Contributor contributor : contributors) {
        System.out.println(contributor.login + " (" + contributor.contributions + ")");
      }
    } finally {
      reporter.report();
    }
  }

Usage with Feign < 10.11

Basically you only have to replace Feign.builder() with FeignWithMetrics.builder(metricRegistry).

  @Timed
  @Metered
  @ExceptionMetered
  @ResponseMetered
  interface GitHub {
    @RequestLine("GET /repos/{owner}/{repo}/contributors")
    List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
  }

  static class Contributor {
    String login;
    int contributions;
  }

  public static void main(final String... args) {

    final MetricRegistry metricRegistry = new MetricRegistry();

    final ConsoleReporter reporter =
        ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).build();

    final GitHub github =
        FeignWithMetrics.builder(metricRegistry).decoder(new GsonDecoder())
            .target(GitHub.class, "https://api.github.com");
    try {
      // Fetch and print a list of the contributors to this library.
      final List<Contributor> contributors = github.contributors("mwiede", "metrics-feign");
      for (final Contributor contributor : contributors) {
        System.out.println(contributor.login + " (" + contributor.contributions + ")");
      }
    } finally {
      reporter.report();
    }
  }

List of provided metrics

Based of the example above, the following metrics were registered and reported:

Meters

  • com.github.mwiede.metrics.example.Example$GitHub.contributors.1xx-responses
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.2xx-responses
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.3xx-responses
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.4xx-responses
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.5xx-responses
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.Metered
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.exceptions
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.reAttempts.Metered
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.retryExhausted.Metered

Timers

com.github.mwiede.metrics.example.Example$GitHub.contributors.Timed

Download

You can use this library via maven:

<dependency>
  <groupId>com.github.mwiede</groupId>
  <artifactId>metrics-feign</artifactId>
  <version>3.0</version>
</dependency>

Версии библиотеки

Версия
3.0
2.0
1.0