-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskell client library for http://prometheus.io. -- -- Haskell client library for http://prometheus.io. @package prometheus-client @version 1.1.0 -- | This module provides the basics for instrumenting Haskell executables -- for use with the Prometheus monitoring system. module Prometheus -- | Registers a metric with the global metric registry. registerIO :: MonadIO m => m (Metric s) -> m s -- | Registers a metric with the global metric registry. register :: MonadIO m => Metric s -> m s -- | Registers a metric with the global metric registry. -- -- IMPORTANT: This method should only be used to register metrics -- as top level symbols, it should not be run from other pure code. -- -- For example, -- --
-- >>> :{
-- {-# NOINLINE c #-}
-- let c = unsafeRegisterIO $ counter (Info "my_counter" "An example metric")
-- :}
-- ...
--
unsafeRegisterIO :: IO (Metric s) -> s
-- | Registers a metric with the global metric registry.
--
-- IMPORTANT: This method should only be used to register metrics
-- as top level symbols, it should not be run from other pure code.
unsafeRegister :: Metric s -> s
-- | Removes all currently registered metrics from the registry.
unregisterAll :: MonadIO m => m ()
-- | Collect samples from all currently registered metrics. In typical use
-- cases there is no reason to use this function, instead you should use
-- exportMetricsAsText or a convenience library.
--
-- This function is likely only of interest if you wish to export metrics
-- in a non-supported format for use with another monitoring service.
collectMetrics :: MonadIO m => m [SampleGroup]
-- | Export all registered metrics in the Prometheus 0.0.4 text exposition
-- format.
--
-- For the full specification of the format, see the official Prometheus
-- documentation.
--
-- -- >>> :m +Data.ByteString -- -- >>> myCounter <- register $ counter (Info "my_counter" "Example counter") -- -- >>> incCounter myCounter -- -- >>> exportMetricsAsText >>= Data.ByteString.Lazy.putStr -- # HELP my_counter Example counter -- # TYPE my_counter counter -- my_counter 1.0 --exportMetricsAsText :: MonadIO m => m ByteString data Counter -- | Creates a new counter metric with a given name and help string. counter :: Info -> Metric Counter -- | Increments the value of a counter metric by 1. incCounter :: MonadMonitor m => Counter -> m () -- | Add the given value to the counter, if it is zero or more. addCounter :: MonadMonitor m => Counter -> Double -> m Bool -- | Add the given value to the counter. Panic if it is less than zero. unsafeAddCounter :: MonadMonitor m => Counter -> Double -> m () -- | Add the duration of an IO action (in seconds) to a counter. -- -- If the IO action throws, no duration is added. addDurationToCounter :: (MonadIO m, MonadMonitor m) => Counter -> m a -> m a -- | Count the amount of times an action throws any synchronous exception. -- --
-- >>> exceptions <- register $ counter (Info "exceptions_total" "Total amount of exceptions thrown")
--
-- >>> countExceptions exceptions $ return ()
--
-- >>> getCounter exceptions
-- 0.0
--
-- >>> countExceptions exceptions (error "Oh no!") `catch` (\SomeException{} -> return ())
--
-- >>> getCounter exceptions
-- 1.0
--
--
-- It's important to note that this will count *all* synchronous
-- exceptions. If you want more granular counting of exceptions, you will
-- need to write custom code using incCounter.
countExceptions :: (MonadCatch m, MonadMonitor m) => Counter -> m a -> m a
-- | Retrieves the current value of a counter metric.
getCounter :: MonadIO m => Counter -> m Double
data Gauge
-- | Create a new gauge metric with a given name and help string.
gauge :: Info -> Metric Gauge
-- | Increments a gauge metric by 1.
incGauge :: MonadMonitor m => Gauge -> m ()
-- | Decrements a gauge metric by 1.
decGauge :: MonadMonitor m => Gauge -> m ()
-- | Adds a value to a gauge metric.
addGauge :: MonadMonitor m => Gauge -> Double -> m ()
-- | Subtracts a value from a gauge metric.
subGauge :: MonadMonitor m => Gauge -> Double -> m ()
-- | Sets a gauge metric to a specific value.
setGauge :: MonadMonitor m => Gauge -> Double -> m ()
-- | Sets a gauge metric to the duration in seconds of an IO action.
setGaugeToDuration :: (MonadIO m, MonadMonitor m) => Gauge -> m a -> m a
-- | Retrieves the current value of a gauge metric.
getGauge :: MonadIO m => Gauge -> m Double
-- | Interface shared by Summary and Histogram.
class Observer metric
-- | Observe that a particular floating point value has occurred. For
-- example, observe that this request took 0.23s.
observe :: (Observer metric, MonadMonitor m) => metric -> Double -> m ()
-- | Adds the duration in seconds of an IO action as an observation to an
-- observer metric.
--
-- If the IO action throws an exception no duration will be observed.
observeDuration :: (Observer metric, MonadIO m, MonadMonitor m) => metric -> m a -> m a
data Summary
type Quantile = (Rational, Rational)
-- | Creates a new summary metric with a given name, help string, and a
-- list of quantiles. A reasonable set set of quantiles is provided by
-- defaultQuantiles.
summary :: Info -> [Quantile] -> Metric Summary
defaultQuantiles :: [Quantile]
-- | Retrieves a list of tuples containing a quantile and its associated
-- value.
getSummary :: MonadIO m => Summary -> m [(Rational, Double)]
-- | A histogram. Counts the number of observations that fall within the
-- specified buckets.
data Histogram
-- | Upper-bound for a histogram bucket.
type Bucket = Double
-- | Create a new Histogram metric with a given name, help string,
-- and list of buckets. Panics if the list of buckets is not strictly
-- increasing. A good default list of buckets is defaultBuckets.
-- You can also create buckets with linearBuckets or
-- exponentialBuckets.
histogram :: Info -> [Bucket] -> Metric Histogram
-- | The default Histogram buckets. These are tailored to measure the
-- response time (in seconds) of a network service. You will almost
-- certainly need to customize them for your particular use case.
defaultBuckets :: [Double]
-- | Create count buckets, where the lowest bucket has an upper
-- bound of start and each bucket's upper bound is
-- factor times the previous bucket's upper bound. Use this to
-- create buckets for histogram.
exponentialBuckets :: Bucket -> Double -> Int -> [Bucket]
-- | Create count buckets, each width wide, where the
-- lowest bucket has an upper bound of start. Use this to create
-- buckets for histogram.
linearBuckets :: Bucket -> Double -> Int -> [Bucket]
-- | Retries a map of upper bounds to counts of values observed that are
-- less-than-or-equal-to that upper bound, but greater than any other
-- upper bound in the map.
getHistogram :: MonadIO m => Histogram -> m (Map Bucket Int)
data Vector l m
-- | Creates a new vector of metrics given a label.
vector :: Label l => l -> Metric m -> Metric (Vector l m)
-- | Given a label, applies an operation to the corresponding metric in the
-- vector.
withLabel :: (Label label, MonadMonitor m) => Vector label metric -> label -> (metric -> IO ()) -> m ()
-- | Removes a label from a vector.
removeLabel :: (Label label, MonadMonitor m) => Vector label metric -> label -> m ()
-- | Removes all labels from a vector.
clearLabels :: (Label label, MonadMonitor m) => Vector label metric -> m ()
getVectorWith :: Vector label metric -> (metric -> IO a) -> IO [(label, a)]
-- | Label describes a class of types that can be used to as the label of a
-- vector.
class Ord l => Label l
labelPairs :: Label l => l -> l -> LabelPairs
-- | A list of tuples where the first value is the label and the second is
-- the value of that label.
type LabelPairs = [(Text, Text)]
type Label0 = ()
type Label1 = Text
type Label2 = (Text, Text)
type Label3 = (Text, Text, Text)
type Label4 = (Text, Text, Text, Text)
type Label5 = (Text, Text, Text, Text, Text)
type Label6 = (Text, Text, Text, Text, Text, Text)
type Label7 = (Text, Text, Text, Text, Text, Text, Text)
type Label8 = (Text, Text, Text, Text, Text, Text, Text, Text)
type Label9 = (Text, Text, Text, Text, Text, Text, Text, Text, Text)
-- | MonadMonitor describes a class of Monads that are capable of
-- performing asynchronous IO operations.
class Monad m => MonadMonitor m
doIO :: MonadMonitor m => IO () -> m ()
doIO :: (MonadMonitor m, MonadTrans t, MonadMonitor n, m ~ t n) => IO () -> m ()
-- | Monitor allows the use of Prometheus metrics in pure code. When using
-- Monitor, all of the metric operations will be collected and queued
-- into a single IO () value that can be run from impure code.
--
-- Because all of the operations are performed asynchronously use of this
-- class is not recommended for use with metrics that are time sensitive
-- (e.g. for measuring latency).
type Monitor a = MonitorT Identity a
-- | Extract a value and the corresponding monitor update value from the
-- Monitor monad. For an example use see Monitor.
runMonitor :: Monitor a -> (a, IO ())
-- | MonitorT is the monad transformer analog of Monitor and allows for
-- monitoring pure monad transformer stacks.
data MonitorT m a
-- | Extract a value and the corresponding monitor update value from the
-- MonitorT monad transformer.
runMonitorT :: Monad m => MonitorT m a -> m (a, IO ())
-- | Meta data about a metric including its name and a help string that
-- describes the value that the metric is measuring.
data Info
Info :: Text -> Text -> Info
[metricName] :: Info -> Text
[metricHelp] :: Info -> Text
-- | A metric represents a single value that is being monitored. It is
-- comprised of a handle value and a collect method. The handle value is
-- typically a new type wrapped value that provides access to the
-- internal state of the metric. The collect method samples the current
-- value of the metric.
newtype Metric s
Metric :: IO (s, IO [SampleGroup]) -> Metric s
-- | construct is an IO action that creates a new instance of
-- a metric. For example, in a counter, this IO action would
-- create a mutable reference to maintain the state of the counter.
--
-- construct returns two things:
--
--