packages feed

network-metrics 0.3.2 → 0.4

raw patch · 8 files changed

+23/−24 lines, 8 files

Files

README.md view
@@ -4,8 +4,6 @@ Table of Contents ----------------- -* [Usage](#usage)-* [API](#api) * [Contribute](#contribute) * [Licence](#licence) @@ -34,8 +32,8 @@ import Network.Metric  main = do-    sink <- open Ganglia "localhost" "1234"-    -- Creates ganglia key: "name.space.bucket" with an "int32" type+    sink <- open Ganglia (Just "thishost") "localhost" "1234"+    -- Creates ganglia key: "thishost.name.space.bucket" with an "int32" type     push sink $ Counter "name.space" "bucket" 1234     close sink ````@@ -49,7 +47,7 @@ import Network.Metric.Sink.Graphite  main = do-    sink <- open "localhost" "1234"+    sink <- open Nothing "localhost" "1234"     -- Creates graphite key: "name.space.bucket"     push sink $ Counter "name.space" "bucket" 1234     close sink@@ -64,7 +62,6 @@ Preliminary API documentation is available [on Hackage](http://hackage.haskell.org/package/network-metrics).  > The API is currently in flux, and conversion between the universal `Counter`, `Gauge`, and `Timing` ctors to the respective sink types is not yet completed.-  <a name="contribute" /> 
network-metrics.cabal view
@@ -1,5 +1,5 @@ name:               network-metrics-version:            0.3.2+version:            0.4 synopsis:           Send metrics to Ganglia, Graphite, and statsd. license:            OtherLicense license-file:       LICENSE
src/Network/Metric.hs view
@@ -47,7 +47,7 @@ --  -- | Open a new sink specified by SinkType-open :: SinkType -> Host -> HostName -> PortNumber -> IO AnySink+open :: SinkType -> Maybe Host -> HostName -> PortNumber -> IO AnySink open Ganglia  = GangliaSink.open open Graphite = GraphiteSink.open open Statsd   = StatsdSink.open
src/Network/Metric/Internal.hs view
@@ -110,7 +110,7 @@     measure (AnyMeasurable m) = measure m  instance Measurable Metric where-    measure = flip (:) [] . id+    measure = flip (:) []  instance Encodable Int where     encode = BS.pack . show@@ -134,8 +134,9 @@ --  -- | Combine a Host, Group and Bucket into a single key-key :: Host -> Group -> Bucket -> BS.ByteString-key h g b = BS.intercalate "." [h, g, b]+key :: Maybe Host -> Group -> Bucket -> BS.ByteString+key (Just h) g b = BS.intercalate "." [h, g, b]+key Nothing g b  = BS.intercalate "." [g, b]  -- | Helper to curry a constructor function for a sink fOpen :: Sink a
src/Network/Metric/Sink/Ganglia.hs view
@@ -37,9 +37,10 @@ import Data.Binary.Put import Data.Bits                ((.&.)) import Data.Char                (toLower)-import Data.Data                (Data, Typeable)+import Data.Data                (Data) import Data.Default             (Default, def) import Data.Int                 (Int32)+import Data.Maybe               (fromMaybe) import Data.Typeable            (Typeable, typeOf) import Data.Word                (Word32) import Network.Socket           (SocketType(..))@@ -76,10 +77,10 @@     def = defaultMetric  -- | A handle to a Ganglia sink-data Ganglia = Ganglia Host Handle deriving (Show)+data Ganglia = Ganglia (Maybe Host) Handle deriving (Show)  instance Sink Ganglia where-    push (Ganglia host hd) m = mapM_ (hPush hd) (concat . map enc $ measure m)+    push (Ganglia host hd) m = mapM_ (hPush hd) (concatMap enc $ measure m)       where         enc (Counter g b v) = put host g b v Positive         enc (Timer g b v)   = put host g b v Both@@ -107,7 +108,7 @@     }  -- | Open a new Ganglia sink-open :: Host -> HostName -> PortNumber -> IO AnySink+open :: Maybe Host -> HostName -> PortNumber -> IO AnySink open host = fOpen (Ganglia host) Datagram  -- | Encode a GangliaMetric's metadata into a Binary.Put monad@@ -139,7 +140,7 @@  -- | Oh, the horror put :: Encodable a-    => Host+    => Maybe Host     -> Group     -> Bucket     -> a@@ -151,7 +152,7 @@      metric = defaultMetric          { name  = bucket          , group = group-         , host  = host+         , host  = fromMaybe "" host          , value = encode value          , type' = determineType value          , slope = slope
src/Network/Metric/Sink/Graphite.hs view
@@ -29,7 +29,7 @@ import qualified Data.ByteString.Lazy.Char8 as BL  -- | A handle to a Graphite sink-data Graphite = Graphite Host Handle deriving (Show)+data Graphite = Graphite (Maybe Host) Handle deriving (Show)  instance Sink Graphite where     push (Graphite host hd) m = do@@ -48,7 +48,7 @@ --  -- | Open a new Graphite sink-open :: Host -> HostName -> PortNumber -> IO AnySink+open :: Maybe Host -> HostName -> PortNumber -> IO AnySink open host = fOpen (Graphite host) Stream  --@@ -57,7 +57,7 @@  -- | Encode a metric into the Graphite format put :: Encodable a-    => Host+    => Maybe Host     -> Group     -> Bucket     -> a
src/Network/Metric/Sink/Handle.hs view
@@ -26,7 +26,7 @@ import qualified Data.ByteString.Char8 as BS  -- | A generic sink handle-data SinkHandle = SinkHandle Host (String -> IO ())+data SinkHandle = SinkHandle (Maybe Host) (String -> IO ())  instance Sink SinkHandle where     push h = mapM_ enc . measure
src/Network/Metric/Sink/Statsd.hs view
@@ -33,7 +33,7 @@ data Sampled = Sampled | Exact | Ignore  -- | A handle to a Statsd sink-data Statsd = Statsd Host Handle deriving (Show)+data Statsd = Statsd (Maybe Host) Handle deriving (Show)  instance Sink Statsd where     push (Statsd host hd) m = mapM enc (measure m) >>= mapM_ (hPush hd)@@ -49,7 +49,7 @@ --  -- | Open a new Statsd sink-open :: Host -> HostName -> PortNumber -> IO AnySink+open :: Maybe Host -> HostName -> PortNumber -> IO AnySink open host = fOpen (Statsd host) Datagram  --@@ -58,7 +58,7 @@ -- | Encode a metric into the Statsd format -- *TODO:* Currently statsd sampling is not exposed via the global metric type put :: Encodable a-    => Host+    => Maybe Host     -> Group     -> Bucket     -> a