servant-prometheus: Helpers for using prometheus with servant

[ bsd3, library, servant, system, web ] [ Propose Tags ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.0.0, 1.1.0, 1.2.0
Change log CHANGELOG.md
Dependencies base (>=4.10 && <4.18), clock (>=0.8.3 && <0.9), ghc-prim (>=0.8.0 && <0.10), hashable (>=1.4.2 && <1.5), http-types (>=0.12.3 && <0.13), prometheus-client (>=1.1.0 && <1.2), servant (>=0.14 && <0.20), text (>=1.2.5 && <2.1), wai (>=3.2.3 && <3.3) [details]
License BSD-3-Clause
Author Andrii Demydenko <worm2fed@gmail.com>, Anchor Engineering <engineering@lists.anchor.net.au>, Servant Contributors
Maintainer Andrii Demydenko <worm2fed@gmail.com>
Category Servant, Web, System
Home page https://github.com/worm2fed/servant-prometheus#readme
Bug tracker https://github.com/worm2fed/servant-prometheus/issues
Source repo head: git clone https://github.com/worm2fed/servant-prometheus
Uploaded by worm2fed at 2023-12-15T23:46:08Z
Distributions
Downloads 107 total (14 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for servant-prometheus-1.2.0

[back to package description]

servant-prometheus

Build status Hackage

Servant Performance Counters

This package lets you track performance counters for each of your Servant endpoints using Prometheus.

Usage

servant-prometheus knows how to handle all official Servant combinators out of the box.

Instrumenting your API

To use servant-prometheus, you'll need to wrap your WAI application with the provided middleware.

import Network.Wai.Handler.Warp
import Prometheus.Servant

main :: IO ()
main = do
  let api    = ...
      server = ...
      app = prometheusMiddleware defaultMetrics api server

  run 8080 app

Custom metrics

Note, that in example above defaultMetrics used, which actually provided as an example and good starting point. If you want to use your custom metrics (eg you want another labels), you'll need to define an implementation for Metrics mLatencyLabel mActiveLabel data. That's not hard, just copy-paste and tweak accordingly to your needs.

Runtime overhead

Instrumenting your API introduces a non-zero runtime overhead, on the order of 200 - 600 µsec depending upon your machine. It's a good idea to run the benchmarks on your intended production platform to get an idea of how large the overhead will be. You'll need to have wrk installed to run the benchmarks.

In general, the runtime overhead should be effectively negligible if your handlers are issuing network requests, such as to databases. If you have handlers that are small, CPU-only, and requested frequently, you will see a performance hit from servant-prometheus.