]> gitweb @ CieloNegro.org - hs-rrdtool.git/blob - Database/RRDtool/Create.hs
revised HLength
[hs-rrdtool.git] / Database / RRDtool / Create.hs
1 module Database.RRDtool.Create
2     ( DataSource
3     , ExternalDSType(..)
4     , ExternalDataSource(..)
5     , ComputedDataSource(..)
6     , createRRD
7
8     -- Data.HList
9     , (.*.)    
10     , HNil(..)
11
12     -- Database.RRDtool.Expression
13     , Constant(..)
14     , IsVarName
15     , Variable(..)
16     , CommonUnaryOp(..)
17     , CommonBinaryOp(..)
18     , CommonTrinaryOp(..)
19     , CommonSetOp(..)
20     , TrendOp(..)
21     , VariableShiftPredictOp(..)
22     , FixedShiftPredictOp(..)
23     , CommonValue(..)
24     )
25     where
26
27 import Data.HList
28 import Data.Time.Clock
29 import Data.Time.Clock.POSIX
30 import Database.RRDtool.Expression
31
32
33 -- |A single RRD can accept input from several data sources (DS), for
34 -- example incoming and outgoing traffic on a specific communication
35 -- line. With the DS configuration option you must define some basic
36 -- properties of each data source you want to store in the RRD.
37 --
38 -- /NOTE on COUNTER vs DERIVE/
39 --
40 -- by Don Baarda <don.baarda@baesystems.com>
41 --
42 -- If you cannot tolerate ever mistaking the occasional counter reset
43 -- for a legitimate counter wrap, and would prefer \"Unknowns\" for
44 -- all legitimate counter wraps and resets, always use DERIVE with
45 -- @'dsMin' = 0@. Otherwise, using COUNTER with a suitable max will
46 -- return correct values for all legitimate counter wraps, mark some
47 -- counter resets as \"Unknown\", but can mistake some counter resets
48 -- for a legitimate counter wrap.
49 --
50 -- For a 5 minute step and 32-bit counter, the probability of
51 -- mistaking a counter reset for a legitimate wrap is arguably about
52 -- 0.8% per 1Mbps of maximum bandwidth. Note that this equates to 80%
53 -- for 100Mbps interfaces, so for high bandwidth interfaces and a
54 -- 32bit counter, DERIVE with @'dsMin' = 0@ is probably preferable. If
55 -- you are using a 64bit counter, just about any max setting will
56 -- eliminate the possibility of mistaking a reset for a counter wrap.
57 class DataSource ds
58
59 data ExternalDSType
60     = GAUGE    -- ^GAUGE is for things like temperatures or number of
61                -- people in a room or the value of a RedHat share.
62     | COUNTER  -- ^COUNTER is for continuous incrementing counters
63                -- like the ifInOctets counter in a router. The COUNTER
64                -- data source assumes that the counter never
65                -- decreases, except when a counter overflows. The
66                -- update function takes the overflow into account. The
67                -- counter is stored as a per-second rate. When the
68                -- counter overflows, RRDtool checks if the overflow
69                -- happened at the 32bit or 64bit border and acts
70                -- accordingly by adding an appropriate value to the
71                -- result.
72     | DERIVE   -- ^DERIVE will store the derivative of the line going
73                -- from the last to the current value of the data
74                -- source. This can be useful for gauges, for example,
75                -- to measure the rate of people entering or leaving a
76                -- room. Internally, derive works exactly like COUNTER
77                -- but without overflow checks. So if your counter does
78                -- not reset at 32 or 64 bit you might want to use
79                -- DERIVE and combine it with a 'dsMin' value of 0.
80     | ABSOLUTE -- ^ABSOLUTE is for counters which get reset upon
81                -- reading. This is used for fast counters which tend
82                -- to overflow. So instead of reading them normally you
83                -- reset them after every read to make sure you have a
84                -- maximum time available before the next
85                -- overflow. Another usage is for things you count like
86                -- number of messages since the last update.
87     deriving (Show, Eq, Ord)
88
89 instance DataSource ExternalDSType
90
91 data ExternalDataSource
92     = ExternalDataSource {
93         -- |The name you will use to reference this particular data
94         -- source from an RRD. A ds name must be 1 to 19 characters
95         -- long in the characters @[a-zA-Z0-9_]@.
96         edsName :: !String
97         -- |The type of this data source.
98       , edsType :: !ExternalDSType
99         -- |Defines the maximum number of seconds that may pass
100         -- between two updates of this data source before the value of
101         -- the data source is assumed to be @*UNKNOWN*@.
102       , edsHeartbeat :: !NominalDiffTime
103         -- |'edsMin' and 'edsMax' Define the expected range values for
104         -- data supplied by a data source. If 'edsMin' and\/or 'edsMax'
105         -- any value outside the defined range will be regarded as
106         -- @*UNKNOWN*@. If you do not know or care about 'edsMin' and
107         -- 'edsMax', set them to 'Nothing' for unknown. Note that
108         -- 'edsMin' and 'edsMax' always refer to the processed values of
109         -- the DS. For a traffic-'COUNTER' type DS this would be the
110         -- maximum and minimum data-rate expected from the device.
111         --
112         -- If information on minimal\/maximal expected values is
113         -- available, always set the min and\/or max properties. This
114         -- will help RRDtool in doing a simple sanity check on the
115         -- data supplied when running update.
116       , edsMin :: !(Maybe Double)
117         -- |See 'edsMin'.
118       , edsMax :: !(Maybe Double)
119       }
120     deriving (Show, Eq, Ord)
121
122
123 -- |ComputedDataSource is for storing the result of a formula applied
124 -- to other data sources in the RRD. This data source is not supplied
125 -- a value on update, but rather its Primary Data Points (PDPs) are
126 -- computed from the PDPs of the data sources according to the
127 -- rpn-expression that defines the formula. Consolidation functions
128 -- are then applied normally to the PDPs of the COMPUTE data source
129 -- (that is the rpn-expression is only applied to generate PDPs). In
130 -- database software, such data sets are referred to as \"virtual\" or
131 -- \"computed\" columns.
132 --
133 -- FIXME: doc links
134 data ComputedDataSource e
135     = ComputedDataSource {
136         -- |See 'edsName'
137         cdsName :: !String
138         -- |rpn-expression defines the formula used to compute the
139         -- PDPs of a COMPUTE data source from other data sources in
140         -- the same \<RRD\>. It is similar to defining a CDEF argument
141         -- for the graph command.  For COMPUTE data sources, the
142         -- following RPN operations are not supported: COUNT, PREV,
143         -- TIME, and LTIME. In addition, in defining the RPN
144         -- expression, the COMPUTE data source may only refer to the
145         -- names of data source listed previously in the create
146         -- command. This is similar to the restriction that CDEFs must
147         -- refer only to DEFs and CDEFs previously defined in the same
148         -- graph command.
149         -- 
150         -- FIXME: doc links
151       , cdsExpr :: !e
152     }
153     deriving (Show, Eq, Ord)
154
155 instance IsCommonExpr e => DataSource (ComputedDataSource e)
156
157
158 dsTest = ComputedDataSource {
159            cdsName = "foo"
160 --       , dsExpr = Previous :<: Const 100
161 --       , dsExpr = Var "foo" :<: Const 100
162          , cdsExpr = AverageOf (Const 100 .*. Const 200 .*. HNil)
163          }
164
165 -- |The 'createRRD' function lets you set up new Round Robin Database
166 -- (RRD) files. The file is created at its final, full size and filled
167 -- with @*UNKNOWN*@ data.
168 createRRD
169     :: FilePath -- ^The name of the RRD you want to create. RRD files
170                 -- should end with the extension @.rrd@. However,
171                 -- RRDtool will accept any filename.
172     -> Bool -- ^Do not clobber an existing file of the same name.
173     -> Maybe POSIXTime -- ^Specifies the time in seconds since
174                        -- @1970-01-01 UTC@ when the first value should
175                        -- be added to the RRD. RRDtool will not accept
176                        -- any data timed before or at the time
177                        -- specified. (default: @now - 10s@)
178     -> Maybe NominalDiffTime -- ^Specifies the base interval in
179                              -- seconds with which data will be fed
180                              -- into the RRD. (default: 300 sec)
181 --    -> [DataSource] -- ^Data sources to accept input from.
182     -> IO ()
183 createRRD = error "FIXME"