A decorator wrapping Feign client method handlers in order to provide metrics of calls to feign target interfaces.
Branch: master
Clone or download
Matthias Wiedeman
Matthias Wiedeman fixing CVE-2017-7525
Latest commit b631a73 Oct 16, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore added iml to ignore Feb 19, 2018
.travis.yml renamed travis file Oct 26, 2017
LICENSE Initial commit Oct 25, 2017
README.md Update README.md Sep 10, 2018
pom.xml fixing CVE-2017-7525 Oct 16, 2018

README.md

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

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>2.0</version>
</dependency>