summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors/Load/Linux.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/Linux.hs
parent7af1ddc5ebbe9d651ffbc057614be18637e69939 (diff)
downloadxmobar-15dccb714af16c786ebb63cf619f885495781f5f.tar.gz
xmobar-15dccb714af16c786ebb63cf619f885495781f5f.tar.bz2
add load monitor for freebsd
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/Load/Linux.hs')
-rw-r--r--src/Xmobar/Plugins/Monitors/Load/Linux.hs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Load/Linux.hs b/src/Xmobar/Plugins/Monitors/Load/Linux.hs
new file mode 100644
index 0000000..9ba5a5c
--- /dev/null
+++ b/src/Xmobar/Plugins/Monitors/Load/Linux.hs
@@ -0,0 +1,38 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : Plugins.Monitors.Load.Linux
+-- Copyright : Finn Lawler
+-- License : BSD-style (see LICENSE)
+--
+-- Author : Finn Lawler <flawler@cs.tcd.ie>
+-- Maintainer : jao <mail@jao.io>
+-- Stability : unstable
+-- Portability : unportable
+--
+-- A load average monitor for Xmobar. Adapted from
+-- Xmobar.Plugins.Monitors.Thermal by Juraj Hercek.
+--
+-----------------------------------------------------------------------------
+
+module Xmobar.Plugins.Monitors.Load.Linux (fetchLoads) where
+
+import Xmobar.Plugins.Monitors.Load.Common (Result(..))
+import qualified Data.ByteString.Lazy.Char8 as B
+import System.Posix.Files (fileExist)
+
+-- | 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
+
+fetchLoads :: IO Result
+fetchLoads = do
+ let file = "/proc/loadavg"
+
+ exists <- fileExist file
+ if exists then
+ (do contents <- B.readFile file
+ return $ Result (parseLoadAvgs contents))
+ else
+ return NA