summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors/Load.hs
diff options
context:
space:
mode:
authorMichal Zielonka <michal.zielonka.8001@gmail.com>2022-04-11 22:53:29 +0200
committerMichal Zielonka <michal.zielonka.8001@gmail.com>2022-04-11 22:53:29 +0200
commit15dccb714af16c786ebb63cf619f885495781f5f (patch)
treee2f1f8fb8511ee35ddf6f42a974fc9aba7966b31 /src/Xmobar/Plugins/Monitors/Load.hs
parent7af1ddc5ebbe9d651ffbc057614be18637e69939 (diff)
downloadxmobar-15dccb714af16c786ebb63cf619f885495781f5f.tar.gz
xmobar-15dccb714af16c786ebb63cf619f885495781f5f.tar.bz2
add load monitor for freebsd
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/Load.hs')
-rw-r--r--src/Xmobar/Plugins/Monitors/Load.hs32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Load.hs b/src/Xmobar/Plugins/Monitors/Load.hs
index bc0af09..270c049 100644
--- a/src/Xmobar/Plugins/Monitors/Load.hs
+++ b/src/Xmobar/Plugins/Monitors/Load.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE CPP #-}
+
-----------------------------------------------------------------------------
-- |
-- Module : Plugins.Monitors.Load
@@ -17,28 +19,28 @@
module Xmobar.Plugins.Monitors.Load (loadConfig, runLoad) where
import Xmobar.Plugins.Monitors.Common
-import qualified Data.ByteString.Lazy.Char8 as B
-import System.Posix.Files (fileExist)
+import Xmobar.Plugins.Monitors.Load.Common (Result(..))
+
+#if defined(freebsd_HOST_OS)
+import qualified Xmobar.Plugins.Monitors.Load.FreeBSD as ML
+#else
+import qualified Xmobar.Plugins.Monitors.Load.Linux as ML
+#endif
+
-- | Default configuration.
loadConfig :: IO MConfig
loadConfig = mkMConfig "Load: <load1>" ["load1", "load5", "load15"]
--- | Parses the contents of a loadavg proc file, returning
--- the list of load averages
-parseLoadAvgs :: B.ByteString -> [Float]
-parseLoadAvgs =
- map (read . B.unpack) . take 3 . B.words . head . B.lines
-- | Retrieves load information. Returns the monitor string parsed
-- according to template (either default or user specified).
runLoad :: [String] -> Monitor String
runLoad _ = do
- let file = "/proc/loadavg"
- exists <- io $ fileExist file
- if exists then
- (do l <- io $ B.readFile file >>= return . parseLoadAvgs
- d <- getConfigValue decDigits
- parseTemplate =<< mapM (showWithColors (showDigits d)) l)
- else
- getConfigValue naString
+ result <- io ML.fetchLoads
+ case result of
+ Result loads ->
+ do
+ d <- getConfigValue decDigits
+ parseTemplate =<< mapM (showWithColors (showDigits d)) loads
+ NA -> getConfigValue naString