Revision c6bca2d1
b/Makefile.am | ||
---|---|---|
64 | 64 |
src \ |
65 | 65 |
src/Ganeti \ |
66 | 66 |
src/Ganeti/Block \ |
67 |
src/Ganeti/Block/Diskstats \ |
|
67 | 68 |
src/Ganeti/Block/Drbd \ |
68 | 69 |
src/Ganeti/Confd \ |
69 | 70 |
src/Ganeti/Curl \ |
... | ... | |
531 | 532 |
$(patsubst src.%,--exclude Test.%,$(subst /,.,$(patsubst %.hs,%, $(HS_LIB_SRCS)))) |
532 | 533 |
|
533 | 534 |
HS_LIB_SRCS = \ |
535 |
src/Ganeti/Block/Diskstats/Parser.hs \ |
|
536 |
src/Ganeti/Block/Diskstats/Types.hs \ |
|
534 | 537 |
src/Ganeti/Block/Drbd/Types.hs \ |
535 | 538 |
src/Ganeti/Block/Drbd/Parser.hs \ |
536 | 539 |
src/Ganeti/BasicTypes.hs \ |
b/src/Ganeti/Block/Diskstats/Parser.hs | ||
---|---|---|
1 |
{-# LANGUAGE OverloadedStrings #-} |
|
2 |
{-| Diskstats proc file parser |
|
3 |
|
|
4 |
This module holds the definition of the parser that extracts status |
|
5 |
information about the disks of the system from the @/proc/diskstats@ file. |
|
6 |
|
|
7 |
-} |
|
8 |
{- |
|
9 |
|
|
10 |
Copyright (C) 2013 Google Inc. |
|
11 |
|
|
12 |
This program is free software; you can redistribute it and/or modify |
|
13 |
it under the terms of the GNU General Public License as published by |
|
14 |
the Free Software Foundation; either version 2 of the License, or |
|
15 |
(at your option) any later version. |
|
16 |
|
|
17 |
This program is distributed in the hope that it will be useful, but |
|
18 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
20 |
General Public License for more details. |
|
21 |
|
|
22 |
You should have received a copy of the GNU General Public License |
|
23 |
along with this program; if not, write to the Free Software |
|
24 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
25 |
02110-1301, USA. |
|
26 |
|
|
27 |
-} |
|
28 |
module Ganeti.Block.Diskstats.Parser (diskstatsParser) where |
|
29 |
|
|
30 |
import Control.Applicative ((<*>), (*>), (<*), (<$>)) |
|
31 |
import qualified Data.Attoparsec.Text as A |
|
32 |
import qualified Data.Attoparsec.Combinator as AC |
|
33 |
import Data.Attoparsec.Text (Parser) |
|
34 |
import Data.Text (unpack) |
|
35 |
|
|
36 |
import Ganeti.Block.Diskstats.Types |
|
37 |
|
|
38 |
-- * Utility functions |
|
39 |
|
|
40 |
-- | Our own space-skipping function, because A.skipSpace also skips |
|
41 |
-- newline characters. It skips ZERO or more spaces, so it does not |
|
42 |
-- fail if there are no spaces. |
|
43 |
skipSpaces :: Parser () |
|
44 |
skipSpaces = A.skipWhile A.isHorizontalSpace |
|
45 |
|
|
46 |
-- | A parser recognizing a number preceeded by spaces. |
|
47 |
numberP :: Parser Int |
|
48 |
numberP = skipSpaces *> A.decimal |
|
49 |
|
|
50 |
-- | A parser recognizing a word preceded by spaces, and closed by a space. |
|
51 |
stringP :: Parser String |
|
52 |
stringP = skipSpaces *> fmap unpack (A.takeWhile $ not . A.isHorizontalSpace) |
|
53 |
|
|
54 |
-- * Parser implementation |
|
55 |
|
|
56 |
-- | The parser for one line of the diskstatus file. |
|
57 |
oneDiskstatsParser :: Parser Diskstats |
|
58 |
oneDiskstatsParser = |
|
59 |
Diskstats <$> numberP <*> numberP <*> stringP <*> numberP <*> numberP |
|
60 |
<*> numberP <*> numberP <*> numberP <*> numberP <*> numberP <*> numberP |
|
61 |
<*> numberP <*> numberP <*> numberP <* A.endOfLine |
|
62 |
|
|
63 |
-- | The parser for a whole diskstatus file. |
|
64 |
diskstatsParser :: Parser [Diskstats] |
|
65 |
diskstatsParser = oneDiskstatsParser `AC.manyTill` A.endOfInput |
b/src/Ganeti/Block/Diskstats/Types.hs | ||
---|---|---|
1 |
{-# LANGUAGE TemplateHaskell #-} |
|
2 |
{-| Diskstats data types |
|
3 |
|
|
4 |
This module holds the definition of the data types describing the status of the |
|
5 |
disks according to the information contained in @/proc/diskstats@. |
|
6 |
|
|
7 |
-} |
|
8 |
{- |
|
9 |
|
|
10 |
Copyright (C) 2013 Google Inc. |
|
11 |
|
|
12 |
This program is free software; you can redistribute it and/or modify |
|
13 |
it under the terms of the GNU General Public License as published by |
|
14 |
the Free Software Foundation; either version 2 of the License, or |
|
15 |
(at your option) any later version. |
|
16 |
|
|
17 |
This program is distributed in the hope that it will be useful, but |
|
18 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
20 |
General Public License for more details. |
|
21 |
|
|
22 |
You should have received a copy of the GNU General Public License |
|
23 |
along with this program; if not, write to the Free Software |
|
24 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
25 |
02110-1301, USA. |
|
26 |
|
|
27 |
-} |
|
28 |
module Ganeti.Block.Diskstats.Types |
|
29 |
( Diskstats(..) |
|
30 |
) where |
|
31 |
|
|
32 |
import Ganeti.THH |
|
33 |
|
|
34 |
|
|
35 |
-- | This is the format of the report produced by each data collector. |
|
36 |
$(buildObject "Diskstats" "ds" |
|
37 |
[ simpleField "major" [t| Int |] |
|
38 |
, simpleField "minor" [t| Int |] |
|
39 |
, simpleField "name" [t| String |] |
|
40 |
, simpleField "reads" [t| Int |] |
|
41 |
, simpleField "mergedReads" [t| Int |] |
|
42 |
, simpleField "secRead" [t| Int |] |
|
43 |
, simpleField "timeRead" [t| Int |] |
|
44 |
, simpleField "writes" [t| Int |] |
|
45 |
, simpleField "mergedWrites" [t| Int |] |
|
46 |
, simpleField "secWritten" [t| Int |] |
|
47 |
, simpleField "timeWrite" [t| Int |] |
|
48 |
, simpleField "ios" [t| Int |] |
|
49 |
, simpleField "timeIO" [t| Int |] |
|
50 |
, simpleField "wIOmillis" [t| Int |] |
|
51 |
]) |
Also available in: Unified diff