Commit 798582cf authored by Spyros Trigazis's avatar Spyros Trigazis Committed by Michele Tartara
Browse files

Make CPUload Data Collector aware of clock ticks



Modify CPUload data collector to get the number of clock ticks
per second from Posix.Unistd. Since CPUload collector converts
clock ticks (jiffies) to seconds and the clock ticks to seconds
ratio varies between linux distributions, it must be read from
the corresponding library to be consistent.
Signed-off-by: default avatarSpyros Trigazis <strigazi@gmail.com>
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent f8d4db63
......@@ -38,6 +38,7 @@ import Data.Attoparsec.Text.Lazy as A
import Data.Text.Lazy (pack, unpack)
import qualified Text.JSON as J
import qualified Data.Sequence as Seq
import System.Posix.Unistd (getSysVar, SysVar(ClockTick))
import qualified Ganeti.BasicTypes as BT
import qualified Ganeti.Constants as C
......@@ -155,8 +156,8 @@ dcUpdate mcd = do
-- | Computes the average load for every CPU and the overall from data read
-- from the map.
computeAverage :: Buffer -> Integer -> [Double]
computeAverage s w =
computeAverage :: Buffer -> Integer -> Integer -> [Double]
computeAverage s w ticks =
let window = Seq.takeWhileL ((> w) . fst) s
go Seq.EmptyL _ = []
go _ Seq.EmptyR = []
......@@ -164,15 +165,16 @@ computeAverage s w =
let (timestampL, listL) = leftmost
(timestampR, listR) = rightmost
work = zipWith (-) listL listR
overall = (timestampL - timestampR) * 100
overall = (timestampL - timestampR) * ticks
map (\x -> fromIntegral x / fromIntegral overall) work
in go (Seq.viewl window) (Seq.viewr window)
-- | This function computes the JSON representation of the CPU load.
buildJsonReport :: Buffer -> IO J.JSValue
buildJsonReport v =
let res = computeAverage v windowSize
in return . J.showJSON $ formatData res
buildJsonReport v = do
ticks <- getSysVar ClockTick
let res = computeAverage v windowSize ticks
return . J.showJSON $ formatData res
-- | This function computes the DCReport for the CPU load.
buildDCReport :: Buffer -> IO DCReport
......
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