network-metrics 0.1.2 → 0.1.3
raw patch · 7 files changed
+38/−16 lines, 7 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Network.Metrics: Handle :: Socket -> SockAddr -> Handle
+ Network.Metrics: data Handle
+ Network.Metrics.Statsd: Counter :: MetricType
+ Network.Metrics.Statsd: Gauge :: MetricType
+ Network.Metrics.Statsd: Timer :: MetricType
- Network.Metrics.Ganglia: emit :: Metric -> Handle -> IO Handle
+ Network.Metrics.Ganglia: emit :: Metric -> Handle -> IO ()
- Network.Metrics.Graphite: emit :: Metric -> Handle -> IO Handle
+ Network.Metrics.Graphite: emit :: Metric -> Handle -> IO ()
- Network.Metrics.Statsd: Metric :: MetricType -> ByteString -> Integer -> Double -> Metric
+ Network.Metrics.Statsd: Metric :: MetricType -> ByteString -> ByteString -> Double -> Metric
- Network.Metrics.Statsd: emit :: Metric -> Handle -> IO Handle
+ Network.Metrics.Statsd: emit :: Metric -> Handle -> IO ()
- Network.Metrics.Statsd: value :: Metric -> Integer
+ Network.Metrics.Statsd: value :: Metric -> ByteString
Files
- network-metrics.cabal +3/−2
- src/GMetric.hs +4/−1
- src/Network/Metrics.hs +18/−0
- src/Network/Metrics/Ganglia.hs +4/−4
- src/Network/Metrics/Graphite.hs +1/−1
- src/Network/Metrics/Internal.hs +4/−4
- src/Network/Metrics/Statsd.hs +4/−4
network-metrics.cabal view
@@ -1,5 +1,5 @@ name: network-metrics-version: 0.1.2+version: 0.1.3 synopsis: Send metrics to Ganglia, Graphite, and statsd. license: OtherLicense license-file: LICENSE@@ -32,7 +32,8 @@ location: git://github.com/brendanhay/network-metrics.git library- exposed-modules: Network.Metrics.Ganglia+ exposed-modules: Network.Metrics+ , Network.Metrics.Ganglia , Network.Metrics.Graphite , Network.Metrics.Statsd other-modules: Network.Metrics.Internal
src/GMetric.hs view
@@ -48,7 +48,10 @@ -- emit :: Options -> IO ()-emit Options{..} = G.open optHost optPort >>= G.emit metric >>= G.close+emit Options{..} = do+ handle <- G.open optHost optPort+ G.emit metric handle+ G.close handle where metric = G.Metric (pack optName)
+ src/Network/Metrics.hs view
@@ -0,0 +1,18 @@+-- |+-- Module : Network.Metrics+-- Copyright : (c) 2012 Brendan Hay <brendan@soundcloud.com>+-- License : This Source Code Form is subject to the terms of+-- the Mozilla Public License, v. 2.0.+-- A copy of the MPL can be found in the LICENSE file or+-- you can obtain it at http://mozilla.org/MPL/2.0/.+-- Maintainer : Brendan Hay <brendan@soundcloud.com>+-- Stability : experimental+-- Portability : non-portable (GHC extensions)+--++module Network.Metrics (+ -- * Re-exported types+ Handle(..)+ ) where++import Network.Metrics.Internal
src/Network/Metrics/Ganglia.hs view
@@ -97,12 +97,12 @@ open = I.open Datagram -- | Emit a metric's metadata and value on the specified socket handle-emit :: Metric -> I.Handle -> IO I.Handle+emit :: Metric -> I.Handle -> IO () emit metric handle@(I.Handle sock addr) = do sIsConnected sock >>= \b -> unless b $ connect sock addr _ <- push putMetaData handle _ <- push putMetric handle- return handle+ return () where push fn = I.emit . runPut $ fn metric @@ -204,6 +204,6 @@ loop h = do r <- randomRIO variance :: IO Int n <- sample ["magic", "candy", "unicorns"]- f <- emit defaultMetric { name = n, value = BS.pack $ show r } h+ emit defaultMetric { name = n, value = BS.pack $ show r } h threadDelay oneSecond- loop f+ loop h
src/Network/Metrics/Graphite.hs view
@@ -44,7 +44,7 @@ open = I.open Stream -- | Emit a metric's metadata and value on the specified socket handle-emit :: Metric -> I.Handle -> IO I.Handle+emit :: Metric -> I.Handle -> IO () emit Metric{..} handle = do time <- getPOSIXTime I.emit (encoded time) handle
src/Network/Metrics/Internal.hs view
@@ -45,9 +45,9 @@ close (Handle sock _) = sClose sock -- | Push an encoded metric to the specified socket handle-emit :: BL.ByteString -> Handle -> IO Handle-emit bstr handle@(Handle sock addr) | BL.null bstr = return handle- | otherwise = do+emit :: BL.ByteString -> Handle -> IO ()+emit bstr (Handle sock addr) | BL.null bstr = return ()+ | otherwise = do sIsConnected sock >>= \b -> unless b $ connect sock addr _ <- send sock bstr- return handle+ return ()
src/Network/Metrics/Statsd.hs view
@@ -12,7 +12,7 @@ module Network.Metrics.Statsd ( -- * Exported types- MetricType+ MetricType(..) , Metric(..) -- * Socket Handle operations@@ -36,7 +36,7 @@ data Metric = Metric { type' :: MetricType , bucket :: BS.ByteString- , value :: Integer+ , value :: BS.ByteString , rate :: Double } deriving (Show) @@ -51,7 +51,7 @@ open = I.open Datagram -- | Emit a metric's metadata and value on the specified socket handle-emit :: Metric -> I.Handle -> IO I.Handle+emit :: Metric -> I.Handle -> IO () emit metric handle = do rand <- randomRIO (0.0, 1.0) I.emit (encoded rand) handle@@ -73,7 +73,7 @@ Exact -> base Ignore -> [] where- base = [bucket, ":", BS.pack $ show value, "|", suffix type']+ base = [bucket, ":", value, "|", suffix type'] suffix :: MetricType -> BS.ByteString suffix typ = case typ of