X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Database%2FRRDtool.hs;h=45ae91a3a36da7f675fca245a6de2c66abbcf07d;hb=1376286d127998a72ca99d2809405355eafe69cc;hp=7ffef4436be2fdbf80134594598e784bba4ec7e6;hpb=683cfdfbe58b5baf9fc6973986a3850d0a2f3df9;p=hs-rrdtool.git diff --git a/Database/RRDtool.hs b/Database/RRDtool.hs index 7ffef44..45ae91a 100644 --- a/Database/RRDtool.hs +++ b/Database/RRDtool.hs @@ -1,10 +1,33 @@ module Database.RRDtool ( DataSource(..) - , Expr(..) + + , Expr + , CommonExpr + , IterativeExpr + , AggregativeExpr + + , ExprSet + , CommonExprSet + + , Constant(..) + , Variable(..) + , CommonUnaryOp(..) + , CommonBinaryOp(..) + , CommonTrinaryOp(..) + , CommonSetOp(..) + , TrendOp(..) + , VariableShiftPredictOp(..) + , FixedShiftPredictOp(..) + , CommonValue(..) + , IterativeValue(..) + , IterativeValueOf(..) + , AggregativeUnaryOp(..) + , createRRD ) where +import Data.HList import Data.Time.Clock import Data.Time.Clock.POSIX @@ -36,7 +59,7 @@ import Data.Time.Clock.POSIX data DataSource = -- |GAUGE is for things like temperatures or number of people in -- a room or the value of a RedHat share. - GAUGE { + GAUGE { -- |The name you will use to reference this particular data -- source from an RRD. A ds-name must be 1 to 19 characters -- long in the characters @[a-zA-Z0-9_]@. @@ -61,79 +84,242 @@ data DataSource , dsMin :: !(Maybe Double) -- |See 'dsMin'. , dsMax :: !(Maybe Double) - } - -- |COUNTER is for continuous incrementing counters like the - -- ifInOctets counter in a router. The COUNTER data source - -- assumes that the counter never decreases, except when a - -- counter overflows. The update function takes the overflow - -- into account. The counter is stored as a per-second - -- rate. When the counter overflows, RRDtool checks if the - -- overflow happened at the 32bit or 64bit border and acts - -- accordingly by adding an appropriate value to the result. + } + -- |COUNTER is for continuous incrementing counters like the + -- ifInOctets counter in a router. The COUNTER data source assumes + -- that the counter never decreases, except when a counter + -- overflows. The update function takes the overflow into + -- account. The counter is stored as a per-second rate. When the + -- counter overflows, RRDtool checks if the overflow happened at + -- the 32bit or 64bit border and acts accordingly by adding an + -- appropriate value to the result. | COUNTER { dsName :: !String , dsHeartbeat :: !NominalDiffTime , dsMin :: !(Maybe Double) , dsMax :: !(Maybe Double) - } - -- |DERIVE will store the derivative of the line going from the - -- last to the current value of the data source. This can be - -- useful for gauges, for example, to measure the rate of people - -- entering or leaving a room. Internally, derive works exactly - -- like COUNTER but without overflow checks. So if your counter - -- does not reset at 32 or 64 bit you might want to use DERIVE - -- and combine it with a 'dsMin' value of 0. + } + -- |DERIVE will store the derivative of the line going from the + -- last to the current value of the data source. This can be + -- useful for gauges, for example, to measure the rate of people + -- entering or leaving a room. Internally, derive works exactly + -- like COUNTER but without overflow checks. So if your counter + -- does not reset at 32 or 64 bit you might want to use DERIVE and + -- combine it with a 'dsMin' value of 0. | DERIVE { dsName :: !String , dsHeartbeat :: !NominalDiffTime , dsMin :: !(Maybe Double) , dsMax :: !(Maybe Double) - } - -- |ABSOLUTE is for counters which get reset upon reading. This - -- is used for fast counters which tend to overflow. So instead - -- of reading them normally you reset them after every read to - -- make sure you have a maximum time available before the next - -- overflow. Another usage is for things you count like number - -- of messages since the last update. + } + -- |ABSOLUTE is for counters which get reset upon reading. This is + -- used for fast counters which tend to overflow. So instead of + -- reading them normally you reset them after every read to make + -- sure you have a maximum time available before the next + -- overflow. Another usage is for things you count like number of + -- messages since the last update. | ABSOLUTE { dsName :: !String , dsHeartbeat :: !NominalDiffTime , dsMin :: !(Maybe Double) , dsMax :: !(Maybe Double) - } - -- |COMPUTE is for storing the result of a formula applied to - -- other data sources in the RRD. This data source is not - -- supplied a value on update, but rather its Primary Data - -- Points (PDPs) are computed from the PDPs of the data sources - -- according to the rpn-expression that defines the - -- formula. Consolidation functions are then applied normally to - -- the PDPs of the COMPUTE data source (that is the - -- rpn-expression is only applied to generate PDPs). In database - -- software, such data sets are referred to as \"virtual\" or - -- \"computed\" columns. - -- - -- FIXME: doc links - | COMPUTE { + } + -- |COMPUTE is for storing the result of a formula applied to + -- other data sources in the RRD. This data source is not supplied + -- a value on update, but rather its Primary Data Points (PDPs) + -- are computed from the PDPs of the data sources according to the + -- rpn-expression that defines the formula. Consolidation + -- functions are then applied normally to the PDPs of the COMPUTE + -- data source (that is the rpn-expression is only applied to + -- generate PDPs). In database software, such data sets are + -- referred to as \"virtual\" or \"computed\" columns. + -- + -- FIXME: doc links + | forall a. CommonExpr a => COMPUTE { dsName :: !String - -- |rpn-expression defines the formula used to compute the PDPs - -- of a COMPUTE data source from other data sources in the same - -- \. It is similar to defining a CDEF argument for the - -- graph command. For COMPUTE data sources, the following RPN - -- operations are not supported: COUNT, PREV, TIME, and - -- LTIME. In addition, in defining the RPN expression, the - -- COMPUTE data source may only refer to the names of data - -- source listed previously in the create command. This is - -- similar to the restriction that CDEFs must refer only to DEFs - -- and CDEFs previously defined in the same graph command. - -- - -- FIXME: doc links - , dsExpr :: !Expr - } - deriving (Eq, Ord, Show) - -data Expr - = UNK + -- |rpn-expression defines the formula used to compute the + -- PDPs of a COMPUTE data source from other data sources in + -- the same \. It is similar to defining a CDEF argument + -- for the graph command. For COMPUTE data sources, the + -- following RPN operations are not supported: COUNT, PREV, + -- TIME, and LTIME. In addition, in defining the RPN + -- expression, the COMPUTE data source may only refer to the + -- names of data source listed previously in the create + -- command. This is similar to the restriction that CDEFs must + -- refer only to DEFs and CDEFs previously defined in the same + -- graph command. + -- + -- FIXME: doc links + , dsExpr :: !a + } + +dsTest :: DataSource +dsTest = COMPUTE { + dsName = "foo" +-- , dsExpr = Previous :<: Const 100 +-- , dsExpr = Var "foo" :<: Const 100 + , dsExpr = AverageOf (Const 100 .*. Const 200 .*. HNil) + } + +class (Show e, Eq e) => Expr e +class Expr e => CommonExpr e +class Expr e => IterativeExpr e +class Expr e => AggregativeExpr e +instance CommonExpr e => IterativeExpr e + +--class MentionedVars + +class (Show es, Eq es, HList es) => ExprSet es +instance ExprSet HNil +instance (Expr e, ExprSet es) => ExprSet (HCons e es) + +class (Show es, Eq es, HList es) => CommonExprSet es +instance CommonExprSet es => ExprSet es +instance CommonExprSet HNil +instance (CommonExpr e, CommonExprSet es) => CommonExprSet (HCons e es) + + +-- Constants and variable names +data Constant + = Const !Double + deriving (Show, Eq, Ord) +instance Expr Constant +instance CommonExpr Constant + +class (Show a, Eq a) => Variable a where + varName :: a -> String + +instance Variable a => Expr a +instance Variable a => CommonExpr a + +-- Common operators +data CommonUnaryOp a + = IsUnknown !a + | IsInfinity !a + | Sin !a + | Cos !a + | Log !a + | Exp !a + | Sqrt !a + | Atan !a + | Floor !a + | Ceil !a + | Deg2Rad !a + | Rad2Deg !a + | Abs !a + deriving (Show, Eq, Ord) +instance Expr a => Expr (CommonUnaryOp a) +instance CommonExpr a => CommonExpr (CommonUnaryOp a) + +data CommonBinaryOp a b + = !a :<: !b + | !a :<=: !b + | !a :>: !b + | !a :>=: !b + | !a :==: !b + | !a :/=: !b + | Min !a !b + | Max !a !b + | !a :+: !b + | !a :-: !b + | !a :*: !b + | !a :/: !b + | !a :%: !b + | AddNaN !a !b + | AtanXY !a !b + deriving (Show, Eq, Ord) +instance (Expr a, Expr b) + => Expr (CommonBinaryOp a b) +instance (CommonExpr a, CommonExpr b) + => CommonExpr (CommonBinaryOp a b) + +data CommonTrinaryOp a b c + = If !a !b !c + | Limit !a !b !c + deriving (Show, Eq, Ord) +instance (Expr a, Expr b, Expr c) + => Expr (CommonTrinaryOp a b c) +instance (CommonExpr a, CommonExpr b, CommonExpr c) + => CommonExpr (CommonTrinaryOp a b c) + +-- SORT and REV can't be expressed in this way as they pushes possibly +-- multiple values onto the stack... + +data CommonSetOp es + = AverageOf !es + deriving (Show, Eq, Ord) +instance ExprSet es => Expr (CommonSetOp es) +instance CommonExprSet es => CommonExpr (CommonSetOp es) + +data TrendOp v a + = Trend !v !a + | TrendNan !v !a + deriving (Show, Eq, Ord) +instance (Variable v, Expr a) => Expr (TrendOp v a) +instance (Variable v, CommonExpr a) => CommonExpr (TrendOp v a) + +data VariableShiftPredictOp ss w v + = VariableShiftPredictAverage !ss !w !v + | VariableShiftPredictSigma !ss !w !v + deriving (Show, Eq, Ord) +instance (ExprSet ss, Expr w, Variable v) + => Expr (VariableShiftPredictOp ss w v) +instance (CommonExprSet ss, CommonExpr w, Variable v) + => CommonExpr (VariableShiftPredictOp ss w v) + +data FixedShiftPredictOp sm w v + = FixedShiftPredictAverage !sm !w !v + | FixedShiftPredictSigma !sm !w !v + deriving (Show, Eq, Ord) +instance (Expr sm, Expr w, Variable v) + => Expr (FixedShiftPredictOp sm w v) +instance (CommonExpr sm, CommonExpr w, Variable v) + => CommonExpr (FixedShiftPredictOp sm w v) + +-- Common special values +data CommonValue + = Unknown + | Infinity + | NegativeInfinity + | Now + deriving (Show, Eq, Ord) +instance Expr CommonValue +instance CommonExpr CommonValue + +-- Iterative special values +data IterativeValue + = Previous + | Count + | TakenTime + | TakenLocalTime + deriving (Show, Eq, Ord) +instance Expr IterativeValue +instance IterativeExpr IterativeValue + +data IterativeValueOf v + = PreviousOf !v + deriving (Show, Eq, Ord) +instance Variable v => Expr (IterativeValueOf v) +instance Variable v => IterativeExpr (IterativeValueOf v) + +-- Aggregative operators (fairly restricted due to rrdtool's +-- restriction) +data AggregativeUnaryOp v + = Maximum !v + | Minimum !v + | Average !v + | StandardDeviation !v + | First !v + | Last !v + | Total !v + | Percent !v !Constant + | PercentNan !v !Constant + | LSLSlope !v + | LSLInt !v + | LSLCorrel !v deriving (Show, Eq, Ord) +instance Variable v => Expr (AggregativeUnaryOp v) +instance Variable v => AggregativeExpr (AggregativeUnaryOp v) -- |The 'createRRD' function lets you set up new Round Robin Database -- (RRD) files. The file is created at its final, full size and filled