Commit 13d3acab authored by Michele Tartara's avatar Michele Tartara

Add reporting infrastructure for data collectors

This commit adds the part of the JSON report generation code that will be
common to all the data collectors, according to the format specified in the
design document.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent ace37e24
......@@ -487,6 +487,7 @@ HS_LIB_SRCS = \
src/Ganeti/DataCollectors/CLI.hs \
src/Ganeti/DataCollectors/Drbd.hs \
src/Ganeti/DataCollectors/Program.hs \
src/Ganeti/DataCollectors/Types.hs \
src/Ganeti/Errors.hs \
src/Ganeti/HTools/Backend/IAlloc.hs \
src/Ganeti/HTools/Backend/Luxi.hs \
......
......@@ -2315,5 +2315,8 @@ AUTO_REPAIR_ALL_RESULTS = frozenset([
AUTO_REPAIR_ENOPERM,
])
# The version identifier for builtin data collectors
BUILTIN_DATA_COLLECTOR_VERSION = "B"
# Do not re-export imported modules
del re, _vcsversion, _autoconf, socket, pathutils, compat
{-# LANGUAGE TemplateHaskell #-}
{-| Implementation of the Ganeti data collector types.
-}
{-
Copyright (C) 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
module Ganeti.DataCollectors.Types
( DCReport(..)
, buildReport
) where
import Data.Maybe
import Text.JSON
import Ganeti.Constants as C
import Ganeti.THH
import Ganeti.Utils (getCurrentTime)
-- | This is the format of the report produced by each data collector.
$(buildObject "DCReport" "dcReport"
[ simpleField "name" [t| String |]
, simpleField "version" [t| String |]
, simpleField "format_version" [t| Int |]
, simpleField "timestamp" [t| Integer |]
, simpleField "data" [t| JSValue |]
])
-- | Utility function for building a report automatically adding the current
-- timestamp (rounded up to seconds).
-- If the version is not specified, it will be set to the value indicating
-- a builtin collector.
buildReport :: String -> Maybe String -> Int -> JSValue -> IO DCReport
buildReport name version format_version jsonData = do
now <- getCurrentTime
let timestamp = now * 1000000000 :: Integer
ver = fromMaybe C.builtinDataCollectorVersion version
return $ DCReport name ver format_version timestamp jsonData
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment