root / src / Ganeti / DataCollectors / Types.hs @ f0e4b2a4
History | View | Annotate | Download (2.6 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 | a895fa19 | Michele Tartara | Copyright (C) 2012, 2013 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 | f0e4b2a4 | Michele Tartara | , DCCategory(..) |
31 | a895fa19 | Michele Tartara | , DCVersion(..) |
32 | 13d3acab | Michele Tartara | , buildReport |
33 | 13d3acab | Michele Tartara | ) where |
34 | 13d3acab | Michele Tartara | |
35 | 13d3acab | Michele Tartara | import Text.JSON |
36 | 13d3acab | Michele Tartara | |
37 | 13d3acab | Michele Tartara | import Ganeti.Constants as C |
38 | 13d3acab | Michele Tartara | import Ganeti.THH |
39 | 13d3acab | Michele Tartara | import Ganeti.Utils (getCurrentTime) |
40 | 13d3acab | Michele Tartara | |
41 | f0e4b2a4 | Michele Tartara | -- | The possible classes a data collector can belong to. |
42 | f0e4b2a4 | Michele Tartara | data DCCategory = DCInstance | DCStorage | DCDaemon | DCHypervisor |
43 | f0e4b2a4 | Michele Tartara | deriving (Show, Eq) |
44 | f0e4b2a4 | Michele Tartara | |
45 | f0e4b2a4 | Michele Tartara | -- | The JSON instance for DCCategory. |
46 | f0e4b2a4 | Michele Tartara | instance JSON DCCategory where |
47 | f0e4b2a4 | Michele Tartara | showJSON = showJSON . show |
48 | f0e4b2a4 | Michele Tartara | readJSON = |
49 | f0e4b2a4 | Michele Tartara | error "JSON read instance not implemented for type DCCategory" |
50 | f0e4b2a4 | Michele Tartara | |
51 | a895fa19 | Michele Tartara | -- | Type representing the version number of a data collector. |
52 | a895fa19 | Michele Tartara | data DCVersion = DCVerBuiltin | DCVersion String deriving (Show, Eq) |
53 | a895fa19 | Michele Tartara | |
54 | a895fa19 | Michele Tartara | -- | The JSON instance for DCVersion. |
55 | a895fa19 | Michele Tartara | instance JSON DCVersion where |
56 | a895fa19 | Michele Tartara | showJSON DCVerBuiltin = showJSON C.builtinDataCollectorVersion |
57 | a895fa19 | Michele Tartara | showJSON (DCVersion v) = showJSON v |
58 | a895fa19 | Michele Tartara | readJSON = error "JSON read instance not implemented for type DCVersion" |
59 | a895fa19 | Michele Tartara | |
60 | 13d3acab | Michele Tartara | -- | This is the format of the report produced by each data collector. |
61 | 13d3acab | Michele Tartara | $(buildObject "DCReport" "dcReport" |
62 | 13d3acab | Michele Tartara | [ simpleField "name" [t| String |] |
63 | a895fa19 | Michele Tartara | , simpleField "version" [t| DCVersion |] |
64 | 13d3acab | Michele Tartara | , simpleField "format_version" [t| Int |] |
65 | 13d3acab | Michele Tartara | , simpleField "timestamp" [t| Integer |] |
66 | f0e4b2a4 | Michele Tartara | , optionalNullSerField $ |
67 | f0e4b2a4 | Michele Tartara | simpleField "category" [t| DCCategory |] |
68 | 13d3acab | Michele Tartara | , simpleField "data" [t| JSValue |] |
69 | 13d3acab | Michele Tartara | ]) |
70 | 13d3acab | Michele Tartara | |
71 | 13d3acab | Michele Tartara | -- | Utility function for building a report automatically adding the current |
72 | 13d3acab | Michele Tartara | -- timestamp (rounded up to seconds). |
73 | 13d3acab | Michele Tartara | -- If the version is not specified, it will be set to the value indicating |
74 | 13d3acab | Michele Tartara | -- a builtin collector. |
75 | f0e4b2a4 | Michele Tartara | buildReport :: String -> DCVersion -> Int -> Maybe DCCategory -> JSValue |
76 | f0e4b2a4 | Michele Tartara | -> IO DCReport |
77 | f0e4b2a4 | Michele Tartara | buildReport name version format_version category jsonData = do |
78 | 13d3acab | Michele Tartara | now <- getCurrentTime |
79 | 13d3acab | Michele Tartara | let timestamp = now * 1000000000 :: Integer |
80 | f0e4b2a4 | Michele Tartara | return $ DCReport name version format_version timestamp category jsonData |