Commit f6d4b52d authored by Spyros Trigazis's avatar Spyros Trigazis Committed by Michele Tartara

Introduce LoadParser and Types for a new Collector

Introduce the Parser and Types for a new Data Collector.
Signed-off-by: default avatarSpyros Trigazis <strigazi@gmail.com>
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent 090e5de8
......@@ -68,6 +68,7 @@ HS_DIRS = \
src/Ganeti \
src/Ganeti/Confd \
src/Ganeti/Curl \
src/Ganeti/Cpu \
src/Ganeti/DataCollectors \
src/Ganeti/HTools \
src/Ganeti/HTools/Backend \
......@@ -556,6 +557,8 @@ HS_LIB_SRCS = \
src/Ganeti/Confd/Utils.hs \
src/Ganeti/Config.hs \
src/Ganeti/ConfigReader.hs \
src/Ganeti/Cpu/LoadParser.hs \
src/Ganeti/Cpu/Types.hs \
src/Ganeti/Curl/Multi.hs \
src/Ganeti/Daemon.hs \
src/Ganeti/DataCollectors/CLI.hs \
......
{-# LANGUAGE OverloadedStrings #-}
{-| /proc/stat file parser
This module holds the definition of the parser that extracts information
about the CPU load of the system from the @/proc/stat@ file.
-}
{-
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.Cpu.LoadParser (cpustatParser) where
import Control.Applicative ((<*>), (<*), (*>), (<$>), (<|>))
import qualified Data.Attoparsec.Text as A
import qualified Data.Attoparsec.Combinator as AC
import Data.Attoparsec.Text (Parser)
import Ganeti.Parsers
import Ganeti.Cpu.Types
-- * Parser implementation
-- | The parser for one line of the CPU status file.
oneCPUstatParser :: Parser CPUstat
oneCPUstatParser =
let nameP = stringP
userP = numberP
niceP = numberP
systemP = numberP
idleP = numberP
iowaitP = numberP
irqP = numberP
softirqP = numberP
stealP = numberP
guestP = numberP
guest_niceP = numberP
in
CPUstat <$> nameP <*> userP <*> niceP <*> systemP <*> idleP <*> iowaitP
<*> irqP <*> softirqP <*> stealP <*> guestP <*> guest_niceP
<* A.endOfLine
-- | When this is satisfied all the lines containing information about
-- the CPU load are parsed.
intrFound :: Parser ()
intrFound = (A.string "intr" *> return ())
<|> (A.string "page" *> return ())
<|> (A.string "swap" *> return ())
-- | The parser for the fragment of CPU status file containing
-- information about the CPU load.
cpustatParser :: Parser [CPUstat]
cpustatParser = oneCPUstatParser `AC.manyTill` intrFound
{-# LANGUAGE TemplateHaskell #-}
{-| CPUload data types
This module holds the definition of the data types describing the CPU
load according to information collected periodically from @/proc/stat@.
-}
{-
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.Cpu.Types
( CPUstat(..)
) where
import Ganeti.THH
-- | This is the format of the data parsed by the input file.
$(buildObject "CPUstat" "cs"
[ simpleField "name" [t| String |]
, simpleField "user" [t| Int |]
, simpleField "nice" [t| Int |]
, simpleField "system" [t| Int |]
, simpleField "idle" [t| Int |]
, simpleField "iowait" [t| Int |]
, simpleField "irq" [t| Int |]
, simpleField "softirq" [t| Int |]
, simpleField "steal" [t| Int |]
, simpleField "guest" [t| Int |]
, simpleField "guest_nice" [t| Int |]
])
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