From 4b3a516b8444f9bd14d24ed258ce44efe28b0a5a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 4 Feb 2014 17:47:08 -0500 Subject: Parse out fields from /proc/meminfo Newer kernels have changed the order of the lines in the /proc/meminfo find (MemAvailable is now line 3). To support this and older kernels, use the key from the map when getting data from it rather than static line numbers. --- src/Plugins/Monitors/Mem.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Plugins/Monitors/Mem.hs b/src/Plugins/Monitors/Mem.hs index 7e9341f..47a4c3f 100644 --- a/src/Plugins/Monitors/Mem.hs +++ b/src/Plugins/Monitors/Mem.hs @@ -15,6 +15,7 @@ module Plugins.Monitors.Mem (memConfig, runMem, totalMem, usedMem) where import Plugins.Monitors.Common +import qualified Data.Map as M memConfig :: IO MConfig memConfig = mkMConfig @@ -28,8 +29,9 @@ fileMEM = readFile "/proc/meminfo" parseMEM :: IO [Float] parseMEM = do file <- fileMEM - let content = map words $ take 4 $ lines file - [total, free, buffer, cache] = map (\line -> (read $ line !! 1 :: Float) / 1024) content + let content = map words $ take 8 $ lines file + info = M.fromList $ map (\line -> (line !! 0, (read $ line !! 1 :: Float) / 1024)) content + [total, free, buffer, cache] = map (info M.!) ["MemTotal:", "MemFree:", "Buffers:", "Cached:"] rest = free + buffer + cache used = total - rest usedratio = used / total -- cgit v1.2.3