prometheus-client 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NjQwNjBmMGRjMjYwMzJmOWVlMDRkNDJiNWM0MTQzYTkwNGE5MWVlZA==
5
- data.tar.gz: !binary |-
6
- MzEyNGViYThkNTViN2RlZTllYTE4MDE1OTQwNDBiMjdhZDQ4MmViNA==
2
+ SHA1:
3
+ metadata.gz: 525f1dcd2ca63486f95a2d2fd44b7f047625edc3
4
+ data.tar.gz: 0480ce9fd716c715553e8c1a0877345f2124b563
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MTBlMDI5NWY3M2UxODgxOTM2MTdiMWM1ODJhZDQxYzRmMGE4NTY2NTBmNWM1
10
- ZjczYTQxZTk0ODNlYjk5YmQ3MDJjMzE0MDU1NTljOGU1ODBlYmY5YjRjOTYy
11
- MmJlZTY4YWEyMjczMzQwNjVlMWEzZDNlM2VhZTIwZWYyYjY4MGM=
12
- data.tar.gz: !binary |-
13
- YWY2ZWRmOTcwZDE0YTdiOTI3MTRlMzE0MDVmNzU3M2RkMjlmYWMyN2E1OGQx
14
- MjJlMTk4ZTg3OTQ3YzQyZTE0Nzg4NTEzYjk0ZDI3MDc5OTU5NWQyMjcyOTNk
15
- MDg1MjcyNTllNmZjMzM5N2MxMGI5OWFiODUyNjA4MGYzMGNiMDA=
6
+ metadata.gz: 362f0157652258f5270dc815434d7ef4768e4842a68a5a344e9dcff41ee494fadcab29d0c15c5764310bfa8d9b1655e27a829a7c62782505ea3c6f611402796e
7
+ data.tar.gz: 548905e7ec71056de3e6a622073bf0fc342f6dca7a6d9c0c783411c35ab7f306aa87f71aecab7fc128a4dfd232f62dcb72dca0682a3421451d162844dab66960
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Prometheus Ruby Client
2
2
 
3
3
  A suite of instrumentation metric primitives for Ruby that can be exposed
4
- through a JSON web services interface. Intended to be used together with a
4
+ through a HTTP interface. Intended to be used together with a
5
5
  [Prometheus server][1].
6
6
 
7
7
  [![Gem Version][4]](http://badge.fury.io/rb/prometheus-client)
@@ -38,6 +38,9 @@ There are two [Rack][2] middlewares available, one to expose a metrics HTTP
38
38
  endpoint to be scraped by a prometheus server ([Exporter][9]) and one to trace all HTTP
39
39
  requests ([Collector][10]).
40
40
 
41
+ It's highly recommended to enable gzip compression for the metrics endpoint,
42
+ for example by including the `Rack::Deflater` middleware.
43
+
41
44
  ```ruby
42
45
  # config.ru
43
46
 
@@ -45,9 +48,11 @@ require 'rack'
45
48
  require 'prometheus/client/rack/collector'
46
49
  require 'prometheus/client/rack/exporter'
47
50
 
51
+ use Rack::Deflater, if: ->(env, status, headers, body) { body.any? && body[0].length > 512 }
48
52
  use Prometheus::Client::Rack::Collector
49
53
  use Prometheus::Client::Rack::Exporter
50
- run lambda { |env| [200, {'Content-Type' => 'text/html'}, ['OK']] }
54
+
55
+ run ->(env) { [200, {'Content-Type' => 'text/html'}, ['OK']] }
51
56
  ```
52
57
 
53
58
  Start the server and have a look at the metrics endpoint:
@@ -11,14 +11,12 @@ module Prometheus
11
11
  end
12
12
 
13
13
  def increment(labels = {}, by = 1)
14
+ fail ArgumentError, 'increment must be a non-negative number' if by < 0
15
+
14
16
  label_set = label_set_for(labels)
15
17
  synchronize { @values[label_set] += by }
16
18
  end
17
19
 
18
- def decrement(labels = {}, by = 1)
19
- increment(labels, -by)
20
- end
21
-
22
20
  private
23
21
 
24
22
  def default
@@ -14,12 +14,7 @@ module Prometheus
14
14
  def initialize(app, options = {}, &label_builder)
15
15
  @app = app
16
16
  @registry = options[:registry] || Client.registry
17
- @label_builder = label_builder || proc do |env|
18
- {
19
- method: env['REQUEST_METHOD'].downcase,
20
- path: env['PATH_INFO'].to_s,
21
- }
22
- end
17
+ @label_builder = label_builder || DEFAULT_LABEL_BUILDER
23
18
 
24
19
  init_request_metrics
25
20
  init_exception_metrics
@@ -31,17 +26,24 @@ module Prometheus
31
26
 
32
27
  protected
33
28
 
29
+ DEFAULT_LABEL_BUILDER = proc do |env|
30
+ {
31
+ method: env['REQUEST_METHOD'].downcase,
32
+ host: env['HTTP_HOST'].to_s,
33
+ path: env['PATH_INFO'].to_s,
34
+ }
35
+ end
36
+
34
37
  def init_request_metrics
35
38
  @requests = @registry.counter(
36
39
  :http_requests_total,
37
40
  'A counter of the total number of HTTP requests made.')
38
41
  @requests_duration = @registry.counter(
39
- :http_request_durations_total_microseconds,
40
- 'The total amount of time spent answering HTTP requests ' \
41
- '(microseconds).')
42
+ :http_request_duration_total_seconds,
43
+ 'The total amount of time spent answering HTTP requests.')
42
44
  @durations = @registry.summary(
43
- :http_request_durations_microseconds,
44
- 'A histogram of the response latency (microseconds).')
45
+ :http_request_duration_seconds,
46
+ 'A histogram of the response latency.')
45
47
  end
