diff options
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/Swap.hs')
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Swap.hs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Swap.hs b/src/Xmobar/Plugins/Monitors/Swap.hs index fcaab84..ca46010 100644 --- a/src/Xmobar/Plugins/Monitors/Swap.hs +++ b/src/Xmobar/Plugins/Monitors/Swap.hs @@ -1,3 +1,4 @@ +{-#LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | -- Module : Plugins.Monitors.Swap @@ -16,13 +17,44 @@ module Xmobar.Plugins.Monitors.Swap where import Xmobar.Plugins.Monitors.Common +#ifdef FREEBSD +import System.BSD.Sysctl (sysctlReadUInt, sysctlReadULong) +#else import qualified Data.ByteString.Lazy.Char8 as B +#endif swapConfig :: IO MConfig swapConfig = mkMConfig "Swap: <usedratio>%" -- template ["usedratio", "total", "used", "free"] -- available replacements +#ifdef FREEBSD + +isEnabled :: IO Bool +isEnabled = do + enabled <- sysctlReadUInt "vm.swap_enabled" + return $ enabled == 1 + +parseMEM' :: Bool -> IO [Float] +parseMEM' False = return $ [] +parseMEM' True = do + swapIn <- sysctlReadUInt "vm.stats.vm.v_swapin" + swapTotal <- sysctlReadULong "vm.swap_total" + let tot = toInteger swapTotal + free = tot - (toInteger swapIn) + + return $ res (fromInteger tot) (fromInteger free) + where + res :: Float -> Float -> [Float] + res _ 0 = [] + res tot free = [(tot - free) / tot, tot, tot - free, free] + +parseMEM :: IO [Float] +parseMEM = do + enabled <- isEnabled + parseMEM' enabled + +#else fileMEM :: IO B.ByteString fileMEM = B.readFile "/proc/meminfo" @@ -41,6 +73,8 @@ parseMEM = free = get_data "SwapFree:" st return [(tot - free) / tot, tot, tot - free, free] +#endif + formatSwap :: [Float] -> Monitor [String] formatSwap (r:xs) = do d <- getConfigValue decDigits |