module Network.Metric.Sink.Handle (
SinkHandle(..)
, Group
, Bucket
, Metric(..)
, Sink(..)
) where
import Network.Metric.Internal
import qualified Data.ByteString.Char8 as BS
data SinkHandle = SinkHandle Host (String -> IO ())
instance Sink SinkHandle where
push h = mapM_ enc . measure
where
enc (Counter g b v) = put "Counter" h g b v
enc (Timer g b v) = put "Timer" h g b v
enc (Gauge g b v) = put "Gauge" h g b v
close _ = return ()
put :: Encodable a
=> BS.ByteString
-> SinkHandle
-> Group
-> Bucket
-> a
-> IO ()
put p (SinkHandle h f) g b v = f msg
where
msg = BS.unpack $ BS.concat [p, ": ", key h g b, " ", encode v]