ekg-statsd 0.1.0.0 → 0.2.0.0
raw patch · 3 files changed
+53/−9 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ System.Remote.Monitoring.Statsd: prefix :: StatsdOptions -> !Text
+ System.Remote.Monitoring.Statsd: suffix :: StatsdOptions -> !Text
- System.Remote.Monitoring.Statsd: StatsdOptions :: !Text -> !Int -> !Int -> !Bool -> StatsdOptions
+ System.Remote.Monitoring.Statsd: StatsdOptions :: !Text -> !Int -> !Int -> !Bool -> !Text -> !Text -> StatsdOptions
Files
- CHANGES.md +6/−1
- System/Remote/Monitoring/Statsd.hs +46/−7
- ekg-statsd.cabal +1/−1
CHANGES.md view
@@ -1,4 +1,9 @@-## 0.1.0.0 (2013-05-01)+## 0.2.0.0 (2014-05-27)++ * Add configurable metric name prefix and suffix.+ * Add support for GHC 7.4.++## 0.1.0.0 (2014-05-01) * Initial release.
System/Remote/Monitoring/Statsd.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -22,8 +23,7 @@ , defaultStatsdOptions ) where -import Control.Concurrent (ThreadId, forkFinally, myThreadId, threadDelay,- throwTo)+import Control.Concurrent (ThreadId, myThreadId, threadDelay, throwTo) import Control.Exception (IOException, catch) import Control.Monad (forM_, when) import qualified Data.ByteString.Char8 as B8@@ -39,6 +39,14 @@ import qualified System.Metrics as Metrics import System.IO (stderr) +#if __GLASGOW_HASKELL__ >= 706+import Control.Concurrent (forkFinally)+#else+import Control.Concurrent (forkIO)+import Control.Exception (SomeException, mask, try)+import Prelude hiding (catch)+#endif+ -- | A handle that can be used to control the statsd sync thread. -- Created by 'forkStatsd'. data Statsd = Statsd@@ -56,10 +64,26 @@ -- the flush interval statsd itself uses to flush data to its -- backends. data StatsdOptions = StatsdOptions- { host :: !T.Text -- ^ Server hostname or IP address- , port :: !Int -- ^ Server port- , flushInterval :: !Int -- ^ Data push interval, in ms.- , debug :: !Bool -- ^ Print debug output to stderr.+ { -- | Server hostname or IP address+ host :: !T.Text++ -- | Server port+ , port :: !Int++ -- | Data push interval, in ms.+ , flushInterval :: !Int++ -- | Print debug output to stderr.+ , debug :: !Bool++ -- | Prefix to add to all metric names.+ , prefix :: !T.Text++ -- | Suffix to add to all metric names. This is particularly+ -- useful for sending per host stats by settings this value to:+ -- @takeWhile (/= \'.\') \<$\> getHostName@, using @getHostName@+ -- from the @Network.BSD@ module in the network package.+ , suffix :: !T.Text } -- | Defaults:@@ -77,6 +101,8 @@ , port = 8125 , flushInterval = 1000 , debug = False+ , prefix = ""+ , suffix = "" } -- | Create a thread that periodically flushes the metrics in the@@ -150,13 +176,16 @@ flushSample :: Metrics.Sample -> Socket.Socket -> StatsdOptions -> IO () flushSample sample socket opts = do forM_ (M.toList $ sample) $ \ (name, val) ->- flushMetric name val+ let fullName = dottedPrefix <> name <> dottedSuffix+ in flushMetric fullName val where flushMetric name (Metrics.Counter n) = send "|c" name (show n) flushMetric name (Metrics.Gauge n) = send "|g" name (show n) flushMetric _ _ = return () isDebug = debug opts+ dottedPrefix = if T.null (prefix opts) then "" else prefix opts <> "."+ dottedSuffix = if T.null (suffix opts) then "" else "." <> suffix opts send ty name val = do let !msg = B8.concat [T.encodeUtf8 name, ":", B8.pack val, ty] when isDebug $ B8.hPutStrLn stderr $ B8.concat [ "DEBUG: ", msg]@@ -164,3 +193,13 @@ T.hPutStrLn stderr $ "ERROR: Couldn't send message: " <> T.pack (show e) return ()++------------------------------------------------------------------------+-- Backwards compatibility shims++#if __GLASGOW_HASKELL__ < 706+forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId+forkFinally action and_then =+ mask $ \restore ->+ forkIO $ try (restore action) >>= and_then+#endif
ekg-statsd.cabal view
@@ -1,5 +1,5 @@ name: ekg-statsd-version: 0.1.0.0+version: 0.2.0.0 synopsis: Push metrics to statsd description: This library lets you push system metrics to a statsd server.