From 4768d84d13a015c76200010e32ae1515264fd1bb Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Tue, 7 Dec 2010 16:26:09 +0100 Subject: Fix for swap used ratio (issue 24) Thanks to Dan Brown for pointing this out. I've applied a modified version of his patch (inclusion of % will be treated separately). --- Plugins/Monitors/Common.hs | 4 ++++ Plugins/Monitors/Swap.hs | 19 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'Plugins') diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs index 9362fd8..c90c616 100644 --- a/Plugins/Monitors/Common.hs +++ b/Plugins/Monitors/Common.hs @@ -39,6 +39,7 @@ module Plugins.Monitors.Common ( , showWithPadding , showWithColors , showWithColors' + , showPercentWithColors , showPercentsWithColors , showPercentBar , showLogBar @@ -386,6 +387,9 @@ showPercentsWithColors fs = do fstrs <- mapM floatToPercent fs zipWithM (showWithColors . const) fstrs (map (*100) fs) +showPercentWithColors :: Float -> Monitor String +showPercentWithColors f = liftM head $ showPercentsWithColors [f] + showPercentBar :: Float -> Float -> Monitor String showPercentBar v x = do bb <- getConfigValue barBack diff --git a/Plugins/Monitors/Swap.hs b/Plugins/Monitors/Swap.hs index 02acb45..8901a2a 100644 --- a/Plugins/Monitors/Swap.hs +++ b/Plugins/Monitors/Swap.hs @@ -21,7 +21,7 @@ import qualified Data.ByteString.Lazy.Char8 as B swapConfig :: IO MConfig swapConfig = mkMConfig "Swap: " -- template - ["total", "used", "free", "usedratio"] -- available replacements + ["usedratio", "total", "used", "free"] -- available replacements fileMEM :: IO B.ByteString fileMEM = B.readFile "/proc/meminfo" @@ -30,7 +30,7 @@ parseMEM :: IO [Float] parseMEM = do file <- fileMEM let li i l - | l /= [] = (head l) !! i + | l /= [] = head l !! i | otherwise = B.empty fs s l | l == [] = False @@ -39,18 +39,17 @@ parseMEM = st = map B.words . B.lines $ file tot = get_data "SwapTotal:" st free = get_data "SwapFree:" st - return [tot, (tot - free), free, (tot - free) / tot] + return [(tot - free) / tot, tot, tot - free, free] formatSwap :: [Float] -> Monitor [String] -formatSwap x = - do let f1 n = showDigits 2 n - (hd, tl) = splitAt 3 x - firsts <- mapM (showWithColors f1) hd - lasts <- showPercentsWithColors (map (/100) tl) - return $ firsts ++ lasts +formatSwap (r:xs) = + do other <- mapM (showWithColors (showDigits 2)) xs + ratio <- showPercentWithColors r + return $ ratio:other +formatSwap _ = return $ replicate 4 "N/A" runSwap :: [String] -> Monitor String runSwap _ = - do m <- io $ parseMEM + do m <- io parseMEM l <- formatSwap m parseTemplate l -- cgit v1.2.3