packages feed

prometheus 2.0.2 → 2.1.0

raw patch · 3 files changed

+41/−37 lines, 3 filesdep +network-uridep −wreqdep ~http-client

Dependencies added: network-uri

Dependencies removed: wreq

Dependency ranges changed: http-client

Files

README.md view
@@ -3,7 +3,8 @@ A simple and modern, type safe, 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.  .  [Usage Example]+bytes. Batteries-included web server. 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)
prometheus.cabal view
@@ -1,5 +1,5 @@ name:                prometheus-version:             2.0.2+version:             2.1.0 synopsis:            Prometheus Haskell Client homepage:            http://github.com/bitnomial/prometheus bug-reports:         http://github.com/bitnomial/prometheus/issues@@ -77,17 +77,17 @@                  , System.Metrics.Prometheus.Registry                  , System.Metrics.Prometheus.RegistryT -  build-depends: base              >= 4.7  && < 4.12-               , atomic-primops    >= 0.8  && < 0.9-               , bytestring        >= 0.10 && < 0.11-               , containers        >= 0.5  && < 0.6-               , http-client       >= 0.5  && < 0.6-               , http-types        >= 0.8  && < 0.13-               , text              >= 1.2  && < 1.3-               , transformers      >= 0.4  && < 0.6-               , wai               >= 3.2  && < 3.3-               , warp              >= 3.2  && < 3.3-               , wreq              >= 0.5  && < 0.6+  build-depends: base           >= 4.7  && < 4.12+               , atomic-primops >= 0.8  && < 0.9+               , bytestring     >= 0.10 && < 0.11+               , containers     >= 0.5  && < 0.6+               , http-client    >= 0.4  && < 0.6+               , 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  source-repository head   type:     git
src/System/Metrics/Prometheus/Http/Push.hs view
@@ -10,13 +10,16 @@ import           Data.ByteString.Builder               (toLazyByteString) import           Data.Map                              (foldMapWithKey) import           Data.Text                             (Text, unpack)-import           Network.HTTP.Client                   (Request,+import           Network.HTTP.Client                   (Request (..),                                                         RequestBody (..),+                                                        defaultManagerSettings,+                                                        httpNoBody, newManager,                                                         requestBody,+                                                        requestFromURI,                                                         requestHeaders)-import           Network.HTTP.Types                    (hContentType)-import           Network.Wreq.Session                  (newSession, put)-import           Network.Wreq.Types                    (Putable (..))+import           Network.HTTP.Types                    (hContentType, methodPut)+import           Network.URI                           (URI (..), URIAuth,+                                                        nullURI)  import           System.Metrics.Prometheus.Encode.Text (encodeMetrics) import           System.Metrics.Prometheus.MetricId    (Labels (..))@@ -24,27 +27,27 @@   -- | Push text metrics to a pushgateway.-pushHttpTextMetrics :: String            -- ^ The base URL of the pushgateway, including the port number.-                    -> Text              -- ^ The name of this job.-                    -> Labels            -- ^ The label set to use as a grouping key for these metrics.-                    -> Int               -- ^ Push frequency, in microseconds.-                    -> IO RegistrySample -- ^ The action to get the latest metrics.+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 base job (Labels ls) frequency getSample = do-    session <- newSession-    forever $ getSample >>= put session url >> threadDelay frequency+pushHttpTextMetrics gatewayName jobName labels frequencyMicros getSample = do+    manager    <- newManager defaultManagerSettings+    requestUri <- requestFromURI $ buildUri gatewayName jobName labels+    forever $ getSample >>= flip httpNoBody manager . request requestUri >> threadDelay frequencyMicros   where-    url = base ++ "/metrics/job/" ++ unpack job ++-        foldMapWithKey (\k v -> "/" ++ unpack k ++ "/" ++ unpack v) ls---instance Putable RegistrySample where-    putPayload = (pure .) . metricsRequest-+    request req sample = req+        { method         = methodPut+        , requestBody    = RequestBodyLBS . toLazyByteString $ encodeMetrics sample+        , requestHeaders = [(hContentType, "text/plain; version=0.0.4")]+        } -metricsRequest :: RegistrySample -> Request -> Request-metricsRequest s req = req-    { requestBody    = RequestBodyLBS . toLazyByteString $ encodeMetrics s-    , requestHeaders = contentType : requestHeaders req+buildUri :: URIAuth -> Text -> Labels -> URI+buildUri gatewayName jobName (Labels ls) = nullURI+    { uriScheme    = "http:"+    , uriAuthority = Just gatewayName+    , uriPath      = "/metrics/job/" ++ unpack jobName ++ foldMapWithKey labelPath ls     }-  where contentType = (hContentType, "text/plain; version=0.0.4")+  where labelPath k v = "/" ++ unpack k ++ "/" ++ unpack v