root / src / Ganeti / Storage / Diskstats / Parser.hs @ de36f091
History | View | Annotate | Download (2.1 kB)
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.Storage.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 |
|
35 |
import Ganeti.Parsers |
36 |
import Ganeti.Storage.Diskstats.Types |
37 |
|
38 |
-- * Parser implementation |
39 |
|
40 |
-- | The parser for one line of the diskstatus file. |
41 |
oneDiskstatsParser :: Parser Diskstats |
42 |
oneDiskstatsParser = |
43 |
let majorP = numberP |
44 |
minorP = numberP |
45 |
nameP = stringP |
46 |
readsNumP = numberP |
47 |
mergedReadsP = numberP |
48 |
secReadP = numberP |
49 |
timeReadP = numberP |
50 |
writesP = numberP |
51 |
mergedWritesP = numberP |
52 |
secWrittenP = numberP |
53 |
timeWriteP = numberP |
54 |
iosP = numberP |
55 |
timeIOP = numberP |
56 |
wIOmillisP = numberP |
57 |
in |
58 |
Diskstats <$> majorP <*> minorP <*> nameP <*> readsNumP <*> mergedReadsP |
59 |
<*> secReadP <*> timeReadP <*> writesP <*> mergedWritesP <*> secWrittenP |
60 |
<*> timeWriteP <*> iosP <*> timeIOP <*> wIOmillisP <* A.endOfLine |
61 |
|
62 |
-- | The parser for a whole diskstatus file. |
63 |
diskstatsParser :: Parser [Diskstats] |
64 |
diskstatsParser = oneDiskstatsParser `AC.manyTill` A.endOfInput |