{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module System.Metrics.Prometheus.Concurrent.RegistryT where

import           Control.Applicative                           ((<$>))
import           Control.Monad.IO.Class                        (MonadIO, liftIO)
import           Control.Monad.Trans.Class                     (MonadTrans)
import           Control.Monad.Trans.Reader                    (ReaderT (..),
                                                                ask)

import           System.Metrics.Prometheus.Concurrent.Registry (Registry, new)
import qualified System.Metrics.Prometheus.Concurrent.Registry as R
import           System.Metrics.Prometheus.Metric.Counter      (Counter)
import           System.Metrics.Prometheus.Metric.Gauge        (Gauge)
import           System.Metrics.Prometheus.Metric.Histogram    (Histogram)
import qualified System.Metrics.Prometheus.Metric.Histogram    as Histogram
import           System.Metrics.Prometheus.MetricId            (Labels, Name)
import           System.Metrics.Prometheus.Registry            (RegistrySample)


newtype RegistryT m a =
    RegistryT { RegistryT m a -> ReaderT Registry m a
unRegistryT :: ReaderT Registry m a }
    deriving (Applicative (RegistryT m)
a -> RegistryT m a
Applicative (RegistryT m)
-> (forall a b.
    RegistryT m a -> (a -> RegistryT m b) -> RegistryT m b)
-> (forall a b. RegistryT m a -> RegistryT m b -> RegistryT m b)
-> (forall a. a -> RegistryT m a)
-> Monad (RegistryT m)
RegistryT m a -> (a -> RegistryT m b) -> RegistryT m b
RegistryT m a -> RegistryT m b -> RegistryT m b
forall a. a -> RegistryT m a
forall a b. RegistryT m a -> RegistryT m b -> RegistryT m b
forall a b. RegistryT m a -> (a -> RegistryT m b) -> RegistryT m b
forall (m :: * -> *). Monad m => Applicative (RegistryT m)
forall (m :: * -> *) a. Monad m => a -> RegistryT m a
forall (m :: * -> *) a b.
Monad m =>
RegistryT m a -> RegistryT m b -> RegistryT m b
forall (m :: * -> *) a b.
Monad m =>
RegistryT m a -> (a -> RegistryT m b) -> RegistryT m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> RegistryT m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> RegistryT m a
>> :: RegistryT m a -> RegistryT m b -> RegistryT m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
RegistryT m a -> RegistryT m b -> RegistryT m b
>>= :: RegistryT m a -> (a -> RegistryT m b) -> RegistryT m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
RegistryT m a -> (a -> RegistryT m b) -> RegistryT m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (RegistryT m)
Monad, m a -> RegistryT m a
(forall (m :: * -> *) a. Monad m => m a -> RegistryT m a)
-> MonadTrans RegistryT
forall (m :: * -> *) a. Monad m => m a -> RegistryT m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> RegistryT m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> RegistryT m a
MonadTrans, Functor (RegistryT m)
a -> RegistryT m a
Functor (RegistryT m)
-> (forall a. a -> RegistryT m a)
-> (forall a b.
    RegistryT m (a -> b) -> RegistryT m a -> RegistryT m b)
-> (forall a b c.
    (a -> b -> c) -> RegistryT m a -> RegistryT m b -> RegistryT m c)
-> (forall a b. RegistryT m a -> RegistryT m b -> RegistryT m b)
-> (forall a b. RegistryT m a -> RegistryT m b -> RegistryT m a)
-> Applicative (RegistryT m)
RegistryT m a -> RegistryT m b -> RegistryT m b
RegistryT m a -> RegistryT m b -> RegistryT m a
RegistryT m (a -> b) -> RegistryT m a -> RegistryT m b
(a -> b -> c) -> RegistryT m a -> RegistryT m b -> RegistryT m c
forall a. a -> RegistryT m a
forall a b. RegistryT m a -> RegistryT m b -> RegistryT m a
forall a b. RegistryT m a -> RegistryT m b -> RegistryT m b
forall a b. RegistryT m (a -> b) -> RegistryT m a -> RegistryT m b
forall a b c.
(a -> b -> c) -> RegistryT m a -> RegistryT m b -> RegistryT m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *). Applicative m => Functor (RegistryT m)
forall (m :: * -> *) a. Applicative m => a -> RegistryT m a
forall (m :: * -> *) a b.
Applicative m =>
RegistryT m a -> RegistryT m b -> RegistryT m a
forall (m :: * -> *) a b.
Applicative m =>
RegistryT m a -> RegistryT m b -> RegistryT m b
forall (m :: * -> *) a b.
Applicative m =>
RegistryT m (a -> b) -> RegistryT m a -> RegistryT m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> RegistryT m a -> RegistryT m b -> RegistryT m c
<* :: RegistryT m a -> RegistryT m b -> RegistryT m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
RegistryT m a -> RegistryT m b -> RegistryT m a
*> :: RegistryT m a -> RegistryT m b -> RegistryT m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
RegistryT m a -> RegistryT m b -> RegistryT m b
liftA2 :: (a -> b -> c) -> RegistryT m a -> RegistryT m b -> RegistryT m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> RegistryT m a -> RegistryT m b -> RegistryT m c
<*> :: RegistryT m (a -> b) -> RegistryT m a -> RegistryT m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
RegistryT m (a -> b) -> RegistryT m a -> RegistryT m b
pure :: a -> RegistryT m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> RegistryT m a
$cp1Applicative :: forall (m :: * -> *). Applicative m => Functor (RegistryT m)
Applicative, a -> RegistryT m b -> RegistryT m a
(a -> b) -> RegistryT m a -> RegistryT m b
(forall a b. (a -> b) -> RegistryT m a -> RegistryT m b)
-> (forall a b. a -> RegistryT m b -> RegistryT m a)
-> Functor (RegistryT m)
forall a b. a -> RegistryT m b -> RegistryT m a
forall a b. (a -> b) -> RegistryT m a -> RegistryT m b
forall (m :: * -> *) a b.
Functor m =>
a -> RegistryT m b -> RegistryT m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> RegistryT m a -> RegistryT m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> RegistryT m b -> RegistryT m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> RegistryT m b -> RegistryT m a
fmap :: (a -> b) -> RegistryT m a -> RegistryT m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> RegistryT m a -> RegistryT m b
Functor, Monad (RegistryT m)
Monad (RegistryT m)
-> (forall a. IO a -> RegistryT m a) -> MonadIO (RegistryT m)
IO a -> RegistryT m a
forall a. IO a -> RegistryT m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (RegistryT m)
forall (m :: * -> *) a. MonadIO m => IO a -> RegistryT m a
liftIO :: IO a -> RegistryT m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> RegistryT m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (RegistryT m)
MonadIO)


