{- Copyright 2015,2016 Markus Ongyerth, Stephan Guenther This file is part of Monky. Monky is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Monky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Monky. If not, see . -} {-# LANGUAGE OverloadedStrings #-} {-| Module : Monky.Examples.Disk Description : An example module instance for the disk module Maintainer : moepi Stability : testing Portability : Linux -} module Monky.Examples.Disk ( getDiskHandle , getDiskHandleTag , DiskH ) where import Formatting import Monky.Examples.Utility import Monky.Examples.Images import Monky.Modules import Control.Applicative ((<$>)) import qualified Monky.Disk as D -- |The handle type for this module newtype DiskH = DH D.DiskHandle -- |Get a disk handle by uuid. This special cases btrfs getDiskHandle :: String -- ^The UUID of the device to monitor. It has to be mounted at monky startup! -> IO DiskH getDiskHandle = fmap DH . D.getDiskHandle -- |Get a disk handle from a given tag getDiskHandleTag :: String -- ^Which tag to give to libblkid -> String -- ^The value of the tag -> IO DiskH getDiskHandleTag t v = DH <$> D.getDiskHandleTag t v {- Disk module -} instance PollModule DiskH where getOutput (DH dh) = do (dr, dw) <- D.getDiskReadWrite dh df <- D.getDiskFree dh return [ diskImage , MonkyPlain $ sformat (stext % " " % stext % " " % stext) (convertUnitSI df "B") (convertUnitSI dr "B" ) (convertUnitSI dw "B") ]