ekg-statsd 0.2.1.0 → 0.2.1.1
raw patch · 3 files changed
+34/−19 lines, 3 filesdep ~basedep ~timenew-uploaderPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, time
API changes (from Hackage documentation)
Files
- CHANGES.md +5/−0
- System/Remote/Monitoring/Statsd.hs +25/−15
- ekg-statsd.cabal +4/−4
CHANGES.md view
@@ -1,3 +1,8 @@+## 0.2.1.1 (2017-07-31)++ * Support GHC 8.2.1.+ * Suppress errors when sending to a non-existent receiver (#6).+ ## 0.2.1.0 (2016-08-11) * Send distributions as gauges and counters.
System/Remote/Monitoring/Statsd.hs view
@@ -114,16 +114,26 @@ forkStatsd opts store = do addrInfos <- Socket.getAddrInfo Nothing (Just $ T.unpack $ host opts) (Just $ show $ port opts)- socket <- case addrInfos of+ (sendSample, closeSocket) <- case addrInfos of [] -> unsupportedAddressError (addrInfo:_) -> do socket <- Socket.socket (Socket.addrFamily addrInfo) Socket.Datagram Socket.defaultProtocol- Socket.connect socket (Socket.addrAddress addrInfo)- return socket++ let socketAddress = Socket.addrAddress addrInfo++ sendSample <- if debug opts+ then do+ Socket.connect socket socketAddress+ return $ \msg -> Socket.sendAll socket msg++ else return $ \msg -> Socket.sendAllTo socket msg socketAddress++ return (sendSample, Socket.close socket)+ me <- myThreadId- tid <- forkFinally (loop store emptySample socket opts) $ \ r -> do- Socket.close socket+ tid <- forkFinally (loop store emptySample sendSample opts) $ \ r -> do+ closeSocket case r of Left e -> throwTo me e Right _ -> return ()@@ -133,19 +143,19 @@ "unsupported address: " ++ T.unpack (host opts) emptySample = M.empty -loop :: Metrics.Store -- ^ Metric store- -> Metrics.Sample -- ^ Last sampled metrics- -> Socket.Socket -- ^ Connected socket- -> StatsdOptions -- ^ Options+loop :: Metrics.Store -- ^ Metric store+ -> Metrics.Sample -- ^ Last sampled metrics+ -> (B8.ByteString -> IO ()) -- ^ Action to send a sample+ -> StatsdOptions -- ^ Options -> IO ()-loop store lastSample socket opts = do+loop store lastSample sendSample opts = do start <- time sample <- Metrics.sampleAll store let !diff = diffSamples lastSample sample- flushSample diff socket opts+ flushSample diff sendSample opts end <- time threadDelay (flushInterval opts * 1000 - fromIntegral (end - start))- loop store sample socket opts+ loop store sample sendSample opts -- | Microseconds since epoch. time :: IO Int64@@ -178,8 +188,8 @@ } diffMetric _ _ = Nothing -flushSample :: Metrics.Sample -> Socket.Socket -> StatsdOptions -> IO ()-flushSample sample socket opts =+flushSample :: Metrics.Sample -> (B8.ByteString -> IO ()) -> StatsdOptions -> IO ()+flushSample sample sendSample opts = do forM_ (M.toList sample) $ \ (name, val) -> let fullName = dottedPrefix <> name <> dottedSuffix in flushMetric fullName val@@ -203,7 +213,7 @@ 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]- Socket.sendAll socket msg `catch` \ (e :: IOException) -> do+ sendSample msg `catch` \ (e :: IOException) -> do T.hPutStrLn stderr $ "ERROR: Couldn't send message: " <> T.pack (show e) return ()
ekg-statsd.cabal view
@@ -1,5 +1,5 @@ name: ekg-statsd-version: 0.2.1.0+version: 0.2.1.1 synopsis: Push metrics to statsd description: This library lets you push system metrics to a statsd server.@@ -15,16 +15,16 @@ cabal-version: >=1.10 library- exposed-modules: + exposed-modules: System.Remote.Monitoring.Statsd build-depends:- base >= 4.5 && < 4.10,+ base >= 4.5 && < 4.11, bytestring < 1.0, ekg-core >= 0.1 && < 1.0, network < 2.7, text < 1.3,- time < 1.7,+ time < 1.9, unordered-containers < 0.3 default-language: Haskell2010