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