summaryrefslogtreecommitdiffhomepage
path: root/Plugins/Monitors/Mem.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/Monitors/Mem.hs')
-rw-r--r--Plugins/Monitors/Mem.hs23
1 files changed, 14 insertions, 9 deletions
diff --git a/Plugins/Monitors/Mem.hs b/Plugins/Monitors/Mem.hs
index 16fc3a4..c6c4dc4 100644
--- a/Plugins/Monitors/Mem.hs
+++ b/Plugins/Monitors/Mem.hs
@@ -3,7 +3,7 @@
-- Module : Plugins.Monitors.Mem
-- Copyright : (c) Andrea Rossato
-- License : BSD-style (see LICENSE)
---
+--
-- Maintainer : Andrea Rossato <andrea.rossato@unibz.it>
-- Stability : unstable
-- Portability : unportable
@@ -19,29 +19,34 @@ import Plugins.Monitors.Common
memConfig :: IO MConfig
memConfig = mkMConfig
"Mem: <usedratio>% (<cache>M)" -- template
- ["total", "free", "buffer", -- available replacements
- "cache", "rest", "used", "usedratio"]
+ ["usedbar", "freebar", "usedratio", "total", -- available replacements
+ "free", "buffer", "cache", "rest", "used"]
fileMEM :: IO String
fileMEM = readFile "/proc/meminfo"
parseMEM :: IO [Float]
parseMEM =
- do file <- fileMEM
+ do file <- fileMEM
let content = map words $ take 4 $ lines file
[total, free, buffer, cache] = map (\line -> (read $ line !! 1 :: Float) / 1024) content
rest = free + buffer + cache
used = total - rest
- usedratio = used * 100 / total
- return [total, free, buffer, cache, rest, used, usedratio]
+ usedratio = used / total
+ return [usedratio, total, free, buffer, cache, rest, used]
formatMem :: [Float] -> Monitor [String]
-formatMem x =
+formatMem (r:xs) =
do let f n = showDigits 0 n
- mapM (showWithColors f) x
+ rr = 100 * r
+ ub <- showPercentBar rr r
+ fb <- showPercentBar (100 - rr) (1 - r)
+ s <- mapM (showWithColors f) (rr:xs)
+ return (ub:fb:s)
+formatMem _ = return $ replicate 8 "N/A"
runMem :: [String] -> Monitor String
runMem _ =
do m <- io $ parseMEM
l <- formatMem m
- parseTemplate l
+ parseTemplate l