From 54c7dff79233310d5cdeb2369d0aff65f8abb651 Mon Sep 17 00:00:00 2001 From: Michele Tartara Date: Thu, 14 Mar 2013 12:47:24 +0000 Subject: [PATCH] Add Kind data type for data collectors Also, add it to the DRBD data collector, and export it from there. Signed-off-by: Michele Tartara Reviewed-by: Bernardo Dal Seno --- src/Ganeti/DataCollectors/Drbd.hs | 7 ++++++- src/Ganeti/DataCollectors/Types.hs | 23 +++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Ganeti/DataCollectors/Drbd.hs b/src/Ganeti/DataCollectors/Drbd.hs index 805c7e1..b52e2ce 100644 --- a/src/Ganeti/DataCollectors/Drbd.hs +++ b/src/Ganeti/DataCollectors/Drbd.hs @@ -31,6 +31,7 @@ module Ganeti.DataCollectors.Drbd , dcVersion , dcFormatVersion , dcCategory + , dcKind ) where @@ -82,6 +83,10 @@ dcFormatVersion = 1 dcCategory :: Maybe DCCategory dcCategory = Just DCStorage +-- | The kind of this data collector. +dcKind :: DCKind +dcKind = DCKStatus + -- * Command line options options :: IO [OptType] @@ -130,7 +135,7 @@ buildDRBDReport statusFile pairingFile = do show (Prelude.take defaultCharNum $ unpack unparsedText) ++ "\n" ++ show contexts ++ "\n" ++ errorMessage A.Done _ drbdStatus -> return $ J.showJSON drbdStatus - buildReport dcName dcVersion dcFormatVersion dcCategory jsonData + buildReport dcName dcVersion dcFormatVersion dcCategory dcKind jsonData -- | Main function. main :: Options -> [String] -> IO () diff --git a/src/Ganeti/DataCollectors/Types.hs b/src/Ganeti/DataCollectors/Types.hs index ed18546..bef28c9 100644 --- a/src/Ganeti/DataCollectors/Types.hs +++ b/src/Ganeti/DataCollectors/Types.hs @@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Ganeti.DataCollectors.Types ( DCReport(..) , DCCategory(..) + , DCKind(..) , DCVersion(..) , buildReport ) where @@ -48,6 +49,17 @@ instance JSON DCCategory where readJSON = error "JSON read instance not implemented for type DCCategory" +-- | The type representing the kind of the collector. +data DCKind = DCKPerf -- ^ Performance reporting collector + | DCKStatus -- ^ Status reporting collector + deriving (Show, Eq) + +-- | The JSON instance for CollectorKind. +instance JSON DCKind where + showJSON DCKPerf = showJSON (0 :: Int) + showJSON DCKStatus = showJSON (1 :: Int) + readJSON = error "JSON read instance not implemented for type DCKind" + -- | Type representing the version number of a data collector. data DCVersion = DCVerBuiltin | DCVersion String deriving (Show, Eq) @@ -65,6 +77,7 @@ $(buildObject "DCReport" "dcReport" , simpleField "timestamp" [t| Integer |] , optionalNullSerField $ simpleField "category" [t| DCCategory |] + , simpleField "kind" [t| DCKind |] , simpleField "data" [t| JSValue |] ]) @@ -72,9 +85,11 @@ $(buildObject "DCReport" "dcReport" -- timestamp (rounded up to seconds). -- If the version is not specified, it will be set to the value indicating -- a builtin collector. -buildReport :: String -> DCVersion -> Int -> Maybe DCCategory -> JSValue - -> IO DCReport -buildReport name version format_version category jsonData = do +buildReport :: String -> DCVersion -> Int -> Maybe DCCategory -> DCKind + -> JSValue -> IO DCReport +buildReport name version format_version category kind jsonData = do now <- getCurrentTime let timestamp = now * 1000000000 :: Integer - return $ DCReport name version format_version timestamp category jsonData + return $ + DCReport name version format_version timestamp category kind + jsonData -- 1.7.10.4