diff options
author | Andrea Rossato <andrea.rossatoo@unibz.it> | 2007-06-19 10:06:25 +0200 |
---|---|---|
committer | Andrea Rossato <andrea.rossatoo@unibz.it> | 2007-06-19 10:06:25 +0200 |
commit | a23f5db95e3d4a05a7b4085386a3815d043429df (patch) | |
tree | 750f65b326579f2bb94d91e11c9247111b5e590b /monitor.hs | |
parent | 7ea77de00604a2e62f155d222447bede3df28fb4 (diff) | |
download | xmobar-a23f5db95e3d4a05a7b4085386a3815d043429df.tar.gz xmobar-a23f5db95e3d4a05a7b4085386a3815d043429df.tar.bz2 |
added a monitoring script found here http://blog.csdn.net/danranx/archive/2007/06/10/1646608.aspx
darcs-hash:20070619080625-92444-4d5571b8344f3a5da49b42f83969e5b6db21e7bb.gz
Diffstat (limited to 'monitor.hs')
-rwxr-xr-x | monitor.hs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/monitor.hs b/monitor.hs new file mode 100755 index 0000000..d6f0e34 --- /dev/null +++ b/monitor.hs @@ -0,0 +1,66 @@ +#! /usr/bin/env runhaskell + + +import Data.Time (getZonedTime) +import Text.Printf (printf) +import System.Process (runInteractiveCommand) +import Data.List +import System.IO (hGetContents) + + +getOutput :: String -> IO String +getOutput cmd = do + (_, out, _, _) <- runInteractiveCommand cmd + hGetContents out + +memParse :: String -> String +memParse file = + 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 + in + printf "MEM: %sM %.1f%% used %.0fM rest" used usedratio rest + + +mem :: IO String +mem = do + file <- readFile "/proc/meminfo" + return $ memParse file + + +time :: IO String +time = do + now <- getZonedTime + return $ take 16 $ show now + + +temp :: IO String +temp = do + file <- readFile "/proc/acpi/thermal_zone/THRM/temperature" + let t = (words file) !! 1 + return $ "TEMP: " ++ t ++ "C" + + +takeTail :: Int -> [a] -> [a] +takeTail n xs = + let len = length xs in + drop (len-n) xs + + +load :: IO String +load = do + content <- getOutput "uptime" + let l = map (delete ',') $ takeTail 3 $ words content + return $ unwords $ "LOAD:" : l + + +sep :: IO String +sep = return " " + + +main = do + putStr "" + mapM_ (>>=putStr) $ intersperse sep [load, temp, mem, time] + putChar '\n'
\ No newline at end of file |