summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors/Swap/FreeBSD.hs
blob: 0e0c03d74cdee1a391a1ba69135098673ef0eb30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-----------------------------------------------------------------------------
-- |
-- Module      :  Plugins.Monitors.Swap.FreeBSD
-- Copyright   :  (c) Andrea Rossato
-- License     :  BSD-style (see LICENSE)
--
-- Maintainer  :  Jose A. Ortega Ruiz <jao@gnu.org>
-- Stability   :  unstable
-- Portability :  unportable
--
-- A  swap usage monitor for Xmobar
--
-----------------------------------------------------------------------------

module Xmobar.Plugins.Monitors.Swap.FreeBSD (parseMEM) where

import System.BSD.Sysctl (sysctlReadUInt, sysctlReadULong)

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