packages feed

network-metrics 0.2.9 → 0.3.0

raw patch · 4 files changed

+8/−203 lines, 4 filesdep −cmdargsnew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies removed: cmdargs

API changes (from Hackage documentation)

- Network.Metric.Internal: PortNum :: Word16 -> PortNumber
- Network.Metric.Internal: newtype PortNumber :: *
+ Network.Metric.Internal: data PortNumber :: *

Files

README.md view
@@ -6,7 +6,6 @@  * [Usage](#usage) * [API](#api)-* [GMetric](#gmetric) * [Contribute](#contribute) * [Licence](#licence) @@ -65,14 +64,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="gmetric" />--GMetric----------A port of Ganglia's `gmetric` is built by default under the name `gmetric-haskell`.   <a name="contribute" />
network-metrics.cabal view
@@ -1,5 +1,5 @@ name:               network-metrics-version:            0.2.9+version:            0.3.0 synopsis:           Send metrics to Ganglia, Graphite, and statsd. license:            OtherLicense license-file:       LICENSE@@ -55,27 +55,3 @@                   , data-default                   , random                   , time--executable gmetric-haskell-  main-is:          GMetric.hs--  hs-source-dirs:   src--  default-language: Haskell2010-  default-extensions:-                    OverloadedStrings-                  , DeriveDataTypeable-                  , RecordWildCards-                  , TypeSynonymInstances-                  , FlexibleInstances--  ghc-options:      -Wall -rtsopts-  ghc-prof-options: -prof -auto-all -with-rtsopts=-p--  build-depends:    base >= 4.3 && < 5-                  , network-                  , binary-                  , bytestring-                  , data-default-                  , random-                  , cmdargs
− src/GMetric.hs
@@ -1,166 +0,0 @@--- |--- Module      : GMetric.Main--- Copyright   : (c) 2012-2013 Brendan Hay <brendan.g.hay@gmail.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.g.hay@gmail.com>--- Stability   : experimental--- Portability : non-portable (GHC extensions)-----module Main (-      main-    ) where---import Control.Monad          (when)-import System.Console.CmdArgs-import System.Environment     (getArgs, withArgs)-import System.Exit            (ExitCode(..), exitWith)--import qualified Network.Metric.Sink.Ganglia as G--data Options = Options-    { optHost  :: String-    , optPort  :: String-    , optName  :: String-    , optValue :: String-    , optType  :: G.GangliaType-    , optGroup :: String-    , optUnits :: String-    , optSlope :: G.Slope-    , optTMax  :: Integer-    , optDMax  :: Integer-    , optSpoof :: String-    } deriving (Data, Typeable, Show)------- API-----main :: IO ()-main = parse >>= emit------- Private-----emit :: Options -> IO ()-emit Options{..} = return ()-  --   sink@(G.Ganglia hd) <- liftM G.Ganglia (hOpen Datagram optHost port)-  --   _ <- push' G.putMetaData hd-  --   _ <- push' G.putValue hd-  --   G.close sink-  -- where-  --   push' f = flip hPush . runPut $ f metric-  --   port    = PortNum (read optPort :: Word16)-  --   metric  = G.GangliaMetric-  --       (BS.pack optName)-  --       optType-  --       (BS.pack optUnits)-  --       (BS.pack optValue)-  --       ""-  --       (BS.pack optSpoof)-  --       (BS.pack optGroup)-  --       optSlope-  --       (fromInteger optTMax)-  --       (fromInteger optDMax)------- Parsing-----programName, programVersion, programInfo, copyright :: String-programName    = "gmetric-haskell"-programVersion = "0.1.0"-programInfo    = programName ++ " version " ++ programVersion-copyright      = "(C) Brendan Hay <brendan.g.hay@gmail.com> 2012-2013"--parse :: IO Options-parse = do-    raw  <- getArgs-    opts <- (if null raw then withArgs ["--help"] else id) fn-    validate opts-  where-    fn = cmdArgs $ options-        &= versionArg [explicit, name "version", name "v", summary programInfo]-        &= summary (programInfo ++ ", " ++ copyright)-        &= helpArg [explicit, name "help", name "h"]-        &= program programName--validate :: Options -> IO Options-validate opts@Options{..} = do-    exitWhen (null optHost)  "--host cannot be blank"-    exitWhen (null optPort)  "--port cannot be blank"-    exitWhen (null optName)  "--name cannot be blank"-    exitWhen (null optValue) "--value cannot be blank"-    return opts--exitWhen :: Bool -> String -> IO ()-exitWhen p msg = when p $ putStrLn msg >> exitWith (ExitFailure 1)------- Descriptions-----options :: Options-options = Options-    { optHost = ""-        &= name "host"-        &= typ  "STRING"-        &= help "Host channel to deliver metrics to"-        &= explicit-    , optPort = ""-        &= name "port"-        &= typ  "INT"-        &= help "Port channel to deliver metrics to"-        &= explicit-    , optName = ""-        &= name "name"-        &= typ  "STRING"-        &= help "Name of the metric"-        &= explicit-    , optValue = ""-        &= name "value"-        &= typ  "STRING"-        &= help "Value of the metric"-        &= explicit-    , optType = G.String-        &= name "type"-        &= typ  "STRING"-        &= help "Either string|int8|uint8|int16|uint16|int32|uint32|float|double"-        &= explicit-    , optUnits = ""-        &= name "units"-        &= typ  "STRING"-        &= help "Unit of measure for the value e.g. Kilobytes, Celcius (default='')"-        &= explicit-    , optGroup = ""-        &= name "group"-        &= typ  "STRING"-        &= help "Group of the metric"-        &= explicit-    , optSlope = G.Both-        &= name "slope"-        &= typ  "STRING"-        &= help "Either zero|positive|negative|both (default='both')"-        &= explicit-    , optTMax = 60-        &= name "tmax"-        &= typ  "STRING"-        &= help "The maximum time in seconds between gmetric calls (default='60')"-        &= explicit-    , optDMax = 0-        &= name "dmax"-        &= typ  "STRING"-        &= help "The lifetime in seconds of this metric (default='0')"-        &= explicit-    , optSpoof = ""-        &= name "spoof"-        &= typ  "STRING"-        &= help "IP address and name of host/device (colon separated) we are spoofing (default='')"-        &= explicit-    } &= name "gmetric-haskell"-      &= help "The Ganglia Metric Client (gmetric) announces a metric on the specified host/port"
src/Network/Metric/Internal.hs view
@@ -40,11 +40,12 @@      -- * Re-exports     , S.HostName-    , S.PortNumber(..)+    , S.PortNumber     ) where  import Control.Monad (liftM, unless) import Data.Typeable (Typeable)+import Data.Word     (Word16) import Text.Printf   (printf)  import qualified Data.ByteString.Char8          as BS@@ -147,10 +148,13 @@  -- | Create a new socket handle (in a disconnected state) for UDP communication hOpen :: S.SocketType -> S.HostName -> S.PortNumber -> IO Handle-hOpen typ host (S.PortNum port) = do-    (addr:_) <- S.getAddrInfo Nothing (Just host) (Just $ show port)+hOpen typ host port = do+    (addr:_) <- S.getAddrInfo Nothing (Just host) (Just . show . p2w $ port)     sock     <- S.socket (S.addrFamily addr) typ S.defaultProtocol     return $ Handle sock (S.addrAddress addr)+  where+    p2w :: S.PortNumber -> Word16+    p2w = fromIntegral  -- | Close a socket handle hClose :: Handle -> IO ()