packages feed

prometheus 2.1.2 → 2.1.3

raw patch · 3 files changed

+55/−29 lines, 3 filesdep +http-client-tlsdep ~basedep ~http-clientdep ~warpPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: http-client-tls

Dependency ranges changed: base, http-client, warp

API changes (from Hackage documentation)

- System.Metrics.Prometheus.Http.Push: pushHttpTextMetrics :: URIAuth -> Text -> Labels -> Int -> IO RegistrySample -> IO ()
+ System.Metrics.Prometheus.Http.Push: parseURI :: String -> Maybe URI
+ System.Metrics.Prometheus.Http.Push: pushMetrics :: URI -> Text -> Labels -> Int -> IO RegistrySample -> IO ()

Files

README.md view
@@ -1,13 +1,21 @@ # Prometheus Haskell Client -A simple and modern, type safe, idiomatic Haskell client for-[Prometheus](http://prometheus.io) monitoring. Specifically there is+[![Build Status](https://travis-ci.com/bitnomial/prometheus.svg?branch=master)](https://travis-ci.com/bitnomial/prometheus)+[![Hackage](https://img.shields.io/hackage/v/prometheus.svg)](https://hackage.haskell.org/package/prometheus)++A simple and modern, type safe, performance focused, idiomatic Haskell client+for [Prometheus](http://prometheus.io) monitoring. Specifically there is no use of unsafe IO or manual ByteString construction from lists of-bytes. Batteries-included web server. Version 0.* supports Prometheus v1.0-  and version 2.* supports Prometheus v2.0.+bytes. Batteries-included web server. +A key design element of this library is that the RegistryT monad transformer+is only required for registering new time series. Once the time series is+registered, new data samples may just be added in the IO monad.++Note: Version 0.* supports Prometheus v1.0 and version 2.* supports Prometheus v2.0.+ - [Hackage Package](https://hackage.haskell.org/package/prometheus)-- [Github](http://github.com/LukeHoersten/prometheus)+- [Github Repo](http://github.com/bitnomial/prometheus)  ## Usage Example 
prometheus.cabal view
@@ -1,5 +1,5 @@ name:                prometheus-version:             2.1.2+version:             2.1.3 synopsis:            Prometheus Haskell Client homepage:            http://github.com/bitnomial/prometheus bug-reports:         http://github.com/bitnomial/prometheus/issues@@ -15,12 +15,17 @@ description:   [Prometheus Haskell Client]   .-  A simple and modern, type safe, idiomatic Haskell client for-  <http://prometheus.io Prometheus> monitoring. Specifically there is no+  A simple and modern, type safe, performance focused, idiomatic Haskell client+  for <http://prometheus.io Prometheus> monitoring. Specifically there is no   use of unsafe IO or manual ByteString construction from lists of-  bytes. Batteries-included web server. Version 0.* supports Prometheus v1.0-  and version 2.* supports Prometheus v2.0.+  bytes. Batteries-included web server.   .+  A key design element of this library is that the RegistryT monad transformer+  is only required for registering new time series. Once the time series is+  registered, new data samples may just be added in the IO monad.+  .+  Note: Version 0.* supports Prometheus v1.0 and version 2.* supports Prometheus v2.0.+  .   [Usage Example]   .   > module Example where@@ -77,17 +82,18 @@                  , System.Metrics.Prometheus.Registry                  , System.Metrics.Prometheus.RegistryT -  build-depends: base           >= 4.9  && < 4.13+  build-depends: base           >= 4.9  && < 4.14                , atomic-primops >= 0.8  && < 0.9                , bytestring     >= 0.10 && < 0.11                , containers     >= 0.5  && < 0.7-               , http-client    >= 0.4  && < 0.6+               , http-client    >= 0.4  && < 0.7+               , http-client-tls >= 0.3  && < 0.4                , http-types     >= 0.8  && < 0.13                , network-uri    >= 2.5  && < 2.7                , text           >= 1.2  && < 1.3                , transformers   >= 0.4  && < 0.6                , wai            >= 3.2  && < 3.3-               , warp           >= 3.2  && < 3.3+               , warp           >= 3.2  && < 3.5  source-repository head   type:     git
src/System/Metrics/Prometheus/Http/Push.hs view
@@ -1,7 +1,8 @@ {-# LANGUAGE OverloadedStrings #-}  module System.Metrics.Prometheus.Http.Push-       ( pushHttpTextMetrics+       ( pushMetrics+       , parseURI        )        where @@ -12,12 +13,14 @@ import           Data.Text                             (Text, unpack) import           Network.HTTP.Client                   (Request (..),                                                         RequestBody (..),-                                                        defaultManagerSettings,-                                                        httpNoBody, newManager,+                                                        getUri,+                                                        httpNoBody,+                                                        parseRequest,                                                         requestBody,                                                         requestFromURI,                                                         requestHeaders) import           Network.HTTP.Types                    (hContentType, methodPut)+import           Network.HTTP.Client.TLS               (newTlsManager) import           Network.URI                           (URI (..), URIAuth,                                                         nullURI) @@ -25,28 +28,37 @@ import           System.Metrics.Prometheus.MetricId    (Labels (..)) import           System.Metrics.Prometheus.Registry    (RegistrySample) +-- | Parses a uri such that+-- @+--   parseURI "https://example.com"+--      ===+--   Just (URI "https:" "//example.com"+-- @+parseURI :: String -> Maybe URI+parseURI = fmap getUri . parseRequest --- | Push text metrics to a pushgateway.-pushHttpTextMetrics :: URIAuth           -- ^ PushGateway URI name, including port number (ex: myGateway.com:8080)-                    -> Text              -- ^ Job name-                    -> Labels            -- ^ Label set to use as a grouping key for metrics-                    -> Int               -- ^ Microsecond push frequency-                    -> IO RegistrySample -- ^ Action to get latest metrics-                    -> IO ()-pushHttpTextMetrics gatewayName jobName labels frequencyMicros getSample = do-    manager    <- newManager defaultManagerSettings-    requestUri <- requestFromURI $ buildUri gatewayName jobName labels+pushMetrics :: URI               -- ^ PushGateway URI name, including port number (ex: @parseUri https://myGateway.com:8080@)+            -> Text              -- ^ Job name+            -> Labels            -- ^ Label set to use as a grouping key for metrics+            -> Int               -- ^ Microsecond push frequency+            -> IO RegistrySample -- ^ Action to get latest metrics+            -> IO ()+pushMetrics gatewayURI jobName labels frequencyMicros getSample = do+    manager    <- newTlsManager+    gn         <- maybe (error "Invalid URI Authority") pure gatewayName+    requestUri <- requestFromURI $ buildUri scheme gn jobName labels     forever $ getSample >>= flip httpNoBody manager . request requestUri >> threadDelay frequencyMicros   where+    URI scheme gatewayName _ _ _ = gatewayURI     request req sample = req         { method         = methodPut         , requestBody    = RequestBodyLBS . toLazyByteString $ encodeMetrics sample         , requestHeaders = [(hContentType, "text/plain; version=0.0.4")]         } -buildUri :: URIAuth -> Text -> Labels -> URI-buildUri gatewayName jobName (Labels ls) = nullURI-    { uriScheme    = "http:"+buildUri :: String -> URIAuth -> Text -> Labels -> URI+buildUri scheme gatewayName jobName (Labels ls) = nullURI+    { uriScheme    = scheme     , uriAuthority = Just gatewayName     , uriPath      = "/metrics/job/" ++ unpack jobName ++ foldMapWithKey labelPath ls     }