From 314a1261d5fed0bf7ae7a5537bf97e6549cf3401 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Mon, 25 Jan 2010 04:15:34 +0100 Subject: Disk: better error recovery Ignore-this: 9a4573711403eb432c20e99efe176811 darcs-hash:20100125031534-1d908-ff74cc159bda5b25393f42b3c321b8b7282dfcb0.gz --- Plugins/Monitors/Disk.hs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'Plugins') diff --git a/Plugins/Monitors/Disk.hs b/Plugins/Monitors/Disk.hs index 5e6901c..9a86b46 100644 --- a/Plugins/Monitors/Disk.hs +++ b/Plugins/Monitors/Disk.hs @@ -35,7 +35,7 @@ parseMountedDevices = map undev . filter isDev . map (firstTwo . B.words) . B.lines where firstTwo (a:b:_) = (B.unpack a, B.unpack b) - firstTwo _ = error "Unexpected mtab format" + firstTwo _ = ("", "") isDev (d, _) = "/dev/" `isPrefixOf` d undev (d, f) = (drop 5 d, f) @@ -64,7 +64,7 @@ parseData reqs mounted dat dat2 = in case (f1, f2) of (Just (_, x), Just (_, y)) -> formatDev path (dev, zipWith (-) y x) - _ -> error $ "Device " ++ dev ++ "not found in diskstats" + _ -> (dev, path, [0, 0, 0]) in map format rm formatDev :: Path -> (DevName, [Float]) -> (DevName, Path, [Float]) @@ -73,8 +73,8 @@ formatDev path (dev, xs) = wSp = speed (xs !! 6) (xs !! 7) sp = speed (xs !! 2 + xs !! 6) (xs !! 3 + xs !! 7) speed x t = if t == 0 then 0 else 500 * x / t - in - (dev, path, [sp, rSp, wSp]) + dat = if length xs > 6 then [sp, rSp, wSp] else [0, 0, 0] + in (dev, path, dat) speedToStr :: Int -> Float -> String speedToStr n x = @@ -110,7 +110,3 @@ runDisk disks _ = do dat <- io $ mountedData (map fst disks) strs <- mapM (\(d, p, xs) -> runDisk' (findTempl d p disks) xs) dat return $ intercalate " " strs - - - - -- cgit v1.2.3