summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Disk.hs
diff options
context:
space:
mode:
authorJohn Soros <johnny@r0x0r.me>2012-10-08 13:36:14 +0200
committerJohn Soros <johnny@r0x0r.me>2012-10-08 13:36:14 +0200
commitae61c95ee8e4ff85ee6c39f610b670401b6e8d53 (patch)
tree0403b2831f8b3b016fc6bc18b082cf7a92f5516e /src/Plugins/Monitors/Disk.hs
parent44f99f3ed3a6af5a2289765fadf4df29887db5c2 (diff)
downloadxmobar-ae61c95ee8e4ff85ee6c39f610b670401b6e8d53.tar.gz
xmobar-ae61c95ee8e4ff85ee6c39f610b670401b6e8d53.tar.bz2
Enable the monitoring of non-mounted disks and partitions in DiskIO
Diffstat (limited to 'src/Plugins/Monitors/Disk.hs')
-rw-r--r--src/Plugins/Monitors/Disk.hs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/Plugins/Monitors/Disk.hs b/src/Plugins/Monitors/Disk.hs
index 554be05..d52dce2 100644
--- a/src/Plugins/Monitors/Disk.hs
+++ b/src/Plugins/Monitors/Disk.hs
@@ -51,6 +51,20 @@ mountedDevices req = do
isReq (d, p) = p `elem` req || drop 5 d `elem` req
undev (d, f) = (drop 5 d, f)
+availDevices :: [String] -> IO [(DevName, Path)]
+availDevices req = do
+ s <- B.readFile "/proc/diskstats"
+ parse `fmap` mapM canon (devs s)
+ where
+ canon (d, p) = do {d' <- canonicalizePath ("/dev/"++d); return (d', p)}
+ devs = map (third . B.words) . B.lines
+ parse = map undev . filter isReq
+ third (_:_:c:_) = (B.unpack c, B.unpack c)
+ third _ = ("", "")
+ isReq (d, p) = p `elem` req || drop 5 d `elem` req
+ undev (d, f) = (drop 5 d, f)
+
+
diskData :: IO [(DevName, [Float])]
diskData = do
s <- B.readFile "/proc/diskstats"
@@ -109,7 +123,7 @@ runDiskIO' (tmp, xs) = do
runDiskIO :: DevDataRef -> [(String, String)] -> [String] -> Monitor String
runDiskIO dref disks _ = do
- mounted <- io $ mountedDevices (map fst disks)
+ mounted <- io $ availDevices (map fst disks)
dat <- io $ mountedData dref (map fst mounted)
strs <- mapM runDiskIO' $ devTemplates disks mounted dat
return $ unwords strs
@@ -117,7 +131,7 @@ runDiskIO dref disks _ = do
startDiskIO :: [(String, String)] ->
[String] -> Int -> (String -> IO ()) -> IO ()
startDiskIO disks args rate cb = do
- mounted <- mountedDevices (map fst disks)
+ mounted <- availDevices (map fst disks)
dref <- newIORef (map (\d -> (fst d, repeat 0)) mounted)
_ <- mountedData dref (map fst mounted)
runM args diskIOConfig (runDiskIO dref disks) rate cb