-
Notifications
You must be signed in to change notification settings - Fork 1
/
Types.hs
186 lines (153 loc) · 5.99 KB
/
Types.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
--
-- Copyright © 2013-2015 Anchor Systems, Pty Ltd and Others
--
-- The code in this file, and the program it is a part of, is
-- made available to you by its authors as open source software:
-- you can redistribute it and/or modify it under the terms of
-- the 3-clause BSD licence.
--
-- /Description/
-- This module exports the public-facing Ceilometer types
-- and the interface for them.
--
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS -fno-warn-unused-binds #-}
module Ceilometer.Types
( -- * Payload Raws
PRSimple(PRSimple), prSimple
, PRCompoundEvent(PRCompoundEvent), prCompoundEvent
, PRCompoundPollster(PRCompoundPollster), prCompoundPollster
-- * Payload Decoded Fields
, PFValue, PFValue64, PFValue32, PFValueText
, PFEndpoint(..), pfEndpoint
, PFVolumeStatus(..), pfVolumeStatus
, PFVolumeVerb(..), pfVolumeVerb
, PFInstanceStatus(..), pfInstanceStatus
, PFImageStatus(..), pfImageStatus
, PFImageVerb(..), pfImageVerb
, PFSnapshotStatus(..), pfSnapshotStatus
, PFSnapshotVerb(..), pfSnapshotVerb
, PFIPStatus(..), pfIPStatus
, PFIPVerb(..), pfIPVerb
, PFIPAlloc(..), pfIPAlloc
-- * Payload Decoded Points
, PDVolume(PDVolume), pdVolume
, PDSSD(PDSSD), pdSSD
, PDCPU(PDCPU), pdCPU
, PDDiskRead(..), pdDiskRead
, PDDiskWrite(..), pdDiskWrite
, PDNeutronTx(..), pdNeutronTx
, PDNeutronRx(..), pdNeutronRx
, PDInstanceVCPU(PDInstanceVCPU), pdInstanceVCPU
, PDInstanceRAM(PDInstanceRAM), pdInstanceRAM
, PDInstanceDisk(PDInstanceDisk), pdInstanceDisk
, PDInstanceFlavor(PDInstanceFlavor), pdInstanceFlavor
, PDImage(PDImage), pdImage
, PDImagePollster(PDImagePollster), pdImagePollster
, PDSnapshot(PDSnapshot), pdSnapshot
, PDIP(PDIP), pdIP
-- * Values
, Valued, value
, Timed(Timed), time
-- * Interface
, Env(..), Filters(..)
, Flavor, FlavorMap
, siphashID
, filterByInstanceStatus
) where
import Control.Applicative
import Control.Lens hiding (Fold, Simple)
import Data.Binary (Word64)
import Data.Foldable
import Ceilometer.Types.Base
import Ceilometer.Types.CPU
import Ceilometer.Types.Disk
import Ceilometer.Types.Image
import Ceilometer.Types.Instance
import Ceilometer.Types.IP
import Ceilometer.Types.Neutron
import Ceilometer.Types.Snapshot
import Ceilometer.Types.Volume
import Control.PFold
import Vaultaire.Types
--------------------------------------------------------------------------------
-- | Information needed to parse/fold Ceilometer types, supplied by users.
--
data Env = Env { _flavormap :: FlavorMap
, _sourcedict :: SourceDict
, _filters :: Filters
, _start :: TimeStamp
, _end :: TimeStamp }
data Filters = Filters {
instanceStatusFilter :: PFInstanceStatus -> Bool
}
filterByInstanceStatus :: Filters -> (a -> PFInstanceStatus) -> a -> Bool
filterByInstanceStatus (Filters f) g = f . g
--------------------------------------------------------------------------------
-- | Values with a TimeStamp.
--
data Timed value = Timed { _time :: !Word64, _val :: value }
deriving (Show, Functor, Foldable, Traversable)
makeLenses ''Timed
-- | A family of lens that allows viewing/updating the payload value of decoded
-- Ceilometer points.
--
-- note: this is a Lens and not just a Getter since we wish to reuse the logic
-- for collector (making the points) and user (reading the points).
--
class Valued a where
type PFValue a
value :: Lens' a (PFValue a)
instance Valued a => Valued (Timed a) where
type PFValue (Timed a) = PFValue a
value f (Timed t x) = Timed t <$> value f x
instance Valued PDCPU where
type PFValue PDCPU = PFValue64
value f (PDCPU x) = PDCPU <$> f x
instance Valued PDDiskRead where
type PFValue PDDiskRead = PFValue64
value f (PDDiskRead x) = PDDiskRead <$> f x
instance Valued PDDiskWrite where
type PFValue PDDiskWrite = PFValue64
value f (PDDiskWrite x) = PDDiskWrite <$> f x
instance Valued PDNeutronTx where
type PFValue PDNeutronTx = PFValue64
value f (PDNeutronTx x) = PDNeutronTx <$> f x
instance Valued PDNeutronRx where
type PFValue PDNeutronRx = PFValue64
value f (PDNeutronRx x) = PDNeutronRx <$> f x
instance Valued PDVolume where
type PFValue PDVolume = PFValue32
value f (PDVolume a b c x) = PDVolume a b c <$> f x
instance Valued PDSSD where
type PFValue PDSSD = PFValue32
value f (PDSSD a b c x) = PDSSD a b c <$> f x
instance Valued PDInstanceFlavor where
type PFValue PDInstanceFlavor = PFValueText
value f (PDInstanceFlavor s x) = PDInstanceFlavor s <$> f x
instance Valued PDInstanceVCPU where
type PFValue PDInstanceVCPU = PFValue32
value f (PDInstanceVCPU s x) = PDInstanceVCPU s <$> f x
instance Valued PDInstanceRAM where
type PFValue PDInstanceRAM = PFValue32
value f (PDInstanceRAM s x) = PDInstanceRAM s <$> f x
instance Valued PDInstanceDisk where
type PFValue PDInstanceDisk = PFValue32
value f (PDInstanceDisk s x) = PDInstanceDisk s <$> f x
instance Valued PDImage where
type PFValue PDImage = PFValue32
value f (PDImage s v e x) = PDImage s v e <$> f x
instance Valued PDImagePollster where
type PFValue PDImagePollster = PFValue64
value f (PDImagePollster x) = PDImagePollster <$> f x
instance Valued PDSnapshot where
type PFValue PDSnapshot = PFValue32
value f (PDSnapshot a b c x) = PDSnapshot a b c <$> f x
instance Valued PDIP where
type PFValue PDIP = PFIPAlloc
value f (PDIP a b c x) = PDIP a b c <$> f x