GithubHelp home page GithubHelp logo

idiotech / finagle-prometheus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from samstarling/finagle-prometheus

0.0 1.0 0.0 142 KB

Provides a bridge between Finagle and Prometheus metrics

Home Page: https://samstarling.co.uk/projects/finagle-prometheus/

License: MIT License

Scala 100.00%

finagle-prometheus's Introduction

finagle-prometheus

Build Status Coverage Status

finagle-prometheus is a library that provides a bridge between Finagle and Prometheus. It contains everything you need to get metrics from a Finagle application into Prometheus.

Getting started

The library is available in Maven Central, for both Scala 2.12 and 2.13, so just add the following dependency:

"com.samstarling" %% "finagle-prometheus" % "0.0.8"

Usage

Exposing metrics

The MetricsService exposes all metrics over HTTP in the format that Prometheus expects when collecting metrics. All it needs is a CollectorRegistry:

val registry = CollectorRegistry.defaultRegistry
val metricsService = new MetricsService(registry)

You can then mount this service alongside your other HTTP handlers, and configure Prometheus to scrape that endpoint.

Existing Finagle metrics

Finagle exposes a lot of metrics internally. They are reported to a default StatsReceiver. You can replace this with the PrometheusStatsReceiver, which will transform the Finagle metrics into Prometheus metrics, and register them with the given CollectorRegistry.

Create one like this:

val registry = CollectorRegistry.defaultRegistry
val statsReceiver = new PrometheusStatsReceiver(registry)

And use it (for example) when building a Client:

Http.client
    .withTls("api.github.com")
    .withStatsReceiver(statsReceiver)
    .withHttpStats
    .configured(LoadBalancerFactory.HostStats(statsReceiver.scope("host")))
    .newService("api.github.com:443", "GitHub")

The best thing you can do is use the PrometheusStatsReceiver by default. To do this, create a file at resources/META-INF/services/com.twitter.finagle.stats.StatsReceiver with the following contents:

com.samstarling.prometheusfinagle.PrometheusStatsReceiver

The default constructor for the class will be used. This behaviour is documented in Finagle's Resolver class, as well as in the util-stats documentation. For full documentation of the metrics exposed, and what they mean, see the Metrics page on the Finagle documentation site.

Custom metrics

To expose your own metrics (with labels), use the Telemetry class. You can see this in action in the CustomTelemetryService example.

val registry = CollectorRegistry.defaultRegistry
val telemetry = new Telemetry(registry, "namespace")

val counter = telemetry.counter(
    "requests_by_day_of_week",
    "Help text",
    Seq("day_of_week"))

counter.labels(dayOfWeek).inc()

Filters

The library provides some existing filters that you can add to your service. At the moment, they only relate to HTTP. The metrics they export are entirely separate from existing Finagle metrics. The following filters exist:

  • HttpMonitoringFilter: gives metrics relating to the number of HTTP responses, including status code and HTTP method.
  • HttpLatencyMonitoringFilter: gives metrics relating to the latency of HTTP responses, including status code and HTTP method.

Note: your service must be of the type Service[http.Request, http.Response].

finagle-prometheus's People

Contributors

samstarling avatar spockz avatar hderms avatar justinvenus avatar diebauer avatar yarektyshchenko avatar ben-healthforge avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.