commit c6bca2d155e15c89db204eda8fd8e5277e13a356
Author: Michele Tartara <mtartara@google.com>
Date:   Thu May 23 19:53:19 2013 +0200

    Add /proc/diskstats parser
    
    Add a parser for interpreting the content of the /proc/diskstats file,
    providing information about the state of the disks of the system.
    
    Signed-off-by: Michele Tartara <mtartara@google.com>
    Reviewed-by: Klaus Aehlig <aehlig@google.com>

diff --git a/Makefile.am b/Makefile.am
index 6b7e8d5..069a65a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -64,6 +64,7 @@ HS_DIRS = \
 	src \
 	src/Ganeti \
 	src/Ganeti/Block \
+	src/Ganeti/Block/Diskstats \
 	src/Ganeti/Block/Drbd \
 	src/Ganeti/Confd \
 	src/Ganeti/Curl \
@@ -531,6 +532,8 @@ HPCEXCL = --exclude Main \
 	$(patsubst src.%,--exclude Test.%,$(subst /,.,$(patsubst %.hs,%, $(HS_LIB_SRCS))))
 
 HS_LIB_SRCS = \
+	src/Ganeti/Block/Diskstats/Parser.hs \
+	src/Ganeti/Block/Diskstats/Types.hs \
 	src/Ganeti/Block/Drbd/Types.hs \
 	src/Ganeti/Block/Drbd/Parser.hs \
 	src/Ganeti/BasicTypes.hs \
diff --git a/src/Ganeti/Block/Diskstats/Parser.hs b/src/Ganeti/Block/Diskstats/Parser.hs
new file mode 100644
index 0000000..a3492b3
--- /dev/null
+++ b/src/Ganeti/Block/Diskstats/Parser.hs
@@ -0,0 +1,65 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-| Diskstats proc file parser
+
+This module holds the definition of the parser that extracts status
+information about the disks of the system from the @/proc/diskstats@ 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.Block.Diskstats.Parser (diskstatsParser) where
+
+import Control.Applicative ((<*>), (*>), (<*), (<$>))
+import qualified Data.Attoparsec.Text as A
+import qualified Data.Attoparsec.Combinator as AC
+import Data.Attoparsec.Text (Parser)
+import Data.Text (unpack)
+
+import Ganeti.Block.Diskstats.Types
+
+-- * Utility functions
+
+-- | Our own space-skipping function, because A.skipSpace also skips
+-- newline characters. It skips ZERO or more spaces, so it does not
+-- fail if there are no spaces.
+skipSpaces :: Parser ()
+skipSpaces = A.skipWhile A.isHorizontalSpace
+
+-- | A parser recognizing a number preceeded by spaces.
+numberP :: Parser Int
+numberP = skipSpaces *> A.decimal
+
+-- | A parser recognizing a word preceded by spaces, and closed by a space.
+stringP :: Parser String
+stringP = skipSpaces *> fmap unpack (A.takeWhile $ not . A.isHorizontalSpace)
+
+-- * Parser implementation
+
+-- | The parser for one line of the diskstatus file.
+oneDiskstatsParser :: Parser Diskstats
+oneDiskstatsParser =
+  Diskstats <$> numberP <*> numberP <*> stringP <*> numberP <*> numberP
+    <*> numberP <*> numberP <*> numberP <*> numberP <*> numberP <*> numberP
+    <*> numberP <*> numberP <*> numberP <* A.endOfLine
+
+-- | The parser for a whole diskstatus file.
+diskstatsParser :: Parser [Diskstats]
+diskstatsParser = oneDiskstatsParser `AC.manyTill` A.endOfInput
diff --git a/src/Ganeti/Block/Diskstats/Types.hs b/src/Ganeti/Block/Diskstats/Types.hs
new file mode 100644
index 0000000..b44aec2
--- /dev/null
+++ b/src/Ganeti/Block/Diskstats/Types.hs
@@ -0,0 +1,51 @@
+{-# LANGUAGE TemplateHaskell #-}
+{-| Diskstats data types
+
+This module holds the definition of the data types describing the status of the
+disks according to the information contained in @/proc/diskstats@.
+
+-}
+{-
+
+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.Block.Diskstats.Types
+  ( Diskstats(..)
+  ) where
+
+import Ganeti.THH
+
+
+-- | This is the format of the report produced by each data collector.
+$(buildObject "Diskstats" "ds"
+  [ simpleField "major"        [t| Int |]
+  , simpleField "minor"        [t| Int |]
+  , simpleField "name"         [t| String |]
+  , simpleField "reads"        [t| Int |]
+  , simpleField "mergedReads"  [t| Int |]
+  , simpleField "secRead"      [t| Int |]
+  , simpleField "timeRead"     [t| Int |]
+  , simpleField "writes"       [t| Int |]
+  , simpleField "mergedWrites" [t| Int |]
+  , simpleField "secWritten"   [t| Int |]
+  , simpleField "timeWrite"    [t| Int |]
+  , simpleField "ios"          [t| Int |]
+  , simpleField "timeIO"       [t| Int |]
+  , simpleField "wIOmillis"    [t| Int |]
+  ])
