summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins
diff options
context:
space:
mode:
authorBen Boeckel <mathstuf@gmail.com>2014-02-04 17:47:08 -0500
committerBen Boeckel <mathstuf@gmail.com>2014-02-04 17:47:08 -0500
commit4b3a516b8444f9bd14d24ed258ce44efe28b0a5a (patch)
tree1c64b07b8a19894751adcd875b799b25bca14cd2 /src/Plugins
parente8f9e881d37536954f24d73b29cbccf86341c3d3 (diff)
downloadxmobar-4b3a516b8444f9bd14d24ed258ce44efe28b0a5a.tar.gz
xmobar-4b3a516b8444f9bd14d24ed258ce44efe28b0a5a.tar.bz2
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.
Diffstat (limited to 'src/Plugins')
-rw-r--r--src/Plugins/Monitors/Mem.hs6
1 files 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