diff options
author | Michal Zielonka <michal.zielonka.8001@gmail.com> | 2021-10-07 16:39:20 +0200 |
---|---|---|
committer | Michal Zielonka <michal.zielonka.8001@gmail.com> | 2021-10-07 16:39:20 +0200 |
commit | a845465fec735d9818a61d078337653b5293da5c (patch) | |
tree | d13c71da73d1f9ef177e29fce92009139b972c9f /src/Xmobar/Plugins/Monitors | |
parent | 34ff313d90b48033282af7b3e845614cfabcfef7 (diff) | |
download | xmobar-a845465fec735d9818a61d078337653b5293da5c.tar.gz xmobar-a845465fec735d9818a61d078337653b5293da5c.tar.bz2 |
add support swap info for freebsd
in freebsd swap info is available by sysctl
Diffstat (limited to 'src/Xmobar/Plugins/Monitors')
-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 |