Revision 798582cf src/Ganeti/DataCollectors/CPUload.hs

b/src/Ganeti/DataCollectors/CPUload.hs
38 38
import Data.Text.Lazy (pack, unpack)
39 39
import qualified Text.JSON as J
40 40
import qualified Data.Sequence as Seq
41
import System.Posix.Unistd (getSysVar, SysVar(ClockTick))
41 42

  
42 43
import qualified Ganeti.BasicTypes as BT
43 44
import qualified Ganeti.Constants as C
......
155 156

  
156 157
-- | Computes the average load for every CPU and the overall from data read
157 158
-- from the map.
158
computeAverage :: Buffer -> Integer -> [Double]
159
computeAverage s w =
159
computeAverage :: Buffer -> Integer -> Integer -> [Double]
160
computeAverage s w ticks =
160 161
  let window = Seq.takeWhileL ((> w) . fst) s
161 162
      go Seq.EmptyL          _                    = []
162 163
      go _                   Seq.EmptyR           = []
......
164 165
        let (timestampL, listL) = leftmost
165 166
            (timestampR, listR) = rightmost
166 167
            work = zipWith (-) listL listR
167
            overall = (timestampL - timestampR) * 100
168
            overall = (timestampL - timestampR) * ticks
168 169
        map (\x -> fromIntegral x / fromIntegral overall) work
169 170
  in go (Seq.viewl window) (Seq.viewr window)
170 171

  
171 172
-- | This function computes the JSON representation of the CPU load.
172 173
buildJsonReport :: Buffer -> IO J.JSValue
173
buildJsonReport v =
174
  let res = computeAverage v windowSize
175
  in return . J.showJSON $ formatData res
174
buildJsonReport v = do
175
  ticks <- getSysVar ClockTick
176
  let res = computeAverage v windowSize ticks
177
  return . J.showJSON $ formatData res
176 178

  
177 179
-- | This function computes the DCReport for the CPU load.
178 180
buildDCReport :: Buffer -> IO DCReport

Also available in: Unified diff