ekg-prometheus-adapter 0.1.0.1 → 0.1.0.2
raw patch · 3 files changed
+17/−12 lines, 3 filesdep +microlens-thdep ~transformersPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: microlens-th
Dependency ranges changed: transformers
API changes (from Hackage documentation)
- System.Remote.Monitoring.Prometheus: [labels] :: AdapterOptions -> Labels
- System.Remote.Monitoring.Prometheus: [namespace] :: AdapterOptions -> Maybe Text
- System.Remote.Monitoring.Prometheus: [samplingFrequency] :: AdapterOptions -> !Int
+ System.Remote.Monitoring.Prometheus: [_labels] :: AdapterOptions -> Labels
+ System.Remote.Monitoring.Prometheus: [_namespace] :: AdapterOptions -> Maybe Text
+ System.Remote.Monitoring.Prometheus: [_samplingFrequency] :: AdapterOptions -> !Int
Files
LICENSE view
@@ -1,4 +1,4 @@-Copyright Author name here (c) 2016+Copyright Alfredo Di Napoli (c) 2016 All rights reserved.
ekg-prometheus-adapter.cabal view
@@ -1,5 +1,5 @@ name: ekg-prometheus-adapter-version: 0.1.0.1+version: 0.1.0.2 synopsis: Easily expose your EKG metrics to Prometheus description: Please see README.md homepage: https://github.com/adinapoli/ekg-prometheus-adapter#readme@@ -15,14 +15,15 @@ library hs-source-dirs: src- exposed-modules: System.Remote.Monitoring.Prometheus+ exposed-modules: System.Remote.Monitoring.Prometheus build-depends: base >= 4.7 && < 5 , prometheus < 0.5.0 , ekg-core < 0.2.0.0 , unordered-containers < 0.3.0.0 , containers < 0.6.0.0 , text < 1.3.0.0- , transformers+ , transformers < 0.6.0.0+ , microlens-th < 0.5.0.0 default-language: Haskell2010 test-suite tests
src/System/Remote/Monitoring/Prometheus.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TupleSections #-} module System.Remote.Monitoring.Prometheus ( toPrometheusRegistry@@ -15,6 +16,7 @@ import qualified Data.HashMap.Strict as HMap import qualified Data.Map.Strict as Map import Data.Monoid+import Lens.Micro.TH import qualified Data.Text as T import qualified System.Metrics as EKG import qualified System.Metrics.Prometheus.Metric.Counter as Counter@@ -25,12 +27,14 @@ -------------------------------------------------------------------------------- data AdapterOptions = AdapterOptions {- labels :: Prometheus.Labels- , namespace :: Maybe T.Text- , samplingFrequency :: !Int+ _labels :: Prometheus.Labels+ , _namespace :: Maybe T.Text+ , _samplingFrequency :: !Int -- ^ How often update the registry (in seconds). } +makeLenses ''AdapterOptions+ -------------------------------------------------------------------------------- data Metric = C Counter.Counter@@ -48,7 +52,7 @@ (r, mmap) <- liftIO $ toPrometheusRegistry' store opts liftIO $ forkIO $ do let loop = forever $ do- threadDelay (samplingFrequency opts * 10^6)+ threadDelay (_samplingFrequency opts * 10^6) updateMetrics store opts mmap loop loop@@ -68,14 +72,14 @@ -------------------------------------------------------------------------------- mkMetric :: AdapterOptions -> (Prometheus.Registry, MetricsMap) -> (T.Text, EKG.Value) -> IO (Prometheus.Registry, MetricsMap) mkMetric AdapterOptions{..} (oldRegistry, mmap) (key, value) = do- let k = mkKey namespace key+ let k = mkKey _namespace key case value of EKG.Counter c -> do- (counter, newRegistry) <- Prometheus.registerCounter k labels oldRegistry+ (counter, newRegistry) <- Prometheus.registerCounter k _labels oldRegistry Counter.add (fromIntegral c) counter return $! (newRegistry, Map.insert k (C counter) $! mmap) EKG.Gauge g -> do- (gauge, newRegistry) <- Prometheus.registerGauge k labels oldRegistry+ (gauge, newRegistry) <- Prometheus.registerGauge k _labels oldRegistry Gauge.set (fromIntegral g) gauge return $! (newRegistry, Map.insert k (G gauge) $! mmap) EKG.Label _ -> return $! (oldRegistry, mmap)@@ -96,7 +100,7 @@ -------------------------------------------------------------------------------- updateMetric :: AdapterOptions -> MetricsMap -> (T.Text, EKG.Value) -> IO MetricsMap updateMetric AdapterOptions{..} mmap (key, value) = do- let k = mkKey namespace key+ let k = mkKey _namespace key case liftM2 (,) (Map.lookup k mmap) (Just value) of Just (C counter, EKG.Counter c) -> do (Counter.CounterSample oldCounterValue) <- Counter.sample counter