packages feed

ngx-export-tools-extra 0.5.0.0 → 0.5.1.0

raw patch · 3 files changed

+46/−22 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Changelog.md view
@@ -1,3 +1,7 @@+### 0.5.1.0++- Added gauge metrics type to Prometheus counters.+ ### 0.5.0.0  - Added module *NgxExport.Tools.Prometheus* to convert custom counters from
NgxExport/Tools/Prometheus.hs view
@@ -57,6 +57,7 @@  data PrometheusConf =     PrometheusConf { pcMetrics :: Map MetricsName MetricsHelp+                   , pcGauges :: [MetricsName]                    , pcScale1000 :: [MetricsName]                    } deriving Read @@ -76,6 +77,7 @@     (ServerName, AllCounters, AllHistogramsLayout, AllOtherCounters)  data MetricsType = Counter Double+                 | Gauge Double                  | Histogram HistogramData  type PrometheusMetrics = Map MetricsName (MetricsHelp, MetricsType)@@ -159,10 +161,12 @@ --                 { __/pcMetrics/__ = fromList --                     [(\"cnt_4xx\", \"Number of responses with 4xx status\") --                     ,(\"cnt_5xx\", \"Number of responses with 5xx status\")+--                     ,(\"cnt_stub_status_active\", \"Active requests\") --                     ,(\"cnt_uptime\", \"Nginx master uptime\") --                     ,(\"cnt_uptime_reload\", \"Nginx master uptime after reload\") --                     ,(\"hst_request_time\", \"Request duration\") --                     ]+--                 , __/pcGauges/__ = [\"cnt_stub_status_active\"] --                 , __/pcScale1000/__ = [\"hst_request_time_sum\"] --                 }'; --@@ -212,11 +216,12 @@ --         location \/ { --             haskell_run __/toPrometheusMetrics/__ $hs_prom_metrics --                     '[\"__/main/__\"---                       ,__/$cnt_collection/__---                       ,__/$cnt_histograms/__---                       ,{\"cnt_uptime\": $cnt_uptime---                        ,\"cnt_uptime_reload\": $cnt_uptime_reload---                        }+--                      ,__/$cnt_collection/__+--                      ,__/$cnt_histograms/__+--                      ,{\"cnt_stub_status_active\": $cnt_stub_status_active+--                       ,\"cnt_uptime\": $cnt_uptime+--                       ,\"cnt_uptime_reload\": $cnt_uptime_reload+--                       } --                      ]'; -- --             if ($hs_prom_metrics = \'\') {@@ -235,22 +240,24 @@ --         } -- --         location \/uptime {---             echo "$cnt_uptime ($cnt_uptime_reload)";+--             echo "Uptime (after reload): $cnt_uptime ($cnt_uptime_reload)"; --         } --     } -- } -- @ ----- Type /PrometheusConf/ contains fields /pcMetrics/ and /pcScale1000/. The--- latter is a map from metrics names to help messages: this can be used to--- bind small descriptions to the metrics as /nginx-custom-counters-module/--- does not provide such functionality. Setting descriptions to counters is--- optional. Field /pcScale1000/ contains a list of counters that were scaled--- with /scale1000/ and must be converted back.+-- Type /PrometheusConf/ contains fields /pcMetrics/, /pcGauges/, and+-- /pcScale1000/. Field /pcMetrics/ is a map from metrics names to help+-- messages: this can be used to bind small descriptions to the metrics as+-- /nginx-custom-counters-module/ does not provide such functionality. Setting+-- descriptions to counters is optional. Field /pcGauges/ lists counters that+-- must be regarded as gauges: the number of currently active requests is+-- obviously a gauge. Field /pcScale1000/ contains a list of counters that were+-- scaled with /scale1000/ and must be converted back. -- -- Handler /toPrometheusMetrics/ expects 4 fields: the name of the--- /counter set id/: in our example there is only one counter set /main/,--- predefined variables /cnt_collection/ and /cnt_histograms/ from+-- /counter set identifier/: in our example there is only one counter set+-- /main/, predefined variables /cnt_collection/ and /cnt_histograms/ from -- /nginx-custom-counters-module/, and a list of additional counters: in our -- example there are two additional counters /cnt_uptime/ and -- /cnt_uptime_reload/ which are also defined in@@ -259,8 +266,8 @@ -- To fulfill histogram description in Prometheus, the /sum/ value must be -- provided. Histogram sums are not supported in /nginx-custom-counters-module/, -- and therefore they must be declared in separate counters. In this example--- there are two histograms collecting request durations and sent bytes:--- accordingly, there are two sum counters: /hst_request_time_sum/ and+-- there are two histograms collecting request durations and the number of sent+-- bytes: accordingly, there are two sum counters: /hst_request_time_sum/ and -- /hst_bytes_sent_sum/. As request durations may last milliseconds while being -- shown in seconds, they must be scaled with /scale1000/. --@@ -283,6 +290,9 @@ -- > # HELP cnt_5xx Number of responses with 5xx status -- > # TYPE cnt_5xx counter -- > cnt_5xx 0.0+-- > # HELP cnt_stub_status_active Active requests+-- > # TYPE cnt_stub_status_active gauge+-- > cnt_stub_status_active 1.0 -- > # HELP cnt_uptime Nginx master uptime -- > # TYPE cnt_uptime counter -- > cnt_uptime 8.0@@ -337,6 +347,9 @@ -- > # HELP cnt_5xx Number of responses with 5xx status -- > # TYPE cnt_5xx counter -- > cnt_5xx 0.0+-- > # HELP cnt_stub_status_active Active requests+-- > # TYPE cnt_stub_status_active gauge+-- > cnt_stub_status_active 1.0 -- > # HELP cnt_uptime Nginx master uptime -- > # TYPE cnt_uptime counter -- > cnt_uptime 371.0@@ -395,15 +408,16 @@         hs' = M.lookup srv hs         (cntsH, cntsC) =             if maybe True M.null hs'-                then (M.empty, M.map Counter cnts')+                then (M.empty, M.mapWithKey cType cnts')                 else let hs'' = fromJust hs'                          rs = M.keys &&& M.foldr labeledRange M.empty $ hs''                          cntsH' = M.filterWithKey (hCounter rs) cnts'                          cntsC' = cnts' `M.difference` cntsH'                          cntsH'' = M.mapWithKey                              (\k -> toHistogram cntsH' k . range) hs''-                     in (M.map Histogram cntsH'', M.map Counter cntsC')-        cntsA = cntsH `M.union` cntsC `M.union` M.map Counter (toValues ocnts)+                     in (M.map Histogram cntsH'', M.mapWithKey cType cntsC')+        cntsA = cntsH `M.union` cntsC `M.union`+            M.mapWithKey cType (toValues ocnts)     in M.mapWithKey (\k v -> case M.lookup k pcMetrics of                                  Nothing -> ("", v)                                  Just h -> (h, v)@@ -419,6 +433,9 @@                                      in ((k == v1 || k == v2) :)                                 ) [] ks                       )+          cType k v = if k `elem` pcGauges+                          then Gauge v+                          else Counter v           toHistogram cs hk rs =               let ranges = M.mapWithKey                       (\k l -> case M.lookup k cs of@@ -440,14 +457,17 @@     (\a k (h, m) -> T.concat [a, "# HELP ", k, " ", h, "\n"                              ,   "# TYPE ", k, " ", showType m, "\n"                              ,case m of+                                  Counter v ->+                                      T.concat [k, " ", T.pack $ show v, "\n"]+                                  Gauge v ->+                                      T.concat [k, " ", T.pack $ show v, "\n"]                                   Histogram h' -> fst $                                       M.foldlWithKey (showHistogram k)                                           ("", 0.0) h'-                                  Counter v ->-                                      T.concat [k, " ", T.pack $ show v, "\n"]                              ]     ) ""     where showType (Counter _) = "counter"+          showType (Gauge _) = "gauge"           showType (Histogram _) = "histogram"           showHistogram k a@(t, n) c (l, v) =               if T.null l
ngx-export-tools-extra.cabal view
@@ -1,5 +1,5 @@ name:                       ngx-export-tools-extra-version:                    0.5.0.0+version:                    0.5.1.0 synopsis:                   More extra tools for Nginx haskell module description:                More extra tools for         <https://github.com/lyokha/nginx-haskell-module Nginx haskell module>.