module System.Metrics.Prometheus.Http.Push
( pushHttpProtoMetrics
)
where
import Control.Concurrent (threadDelay)
import Control.Monad (forever)
import Data.Map (foldMapWithKey)
import Data.Text (Text, unpack)
import Network.Wreq.Session (put,
withSession)
import System.Metrics.Prometheus.Encode.ProtocolBuffers ()
import System.Metrics.Prometheus.MetricId (Labels (..))
import System.Metrics.Prometheus.Registry (RegistrySample)
pushHttpProtoMetrics :: String
-> Text
-> Labels
-> Int
-> IO RegistrySample
-> IO ()
pushHttpProtoMetrics base job (Labels ls) frequency get =
withSession $ \session -> forever $
get >>= put session url >> threadDelay frequency
where
url = base ++ "/metrics/job/" ++ unpack job ++
foldMapWithKey (\k v -> "/" ++ unpack k ++ "/" ++ unpack v) ls