From 35ca0c36f251003a2123433035b6f3a838cff4a4 Mon Sep 17 00:00:00 2001 From: Zev Weiss Date: Fri, 4 Nov 2016 14:36:04 -0500 Subject: Fix MultiCpu monitor for large uptimes This is essentially commit a0397ad2 applied to MultiCpu. --- src/Plugins/Monitors/MultiCpu.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Plugins/Monitors/MultiCpu.hs b/src/Plugins/Monitors/MultiCpu.hs index eab21da..f0cdec4 100644 --- a/src/Plugins/Monitors/MultiCpu.hs +++ b/src/Plugins/Monitors/MultiCpu.hs @@ -58,15 +58,15 @@ multiCpuConfig = [ k ++ n | n <- "" : map show [0 :: Int ..] , k <- variables] -type CpuDataRef = IORef [[Float]] +type CpuDataRef = IORef [[Int]] -cpuData :: IO [[Float]] +cpuData :: IO [[Int]] cpuData = parse `fmap` B.readFile "/proc/stat" where parse = map parseList . cpuLists cpuLists = takeWhile isCpu . map B.words . B.lines isCpu (w:_) = "cpu" `isPrefixOf` B.unpack w isCpu _ = False - parseList = map (parseFloat . B.unpack) . tail + parseList = map (parseInt . B.unpack) . tail parseCpuData :: CpuDataRef -> IO [[Float]] parseCpuData cref = @@ -76,9 +76,9 @@ parseCpuData cref = let p0 = zipWith percent bs as return p0 -percent :: [Float] -> [Float] -> [Float] +percent :: [Int] -> [Int] -> [Float] percent b a = if tot > 0 then map (/ tot) $ take 4 dif else [0, 0, 0, 0] - where dif = zipWith (-) b a + where dif = map fromIntegral $ zipWith (-) b a tot = sum dif formatMultiCpus :: MultiCpuOpts -> [[Float]] -> Monitor [String] -- cgit v1.2.3