Commit 1a99d6a2 authored by Michele Tartara's avatar Michele Tartara

Add diskstats data collector

Add a new data collector responsible for gathering disk performance
statistics.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 3dca2415
......@@ -548,6 +548,7 @@ HS_LIB_SRCS = \
src/Ganeti/Curl/Multi.hs \
src/Ganeti/Daemon.hs \
src/Ganeti/DataCollectors/CLI.hs \
src/Ganeti/DataCollectors/Diskstats.hs \
src/Ganeti/DataCollectors/Drbd.hs \
src/Ganeti/DataCollectors/InstStatus.hs \
src/Ganeti/DataCollectors/InstStatusTypes.hs \
......
{-| @/proc/diskstats@ data collector.
-}
{-
Copyright (C) 2013 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
module Ganeti.DataCollectors.Diskstats
( main
, options
, arguments
, dcName
, dcVersion
, dcFormatVersion
, dcCategory
, dcKind
, dcReport
) where
import qualified Control.Exception as E
import Control.Monad
import Data.Attoparsec.Text.Lazy as A
import Data.Maybe
import Data.Text.Lazy (pack, unpack)
import qualified Text.JSON as J
import qualified Ganeti.BasicTypes as BT
import qualified Ganeti.Constants as C
import Ganeti.Block.Diskstats.Parser(diskstatsParser)
import Ganeti.Common
import Ganeti.DataCollectors.CLI
import Ganeti.DataCollectors.Types
import Ganeti.Utils
-- | The default path of the diskstats status file.
-- It is hardcoded because it is not likely to change.
defaultFile :: FilePath
defaultFile = C.diskstatsFile
-- | The default setting for the maximum amount of not parsed character to
-- print in case of error.
-- It is set to use most of the screen estate on a standard 80x25 terminal.
-- TODO: add the possibility to set this with a command line parameter.
defaultCharNum :: Int
defaultCharNum = 80*20
-- | The name of this data collector.
dcName :: String
dcName = "diskstats"
-- | The version of this data collector.
dcVersion :: DCVersion
dcVersion = DCVerBuiltin
-- | The version number for the data format of this data collector.
dcFormatVersion :: Int
dcFormatVersion = 1
-- | The category of this data collector.
dcCategory :: Maybe DCCategory
dcCategory = Just DCStorage
-- | The kind of this data collector.
dcKind :: DCKind
dcKind = DCKPerf
-- | The data exported by the data collector, taken from the default location.
dcReport :: IO DCReport
dcReport = buildDCReport defaultFile
-- * Command line options
options :: IO [OptType]
options =
return
[ oInputFile
]
-- | The list of arguments supported by the program.
arguments :: [ArgCompletion]
arguments = [ArgCompletion OptComplFile 0 (Just 0)]
-- | This function computes the JSON representation of the diskstats status.
buildJsonReport :: FilePath -> IO J.JSValue
buildJsonReport inputFile = do
contents <-
((E.try $ readFile inputFile) :: IO (Either IOError String)) >>=
exitIfBad "reading from file" . either (BT.Bad . show) BT.Ok
diskstatsData <-
case A.parse diskstatsParser $ pack contents of
A.Fail unparsedText contexts errorMessage -> exitErr $
show (Prelude.take defaultCharNum $ unpack unparsedText) ++ "\n"
++ show contexts ++ "\n" ++ errorMessage
A.Done _ diskstatsD -> return diskstatsD
return $ J.showJSON diskstatsData
-- | This function computes the DCReport for the diskstats status.
buildDCReport :: FilePath -> IO DCReport
buildDCReport inputFile =
buildJsonReport inputFile >>=
buildReport dcName dcVersion dcFormatVersion dcCategory dcKind
-- | Main function.
main :: Options -> [String] -> IO ()
main opts args = do
let inputFile = fromMaybe defaultFile $ optInputFile opts
unless (null args) . exitErr $ "This program takes exactly zero" ++
" arguments, got '" ++ unwords args ++ "'"
report <- buildDCReport inputFile
putStrLn $ J.encode report
......@@ -28,6 +28,7 @@ module Ganeti.DataCollectors.Program (personalities) where
import Ganeti.Common (PersonalityList)
import Ganeti.DataCollectors.CLI (Options)
import qualified Ganeti.DataCollectors.Diskstats as Diskstats
import qualified Ganeti.DataCollectors.Drbd as Drbd
import qualified Ganeti.DataCollectors.InstStatus as InstStatus
......@@ -40,4 +41,8 @@ personalities = [ (Drbd.dcName, (Drbd.main, Drbd.options, Drbd.arguments,
InstStatus.arguments,
"gathers and displays the status of the\
\ instances in JSON format"))
, (Diskstats.dcName, (Diskstats.main, Diskstats.options,
Diskstats.arguments,
"gathers and displays the disk usage\
\ statistics in JSON format"))
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment