From 5a743aa87ed7d1ce91a18b07b14d8c48af1eb335 Mon Sep 17 00:00:00 2001 From: Andrea Rossato Date: Mon, 27 Aug 2007 12:59:02 +0200 Subject: Plugins.Swap: check for SwapFree and SwapTotal In some system SwapFree and SwapTotal are in different position, so we need to check for the string. Reported by Stan Behrens darcs-hash:20070827105902-d6583-d0d1bd5341299759f2e600bd4173bfcb278dec40.gz --- Plugins/Monitors/Swap.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Plugins') diff --git a/Plugins/Monitors/Swap.hs b/Plugins/Monitors/Swap.hs index d18ab8a..40c21ed 100644 --- a/Plugins/Monitors/Swap.hs +++ b/Plugins/Monitors/Swap.hs @@ -29,9 +29,16 @@ fileMEM = B.readFile "/proc/meminfo" parseMEM :: IO [Float] parseMEM = do file <- fileMEM - let p x y = flip (/) 1024 . read . stringParser x $ y - tot = p (1,11) file - free = p (1,12) file + let li i l + | l /= [] = (head l) !! i + | otherwise = B.empty + fs s l + | l == [] = False + | otherwise = head l == B.pack s + get_data s = flip (/) 1024 . read . B.unpack . li 1 . filter (fs s) + 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] formatSwap :: [Float] -> Monitor [String] -- cgit v1.2.3