Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adinapoli/ekg-prometheus-adapter
Experiments in mapping an EKG Store into a Prometheus Registry
https://github.com/adinapoli/ekg-prometheus-adapter
Last synced: 23 days ago
JSON representation
Experiments in mapping an EKG Store into a Prometheus Registry
- Host: GitHub
- URL: https://github.com/adinapoli/ekg-prometheus-adapter
- Owner: adinapoli
- License: bsd-3-clause
- Created: 2016-10-17T17:28:07.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-08-22T10:15:56.000Z (3 months ago)
- Last Synced: 2024-09-23T12:15:20.643Z (about 1 month ago)
- Language: Haskell
- Size: 17.6 KB
- Stars: 10
- Watchers: 2
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## ekg-prometheus-adapter
Simple library which maps an EKG's `Store` into a [prometheus](http://hackage.haskell.org/package/prometheus)'s `Registry`,
also exposing a function to "inject" the newly created `Registry` into your `RegistryT` computation.### Example
The following example demonstrates how you can use this library to expose to Prometheus various
GHC RTS's metrics whilst still defining your application-specific metrics.``` haskell
{-# LANGUAGE OverloadedStrings #-}
module Main whereimport Control.Concurrent (threadDelay, forkIO)
import Control.Monad
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Class
import Control.Monad.Trans.State.Strict
import GHC.Conc (numSparks, getNumCapabilities, getNumProcessors)
import qualified System.Metrics as EKG
import System.Metrics.Prometheus.Concurrent.Http (serveHttpTextMetrics)
import System.Metrics.Prometheus.Metric.Counter (add, inc)
import System.Metrics.Prometheus.MetricId
import System.Metrics.Prometheus.Registry (Registry, RegistrySample)
import System.Metrics.Prometheus.RegistryT
import System.Random
import System.Remote.Monitoring.Prometheus (registerEKGStore, defaultOptions)mkRegistry store port = do
runRegistryT $ do
registerEKGStore store (defaultOptions $ fromList [("ghc", "rts")])-- Labels can be defined as lists or added to an empty label set
connectSuccessGauge <- registerGauge "example_connections" (fromList [("login", "success")])
connectFailureGauge <- registerGauge "example_connections" (addLabel "login" "failure" mempty)
connectCounter <- registerCounter "example_connection_total" mempty
latencyHistogram <- registerHistogram "example_round_trip_latency_ms" mempty [10, 20..100]liftIO $ forkIO $ do
let loop = forever $ do
threadDelay (5 * 10^6)
v <- randomRIO (1,5)
add v connectCounter
loop
loopsample >>= serveHttpTextMetrics port ["metrics"]
main :: IO ()
main = do
store <- EKG.newStore
EKG.registerGcMetrics store
-- Add GHC.Conc metrics
EKG.registerGauge "ghc.conc.num_sparks" (fromIntegral <$> numSparks) store
EKG.registerCounter "ghc.conc.num_capabilities" (fromIntegral <$> getNumCapabilities) store
EKG.registerCounter "ghc.conc.num_processors" (fromIntegral <$> getNumProcessors) store
_ <- mkRegistry store 8080
return ()
```