root / src / Ganeti / DataCollectors / Types.hs @ 13d3acab
History | View | Annotate | Download (1.9 kB)
1 | 13d3acab | Michele Tartara | {-# LANGUAGE TemplateHaskell #-} |
---|---|---|---|
2 | 13d3acab | Michele Tartara | |
3 | 13d3acab | Michele Tartara | {-| Implementation of the Ganeti data collector types. |
4 | 13d3acab | Michele Tartara | |
5 | 13d3acab | Michele Tartara | -} |
6 | 13d3acab | Michele Tartara | |
7 | 13d3acab | Michele Tartara | {- |
8 | 13d3acab | Michele Tartara | |
9 | 13d3acab | Michele Tartara | Copyright (C) 2012 Google Inc. |
10 | 13d3acab | Michele Tartara | |
11 | 13d3acab | Michele Tartara | This program is free software; you can redistribute it and/or modify |
12 | 13d3acab | Michele Tartara | it under the terms of the GNU General Public License as published by |
13 | 13d3acab | Michele Tartara | the Free Software Foundation; either version 2 of the License, or |
14 | 13d3acab | Michele Tartara | (at your option) any later version. |
15 | 13d3acab | Michele Tartara | |
16 | 13d3acab | Michele Tartara | This program is distributed in the hope that it will be useful, but |
17 | 13d3acab | Michele Tartara | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | 13d3acab | Michele Tartara | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | 13d3acab | Michele Tartara | General Public License for more details. |
20 | 13d3acab | Michele Tartara | |
21 | 13d3acab | Michele Tartara | You should have received a copy of the GNU General Public License |
22 | 13d3acab | Michele Tartara | along with this program; if not, write to the Free Software |
23 | 13d3acab | Michele Tartara | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
24 | 13d3acab | Michele Tartara | 02110-1301, USA. |
25 | 13d3acab | Michele Tartara | |
26 | 13d3acab | Michele Tartara | -} |
27 | 13d3acab | Michele Tartara | |
28 | 13d3acab | Michele Tartara | module Ganeti.DataCollectors.Types |
29 | 13d3acab | Michele Tartara | ( DCReport(..) |
30 | 13d3acab | Michele Tartara | , buildReport |
31 | 13d3acab | Michele Tartara | ) where |
32 | 13d3acab | Michele Tartara | |
33 | 13d3acab | Michele Tartara | import Data.Maybe |
34 | 13d3acab | Michele Tartara | import Text.JSON |
35 | 13d3acab | Michele Tartara | |
36 | 13d3acab | Michele Tartara | import Ganeti.Constants as C |
37 | 13d3acab | Michele Tartara | import Ganeti.THH |
38 | 13d3acab | Michele Tartara | import Ganeti.Utils (getCurrentTime) |
39 | 13d3acab | Michele Tartara | |
40 | 13d3acab | Michele Tartara | -- | This is the format of the report produced by each data collector. |
41 | 13d3acab | Michele Tartara | $(buildObject "DCReport" "dcReport" |
42 | 13d3acab | Michele Tartara | [ simpleField "name" [t| String |] |
43 | 13d3acab | Michele Tartara | , simpleField "version" [t| String |] |
44 | 13d3acab | Michele Tartara | , simpleField "format_version" [t| Int |] |
45 | 13d3acab | Michele Tartara | , simpleField "timestamp" [t| Integer |] |
46 | 13d3acab | Michele Tartara | , simpleField "data" [t| JSValue |] |
47 | 13d3acab | Michele Tartara | ]) |
48 | 13d3acab | Michele Tartara | |
49 | 13d3acab | Michele Tartara | -- | Utility function for building a report automatically adding the current |
50 | 13d3acab | Michele Tartara | -- timestamp (rounded up to seconds). |
51 | 13d3acab | Michele Tartara | -- If the version is not specified, it will be set to the value indicating |
52 | 13d3acab | Michele Tartara | -- a builtin collector. |
53 | 13d3acab | Michele Tartara | buildReport :: String -> Maybe String -> Int -> JSValue -> IO DCReport |
54 | 13d3acab | Michele Tartara | buildReport name version format_version jsonData = do |
55 | 13d3acab | Michele Tartara | now <- getCurrentTime |
56 | 13d3acab | Michele Tartara | let timestamp = now * 1000000000 :: Integer |
57 | 13d3acab | Michele Tartara | ver = fromMaybe C.builtinDataCollectorVersion version |
58 | 13d3acab | Michele Tartara | return $ DCReport name ver format_version timestamp jsonData |