46
48
 
47
49
  def init_exception_metrics
@@ -53,7 +55,7 @@ module Prometheus
53
55
  def trace(env)
54
56
  start = Time.now
55
57
  yield.tap do |response|
56
- duration = ((Time.now - start) * 1_000_000).to_i
58
+ duration = (Time.now - start).to_f
57
59
  record(labels(env, response), duration)
58
60
  end
59
61
  rescue => exception
@@ -1,7 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'prometheus/client'
4
- require 'prometheus/client/formats/json'
5
4
  require 'prometheus/client/formats/text'
6
5
 
7
6
  module Prometheus
@@ -12,8 +11,8 @@ module Prometheus
12
11
  class Exporter
13
12
  attr_reader :app, :registry, :path
14
13
 
15
- FORMATS = [Formats::Text, Formats::JSON]
16
- FALLBACK = Formats::JSON
14
+ FORMATS = [Formats::Text]
15
+ FALLBACK = Formats::Text
17
16
 
18
17
  def initialize(app, options = {})
19
18
  @app = app
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prometheus
4
4
  module Client
5
- VERSION = '0.4.2'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schmidt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-18 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: quantile
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.2.0
27
27
  description:
@@ -34,16 +34,15 @@ files:
34
34
  - README.md
35
35
  - lib/prometheus.rb
36
36
  - lib/prometheus/client.rb
37
- - lib/prometheus/client/registry.rb
38
- - lib/prometheus/client/rack/collector.rb
39
- - lib/prometheus/client/rack/exporter.rb
37
+ - lib/prometheus/client/counter.rb
38
+ - lib/prometheus/client/formats/text.rb
40
39
  - lib/prometheus/client/gauge.rb
41
40
  - lib/prometheus/client/label_set_validator.rb
42
- - lib/prometheus/client/formats/json.rb
43
- - lib/prometheus/client/formats/text.rb
44
- - lib/prometheus/client/push.rb
45
41
  - lib/prometheus/client/metric.rb
46
- - lib/prometheus/client/counter.rb
42
+ - lib/prometheus/client/push.rb
43
+ - lib/prometheus/client/rack/collector.rb
44
+ - lib/prometheus/client/rack/exporter.rb
45
+ - lib/prometheus/client/registry.rb
47
46
  - lib/prometheus/client/summary.rb
48
47
  - lib/prometheus/client/version.rb
49
48
  homepage: https://github.com/prometheus/client_ruby
@@ -56,17 +55,17 @@ require_paths:
56
55
  - lib
57
56
  required_ruby_version: !ruby/object:Gem::Requirement
58
57
  requirements:
59
- - - ! '>='
58
+ - - ">="
60
59
  - !ruby/object:Gem::Version
61
60
  version: '0'
62
61
  required_rubygems_version: !ruby/object:Gem::Requirement
63
62
  requirements:
64
- - - ! '>='
63
+ - - ">="
65
64
  - !ruby/object:Gem::Version
66
65
  version: '0'
67
66
  requirements: []
68
67
  rubyforge_project:
69
- rubygems_version: 2.1.11
68
+ rubygems_version: 2.5.1
70
69
  signing_key:
71
70
  specification_version: 4
72
71
  summary: A suite of instrumentation metric primitivesthat can be exposed through a
@@ -1,33 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'json'
4
-
5
- module Prometheus
6
- module Client
7
- module Formats
8
- # JSON format is a deprecated, human-readable format to expose the state
9
- # of a given registry.
10
- module JSON
11
- MEDIA_TYPE = 'application/json'
12
- SCHEMA = 'prometheus/telemetry'
13
- VERSION = '0.0.2'
14
- CONTENT_TYPE = %(#{MEDIA_TYPE}; schema="#{SCHEMA}"; version=#{VERSION})
15
-
16
- MAPPING = { summary: :histogram }
17
-
18
- def self.marshal(registry)
19
- registry.metrics.map do |metric|
20
- {
21
- baseLabels: metric.base_labels.merge(__name__: metric.name),
22
- docstring: metric.docstring,
23
- metric: {
24
- type: MAPPING[metric.type] || metric.type,
25
- value: metric.values.map { |l, v| { labels: l, value: v } },
26
- },
27
- }
28
- end.to_json
29
- end
30
- end
31
- end
32
- end
33
- end