nagios-plugin-ekg 0.1.0.0 → 0.1.1.0
raw patch · 4 files changed
+35/−10 lines, 4 files
Files
- lib/System/Nagios/Plugin/Ekg.hs +10/−0
- lib/System/Nagios/Plugin/Ekg/Check.hs +14/−1
- lib/System/Nagios/Plugin/Ekg/Types.hs +10/−8
- nagios-plugin-ekg.cabal +1/−1
lib/System/Nagios/Plugin/Ekg.hs view
@@ -1,3 +1,13 @@+{-|+Module : Nagios.Plugin.Ekg+Copyright : Sharif Olorin, 2015, + Anchor Systems, 2015+License : MIT+Maintainer : Sharif Olorin <sio@tesser.org>+Stability : experimental+Portability : POSIX+-}+ module System.Nagios.Plugin.Ekg ( module System.Nagios.Plugin.Ekg.Check, module System.Nagios.Plugin.Ekg.Types
lib/System/Nagios/Plugin/Ekg/Check.hs view
@@ -1,6 +1,9 @@ {-# LANGUAGE OverloadedStrings #-} -module System.Nagios.Plugin.Ekg.Check where+module System.Nagios.Plugin.Ekg.Check (+ checkEkg,+ checkEkg'+) where import Control.Applicative import Control.Lens@@ -16,6 +19,9 @@ import System.Nagios.Plugin.Ekg.Types +data PluginOpts = PluginOpts+ { optsEndpoint :: String }+ pluginOptParser :: ParserInfo PluginOpts pluginOptParser = info (helper <*> opts) ( fullDesc@@ -30,6 +36,11 @@ <> help "URL of the EKG endpoint." ) +-- | Run the check against the EKG endpoint specified on the command+-- line. Terminate according to the+-- <https://nagios-plugins.org/doc/guidelines.html#PLUGOUTPUT plugin development guidelines> -+-- 'OK' if we retrieve and successfully parse a result, otherwise+-- 'CRITICAL'. checkEkg :: NagiosPlugin () checkEkg = do opts <- liftIO $ execParser pluginOptParser@@ -39,6 +50,8 @@ 200 -> checkEkg' $ resp ^. responseBody code -> addResult Critical . T.pack $ "EKG endpoint failed with status " <> show code +-- | Version of 'checkEkg' which takes a 'ByteString' rather than+-- requesting it from an EKG endpoint. checkEkg' :: ByteString -> NagiosPlugin () checkEkg' bs = case (eitherDecode' bs :: Either String MetricTree) of Left err -> addResult Critical $ "failed to parse EKG output: " <> T.pack err
lib/System/Nagios/Plugin/Ekg/Types.hs view
@@ -1,6 +1,8 @@ {-# LANGUAGE OverloadedStrings #-} -module System.Nagios.Plugin.Ekg.Types where+module System.Nagios.Plugin.Ekg.Types (+ MetricTree+) where import Control.Applicative import Control.Monad@@ -16,17 +18,14 @@ import qualified Data.Text as T import System.Nagios.Plugin -data PluginOpts = PluginOpts- { optsEndpoint :: String }- data EkgMetric =- -- * Nondecreasing counter, e.g., all-time number of requests.+ -- | Nondecreasing counter, e.g., all-time number of requests. EkgCounter Int64- -- * Measure of a quantity over time, e.g., number of requests per minute.+ -- | Measure of a quantity over time, e.g., number of requests per minute. | EkgGauge Double- -- * Can't meaningfully turn labels into perfdata, this is a placeholder.+ -- | Can't meaningfully turn labels into perfdata, this is a placeholder. | EkgLabel- -- * Can't meaningfully turn distributions into perfdata, this is a placeholder.+ -- | Can't meaningfully turn distributions into perfdata, this is a placeholder. | EkgDistribution deriving (Eq, Show) @@ -66,6 +65,9 @@ ) parseJSON x = fail $ "MetricNode must be an object, not " <> show x +-- | Top-level object for parsed EKG metrics. Structurally, this is an+-- n-ary tree; the leaves are the metrics themselves and the+-- non-leaf nodes are used to construct the metric labels. newtype MetricTree = MetricTree { unMetricTree :: Map Text MetricNode }
nagios-plugin-ekg.cabal view
@@ -1,5 +1,5 @@ name: nagios-plugin-ekg-version: 0.1.0.0+version: 0.1.1.0 synopsis: Monitor ekg metrics via Nagios description: A generic Nagios plugin which retrieves metrics from an application which uses