module Development.IDE.Types.Monitoring
(Monitoring(..)
) where

import           Data.Int
import           Data.Text (Text)

-- | An abstraction for runtime monitoring inspired by the 'ekg' package
data Monitoring = Monitoring {
    -- | Register an integer-valued metric.
    Monitoring -> Text -> IO Int64 -> IO ()
registerGauge   :: Text -> IO Int64 -> IO (),
    -- | Register a non-negative, monotonically increasing, integer-valued metric.
    Monitoring -> Text -> IO Int64 -> IO ()
registerCounter :: Text -> IO Int64 -> IO (),
    Monitoring -> IO (IO ())
start           :: IO (IO ()) -- ^ Start the monitoring system, returning an action which will stop the system.
  }

instance Semigroup Monitoring where
    Monitoring
a <> :: Monitoring -> Monitoring -> Monitoring
<> Monitoring
b = Monitoring {
        registerGauge :: Text -> IO Int64 -> IO ()
registerGauge   = \Text
n IO Int64
v -> Monitoring -> Text -> IO Int64 -> IO ()
registerGauge Monitoring
a Text
n IO Int64
v forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Monitoring -> Text -> IO Int64 -> IO ()
registerGauge Monitoring
b Text
n IO Int64
v,
        registerCounter :: Text -> IO Int64 -> IO ()
registerCounter = \Text
n IO Int64
v -> Monitoring -> Text -> IO Int64 -> IO ()
registerCounter Monitoring
a Text
n IO Int64
v forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Monitoring -> Text -> IO Int64 -> IO ()
registerCounter Monitoring
b Text
n IO Int64
v,
        start :: IO (IO ())
start = do
            IO ()
a' <- Monitoring -> IO (IO ())
start Monitoring
a
            IO ()
b' <- Monitoring -> IO (IO ())
start Monitoring
b
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ IO ()
a' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO ()
b'
      }

instance Monoid Monitoring where
    mempty :: Monitoring
mempty = Monitoring {
        registerGauge :: Text -> IO Int64 -> IO ()
registerGauge   = \Text
_ IO Int64
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return (),
        registerCounter :: Text -> IO Int64 -> IO ()
registerCounter = \Text
_ IO Int64
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return (),
        start :: IO (IO ())
start = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return ()
      }