diff options
Diffstat (limited to 'Plugins')
-rw-r--r-- | Plugins/Monitors.hs | 4 | ||||
-rw-r--r-- | Plugins/Monitors/Uptime.hs (renamed from Plugins/Uptime.hs) | 35 |
2 files changed, 21 insertions, 18 deletions
diff --git a/Plugins/Monitors.hs b/Plugins/Monitors.hs index 98949cf..a19f82a 100644 --- a/Plugins/Monitors.hs +++ b/Plugins/Monitors.hs @@ -31,6 +31,7 @@ import Plugins.Monitors.CpuFreq import Plugins.Monitors.CoreTemp import Plugins.Monitors.Disk import Plugins.Monitors.Top +import Plugins.Monitors.Uptime #ifdef IWLIB import Plugins.Monitors.Wireless #endif @@ -53,6 +54,7 @@ data Monitors = Weather Station Args Rate | CoreTemp Args Rate | TopProc Args Rate | TopMem Args Rate + | Uptime Args Rate #ifdef IWLIB | Wireless Interface Args Rate #endif @@ -86,6 +88,7 @@ instance Exec Monitors where alias (CoreTemp _ _) = "coretemp" alias (DiskU _ _ _) = "disku" alias (DiskIO _ _ _) = "diskio" + alias (Uptime _ _) = "uptime" #ifdef IWLIB alias (Wireless i _ _) = i ++ "wi" #endif @@ -106,6 +109,7 @@ instance Exec Monitors where start (DiskU s a r) = runM a diskUConfig (runDiskU s) r start (DiskIO s a r) = runM a diskIOConfig (runDiskIO s) r start (TopMem a r) = runM a topMemConfig runTopMem r + start (Uptime a r) = runM a uptimeConfig runUptime r start (TopProc a r) = startTop a r #ifdef IWLIB start (Wireless i a r) = runM (a ++ [i]) wirelessConfig runWireless r diff --git a/Plugins/Uptime.hs b/Plugins/Monitors/Uptime.hs index 6d81acd..453b9ad 100644 --- a/Plugins/Uptime.hs +++ b/Plugins/Monitors/Uptime.hs @@ -1,6 +1,6 @@ ------------------------------------------------------------------------------ -- | --- Module : Plugins.Uptime +-- Module : Plugins.Monitors.Uptime -- Copyright : (c) 2010 Jose Antonio Ortega Ruiz -- License : BSD3-style (see LICENSE) -- @@ -15,19 +15,15 @@ ------------------------------------------------------------------------------ -module Plugins.Uptime (Uptime(..)) where +module Plugins.Monitors.Uptime (uptimeConfig, runUptime) where -import Plugins +import Plugins.Monitors.Common import qualified Data.ByteString.Lazy.Char8 as B -data Uptime = Uptime String Int - deriving (Read, Show) - -instance Exec Uptime where - alias (Uptime a _) = a - run (Uptime _ _) = uptime - rate (Uptime _ r) = r +uptimeConfig :: IO MConfig +uptimeConfig = mkMConfig "Up <days>d <hours>h <minutes>m" + ["days", "hours", "minutes", "seconds"] readUptime :: IO Float readUptime = @@ -36,16 +32,19 @@ readUptime = secsPerDay :: Integer secsPerDay = 24 * 3600 -uptime :: IO String +uptime :: Monitor [String] uptime = do - t <- readUptime + t <- io readUptime + u <- getConfigValue usePercent let tsecs = floor t secs = tsecs `mod` secsPerDay days = tsecs `quot` secsPerDay - hrs = secs `quot` 3600 + hours = secs `quot` 3600 mins = (secs `mod` 3600) `div` 60 - dstr | days == 0 = "" - | otherwise = show days ++ "d " - str x | x < 10 = '0':show x - | otherwise = show x - return $ dstr ++ str hrs ++ ":" ++ str mins + ss = secs `mod` 60 + str x s = if u then show x ++ s else show x + mapM (`showWithColors'` days) + [str days "d", str hours "h", str mins "m", str ss "s"] + +runUptime :: [String] -> Monitor String +runUptime _ = uptime >>= parseTemplate |