From b029fe26b6f9c1d440d6764d8ddc9310b81183f8 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Wed, 1 Feb 2017 11:12:01 -0800 Subject: [PATCH 1/2] Allow statsd reporting of instances of Num type class - Count could also be made generic over Num instances, but left it as is. - Statsd supports Num instances for the various types. - Motivating use case for this patch is wanting to send float values for a gauge metric. --- src/Network/DogStatsd.hs | 6 +++--- src/Network/Statsd.hs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Network/DogStatsd.hs b/src/Network/DogStatsd.hs index afc8e1c..8dc4250 100644 --- a/src/Network/DogStatsd.hs +++ b/src/Network/DogStatsd.hs @@ -34,20 +34,20 @@ decrement client stat = count client stat (-1) count :: UdpClient -> Stat -> Int -> Tags -> IO () count client stat value tags = void . send client $ fmtDogStatsdDatagram stat value Count tags -gauge :: UdpClient -> Stat -> Int -> Tags -> IO () +gauge :: (Show a, Num a) => UdpClient -> Stat -> a -> Tags -> IO () gauge client stat value tags = void . send client $ fmtDogStatsdDatagram stat value Gauge tags timing :: UdpClient -> Stat -> Millisecond -> Tags -> IO () timing client stat value tags = void . send client $ fmtDogStatsdDatagram stat (fromIntegral value) Timing tags -histogram :: UdpClient -> Stat -> Int -> Tags -> IO () +histogram :: (Show a, Num a) => UdpClient -> Stat -> a -> Tags -> IO () histogram client stat value tags = void . send client $ fmtDogStatsdDatagram stat value Histogram tags fmtTag :: (Name, Value) -> String fmtTag (a, "") = a fmtTag (a, b) = a ++ ":" ++ b -fmtDogStatsdDatagram :: Stat -> Int -> Type -> Tags -> String +fmtDogStatsdDatagram :: (Show a, Num a) => Stat -> a -> Type -> Tags -> String fmtDogStatsdDatagram stat value statType [] = fmtDatagram stat value statType fmtDogStatsdDatagram stat value statType tags = let statsdDatagram = fmtDatagram stat value statType diff --git a/src/Network/Statsd.hs b/src/Network/Statsd.hs index 3a22d91..546d3c0 100644 --- a/src/Network/Statsd.hs +++ b/src/Network/Statsd.hs @@ -42,14 +42,14 @@ decrement client stat = count client stat (-1) count :: UdpClient -> Stat -> Int -> IO () count client stat value = void . send client $ fmtDatagram stat value Count -gauge :: UdpClient -> Stat -> Int -> IO () +gauge :: (Show a, Num a) => UdpClient -> Stat -> a -> IO () gauge client stat value = void . send client $ fmtDatagram stat value Gauge timing :: UdpClient -> Stat -> Millisecond -> IO () timing client stat value = void . send client $ fmtDatagram stat (fromIntegral value) Timing -histogram :: UdpClient -> Stat -> Int -> IO () +histogram :: (Show a, Num a) => UdpClient -> Stat -> a -> IO () histogram client stat value = void . send client $ fmtDatagram stat value Histogram -fmtDatagram :: Stat -> Int -> Type -> String +fmtDatagram:: (Show a, Num a) => Stat -> a -> Type -> String fmtDatagram stat value statType = printf "%s:%s|%s" stat (show value) (show statType) From 218c60d83fe2bd0c4e61afe53e2d0702b86a6977 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Wed, 1 Feb 2017 11:19:17 -0800 Subject: [PATCH 2/2] Bump minor-minor version --- statsd-client.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/statsd-client.cabal b/statsd-client.cabal index 19f3789..be9e3cb 100644 --- a/statsd-client.cabal +++ b/statsd-client.cabal @@ -1,5 +1,5 @@ name: statsd-client -version: 0.3.0.0 +version: 0.3.0.1 cabal-version: >=1.10 build-type: Simple license: MIT