X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Database%2FRRDtool%2FCreate.hs;h=28c0bfd357dc77ca5d81a0bb42985b07b6b4a54c;hb=256aad40f96ce034bc1aebd3302ecd8a86419163;hp=a3b51e54171d74e14d1ad822ece4fd8281a0c870;hpb=57b97113a93d366f14278a12b8170a1c06e258a1;p=hs-rrdtool.git diff --git a/Database/RRDtool/Create.hs b/Database/RRDtool/Create.hs index a3b51e5..28c0bfd 100644 --- a/Database/RRDtool/Create.hs +++ b/Database/RRDtool/Create.hs @@ -1,3 +1,13 @@ +{-# LANGUAGE + ExistentialQuantification, + FlexibleContexts, + FlexibleInstances, + MultiParamTypeClasses, + OverlappingInstances, + TypeFamilies, + UndecidableInstances + #-} +{-# LANGUAGE QuasiQuotes #-} -- DELETE THIS module Database.RRDtool.Create ( DataSource , ExternalDSType(..) @@ -6,7 +16,7 @@ module Database.RRDtool.Create , createRRD -- Data.HList - , (.*.) + , (.&.) , HNil(..) -- Database.RRDtool.Expression @@ -25,9 +35,11 @@ module Database.RRDtool.Create where import Data.HList +import Data.HList.Graph import Data.Time.Clock import Data.Time.Clock.POSIX import Database.RRDtool.Expression +import Types.Data.Bool -- |A single RRD can accept input from several data sources (DS), for @@ -54,7 +66,8 @@ import Database.RRDtool.Expression -- 32bit counter, DERIVE with @'dsMin' = 0@ is probably preferable. If -- you are using a 64bit counter, just about any max setting will -- eliminate the possibility of mistaking a reset for a counter wrap. -class DataSource ds +class DataSource ds where + type DSName ds data ExternalDSType = GAUGE -- ^GAUGE is for things like temperatures or number of @@ -86,14 +99,12 @@ data ExternalDSType -- number of messages since the last update. deriving (Show, Eq, Ord) -instance DataSource ExternalDSType - -data ExternalDataSource +data ExternalDataSource vn = ExternalDataSource { -- |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_]@. - edsName :: !String + edsName :: !vn -- |The type of this data source. , edsType :: !ExternalDSType -- |Defines the maximum number of seconds that may pass @@ -119,6 +130,13 @@ data ExternalDataSource } deriving (Show, Eq, Ord) +instance ( IsVarName vn ~ True + ) + => DataSource (ExternalDataSource vn) + where + type DSName (ExternalDataSource vn) = vn + +type instance MentionedVars (ExternalDataSource vn) = HNil -- |ComputedDataSource is for storing the result of a formula applied -- to other data sources in the RRD. This data source is not supplied @@ -131,10 +149,10 @@ data ExternalDataSource -- \"computed\" columns. -- -- FIXME: doc links -data ComputedDataSource e +data ComputedDataSource vn e = ComputedDataSource { -- |See 'edsName' - cdsName :: !String + cdsName :: !vn -- |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 @@ -152,32 +170,112 @@ data ComputedDataSource e } deriving (Show, Eq, Ord) -instance IsCommonExpr e => DataSource (ComputedDataSource e) +instance ( IsVarName vn ~ True + , IsCommonExpr e ~ True + ) + => DataSource (ComputedDataSource vn e) + where + type DSName (ComputedDataSource vn e) = vn +type instance MentionedVars (ComputedDataSource vn e) = MentionedVars e +{- dsTest = ComputedDataSource { cdsName = "foo" --- , dsExpr = Previous :<: Const 100 --- , dsExpr = Var "foo" :<: Const 100 +-- , cdsExpr = Previous :<: Const 100 +-- , cdsExpr = Var "foo" :<: Const 100 , cdsExpr = AverageOf (Const 100 .*. Const 200 .*. HNil) } +-} + +-- |The name of the RRD you want to create. RRD files should end with +-- the extension @.rrd@. However, RRDtool will accept any filename. +newtype RRDPath = RRDPath FilePath + +-- |Do not clobber an existing file of the same name. +data KeepOldRRD = KeepOldRRD + +-- |Specifies the time in seconds since @1970-01-01 UTC@ when the +-- first value should be added to the RRD. RRDtool will not accept any +-- data timed before or at the time specified. (default: @now - 10s@) +newtype RRDStartTime = RRDStartTime POSIXTime + +-- |Specifies the base interval in seconds with which data will be fed +-- into the RRD. (default: 300 sec) +newtype RRDInterval = RRDInterval NominalDiffTime + +class RRDSpec s +instance ( HOccurs RRDPath s + , HOccursOpt KeepOldRRD s + , HOccursOpt RRDStartTime s + , HOccursOpt RRDInterval s + , HOccurs RRDDataSources s + ) + => RRDSpec s + +class NonEmptyDSList l +instance ( DSList l + , DataSource d + ) + => NonEmptyDSList (HCons d l) + +class DSList l +instance DSList HNil +instance ( DSList l + , DataSource d + ) + => DSList (HCons d l) + +data RRDDataSources + = forall l. + ( NonEmptyDSList l + , HGraph l -- FIXME: this constraint is too weak + ) + => RRDDataSources l + +-- RRDDataSources is a graph. +instance ( DSList g + , HNodeSet g + , HNoDuplicates (HMap HNodeIDA g) + ) + => HGraph g + where + type HNodes g = g + +instance ( HNodeIDSet (MentionedVars d) + , DataSource d + ) + => HNode d + where + type HNodeID d = DSName d + type HLinksFrom d = MentionedVars d -- |The 'createRRD' function lets you set up new Round Robin Database -- (RRD) files. The file is created at its final, full size and filled -- with @*UNKNOWN*@ data. -createRRD - :: FilePath -- ^The name of the RRD you want to create. RRD files - -- should end with the extension @.rrd@. However, - -- RRDtool will accept any filename. - -> Bool -- ^Do not clobber an existing file of the same name. - -> Maybe POSIXTime -- ^Specifies the time in seconds since - -- @1970-01-01 UTC@ when the first value should - -- be added to the RRD. RRDtool will not accept - -- any data timed before or at the time - -- specified. (default: @now - 10s@) - -> Maybe NominalDiffTime -- ^Specifies the base interval in - -- seconds with which data will be fed - -- into the RRD. (default: 300 sec) --- -> [DataSource] -- ^Data sources to accept input from. - -> IO () +createRRD :: ( RRDSpec s + ) + => s -> IO () createRRD = error "FIXME" + +testMain :: IO () +testMain = let s = RRDPath "test.rrd" .&. + KeepOldRRD .&. + RRDDataSources testDSList .&. + HNil + in + createRRD s + +testDSList = let a = ComputedDataSource { + cdsName = [$hString|foo|] + , cdsExpr = Var [$hString|bar|] + } + b = ComputedDataSource { + cdsName = [$hString|bar|] + , cdsExpr = Var [$hString|foo|] -- shouldn't typecheck! + } + c = ComputedDataSource { + cdsName = [$hString|baz|] + , cdsExpr = Var [$hString|foo|] -- should typecheck! + } + in a .&. b .&. HNil \ No newline at end of file