Store keys as ByteStrings
[ganeti-github.git] / src / Ganeti / DataCollectors.hs
1 {-| Definition of the data collectors used by MonD.
2
3 -}
4
5 {-
6
7 Copyright (C) 2014 Google Inc.
8 All rights reserved.
9
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are
12 met:
13
14 1. Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 -}
34
35 module Ganeti.DataCollectors( collectors ) where
36
37 import qualified Data.ByteString.UTF8 as UTF8
38 import Data.Map (findWithDefault)
39 import Data.Monoid (mempty)
40
41 import qualified Ganeti.DataCollectors.CPUload as CPUload
42 import qualified Ganeti.DataCollectors.Diskstats as Diskstats
43 import qualified Ganeti.DataCollectors.Drbd as Drbd
44 import qualified Ganeti.DataCollectors.InstStatus as InstStatus
45 import qualified Ganeti.DataCollectors.Lv as Lv
46 import qualified Ganeti.DataCollectors.XenCpuLoad as XenCpuLoad
47 import Ganeti.DataCollectors.Types (DataCollector(..),ReportBuilder(..))
48 import Ganeti.JSON (GenericContainer(..))
49 import Ganeti.Objects
50 import Ganeti.Types
51
52 -- | The list of available builtin data collectors.
53 collectors :: [DataCollector]
54 collectors =
55 [ cpuLoadCollector
56 , xenCpuLoadCollector
57 , diskStatsCollector
58 , drdbCollector
59 , instStatusCollector
60 , lvCollector
61 ]
62 where
63 f .&&. g = \x y -> f x y && g x y
64 xenHypervisor = flip elem [XenPvm, XenHvm]
65 xenCluster _ cfg =
66 any xenHypervisor . clusterEnabledHypervisors $ configCluster cfg
67 collectorConfig name cfg =
68 let config = fromContainer . clusterDataCollectors $ configCluster cfg
69 in findWithDefault mempty (UTF8.fromString name) config
70 updateInterval name cfg = dataCollectorInterval $ collectorConfig name cfg
71 activeConfig name cfg = dataCollectorActive $ collectorConfig name cfg
72 diskStatsCollector =
73 DataCollector Diskstats.dcName Diskstats.dcCategory
74 Diskstats.dcKind (StatelessR Diskstats.dcReport) Nothing activeConfig
75 updateInterval
76 drdbCollector =
77 DataCollector Drbd.dcName Drbd.dcCategory Drbd.dcKind
78 (StatelessR Drbd.dcReport) Nothing activeConfig updateInterval
79 instStatusCollector =
80 DataCollector InstStatus.dcName InstStatus.dcCategory
81 InstStatus.dcKind (StatelessR InstStatus.dcReport) Nothing
82 (xenCluster .&&. activeConfig) updateInterval
83 lvCollector =
84 DataCollector Lv.dcName Lv.dcCategory Lv.dcKind
85 (StatelessR Lv.dcReport) Nothing activeConfig updateInterval
86 cpuLoadCollector =
87 DataCollector CPUload.dcName CPUload.dcCategory CPUload.dcKind
88 (StatefulR CPUload.dcReport) (Just CPUload.dcUpdate) activeConfig
89 updateInterval
90 xenCpuLoadCollector =
91 DataCollector XenCpuLoad.dcName XenCpuLoad.dcCategory XenCpuLoad.dcKind
92 (StatefulR XenCpuLoad.dcReport) (Just XenCpuLoad.dcUpdate) activeConfig
93 updateInterval