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