runRegistryT :: MonadIO m => RegistryT m a -> m a
runRegistryT :: RegistryT m a -> m a
runRegistryT RegistryT m a
registry = IO Registry -> m Registry
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Registry
new m Registry -> (Registry -> m a) -> m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ReaderT Registry m a -> Registry -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (RegistryT m a -> ReaderT Registry m a
forall (m :: * -> *) a. RegistryT m a -> ReaderT Registry m a
unRegistryT RegistryT m a
registry)


registerCounter :: MonadIO m => Name -> Labels -> RegistryT m Counter
registerCounter :: Name -> Labels -> RegistryT m Counter
registerCounter Name
n Labels
l = ReaderT Registry m Registry -> RegistryT m Registry
forall (m :: * -> *) a. ReaderT Registry m a -> RegistryT m a
RegistryT ReaderT Registry m Registry
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask RegistryT m Registry
-> (Registry -> RegistryT m Counter) -> RegistryT m Counter
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO Counter -> RegistryT m Counter
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Counter -> RegistryT m Counter)
-> (Registry -> IO Counter) -> Registry -> RegistryT m Counter
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Labels -> Registry -> IO Counter
R.registerCounter Name
n Labels
l


registerGauge :: MonadIO m => Name -> Labels -> RegistryT m Gauge
registerGauge :: Name -> Labels -> RegistryT m Gauge
registerGauge Name
n Labels
l = ReaderT Registry m Registry -> RegistryT m Registry
forall (m :: * -> *) a. ReaderT Registry m a -> RegistryT m a
RegistryT ReaderT Registry m Registry
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask RegistryT m Registry
-> (Registry -> RegistryT m Gauge) -> RegistryT m Gauge
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO Gauge -> RegistryT m Gauge
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Gauge -> RegistryT m Gauge)
-> (Registry -> IO Gauge) -> Registry -> RegistryT m Gauge
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Labels -> Registry -> IO Gauge
R.registerGauge Name
n Labels
l


registerHistogram :: MonadIO m => Name -> Labels -> [Histogram.UpperBound] -> RegistryT m Histogram
registerHistogram :: Name -> Labels -> [UpperBound] -> RegistryT m Histogram
registerHistogram Name
n Labels
l [UpperBound]
b = ReaderT Registry m Registry -> RegistryT m Registry
forall (m :: * -> *) a. ReaderT Registry m a -> RegistryT m a
RegistryT ReaderT Registry m Registry
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask RegistryT m Registry
-> (Registry -> RegistryT m Histogram) -> RegistryT m Histogram
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO Histogram -> RegistryT m Histogram
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Histogram -> RegistryT m Histogram)
-> (Registry -> IO Histogram) -> Registry -> RegistryT m Histogram
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Labels -> [UpperBound] -> Registry -> IO Histogram
R.registerHistogram Name
n Labels
l [UpperBound]
b


sample :: Monad m => RegistryT m (IO RegistrySample)
sample :: RegistryT m (IO RegistrySample)
sample = Registry -> IO RegistrySample
R.sample (Registry -> IO RegistrySample)
-> RegistryT m Registry -> RegistryT m (IO RegistrySample)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT Registry m Registry -> RegistryT m Registry
forall (m :: * -> *) a. ReaderT Registry m a -> RegistryT m a
RegistryT ReaderT Registry m Registry
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask