gruf-prometheus 1.0.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c3aed24d2b55ffbf676b7a27acab6fdcdff134856f294ae1c7b5ffd3f6c39c9
4
- data.tar.gz: d6221023c0bdbe602c00e46433aea36b746bcb5d37f107df92809f0590a6e61e
3
+ metadata.gz: 9125b43ec8d517f1bf324d3d3400f182638f95d74aff3c15aaebdd165ac373da
4
+ data.tar.gz: 25a42e807dd8271ee51b1bf034bdffd604d942a2e4ce431942d7b5442a9aa641
5
5
  SHA512:
6
- metadata.gz: f3df08b6a3032a196bf88999ca838f4a2bc6042913eaa0534ecdc72077ebfc7a0981878b98fcc1cafa847a4b4ba381eb890ad7dc7a2791d96da1dc4f85aefe45
7
- data.tar.gz: d4df8e1ccd75da130d23bd894e6a088005fa7c7c90958b64fca22d486158d92d58df1f0848d2f43fa3fb1aa75c9b98c13dc8f9fdf8c013001335bd4a3471ee84
6
+ metadata.gz: 208c6b8581538e752a792e27677dc28ce6da9169805d823a890848f636588556d526a6bbb0879beda0605133cde09b090226f3f2da85c81867753a090fe2f852
7
+ data.tar.gz: 16278ab75bb295ed885aec4f4d641fc4841db3ecb63782b5bc608db22fe56f7ede66d6ecea3f564ec730b563499053129d73c346531dd0fc2ff70a4716a0a7d4
@@ -2,6 +2,30 @@ Changelog for the gruf-prometheus gem.
2
2
 
3
3
  ### Pending Release
4
4
 
5
+ ### 1.3.0
6
+
7
+ - Drop Ruby < 2.6 support
8
+ - Bump bc-prometheus-ruby dependency to 0.3
9
+ - Adds support for Ruby 2.7
10
+ - Adds help script for testing locally
11
+
12
+ ### 1.2.0
13
+
14
+ - Add the ability to have custom collectors and type collectors
15
+
16
+ ### 1.1.0
17
+
18
+ - Refactor collector/type collector to utilize new base abstractions
19
+ - Bump bc-prometheus-ruby dependency
20
+
21
+ ### 1.0.2
22
+
23
+ - Bump bc-prometheus-ruby dependency
24
+
25
+ ### 1.0.1
26
+
27
+ - Bump bc-prometheus-ruby dependency
28
+
5
29
  ### 1.0.0
6
30
 
7
31
  - *Breaking Changes* Move all prometheus core dependencies to bc-prometheus-ruby
data/README.md CHANGED
@@ -33,6 +33,8 @@ You can further configure via bc-prometheus-ruby with:
33
33
  | process_label | The label to use for metric prefixing | grpc |
34
34
  | process_name | Label to use for process name in logging | grpc |
35
35
  | collection_frequency | The period in seconds in which to collect metrics | 30 |
36
+ | collectors | Any collectors you would like to start with the server. Passed as a hash of collector class => options | {} |
37
+ | type_collectors | Any type collectors you would like to start with the server. Passed as an array of collector objects | [] |
36
38
 
37
39
  ## License
38
40
 
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'gruf-prometheus.gemspec']
33
33
  spec.require_paths = ['lib']
34
+ spec.required_ruby_version = '>= 2.6'
34
35
 
35
36
  spec.add_development_dependency 'rake', '>= 10.0'
36
37
  spec.add_development_dependency 'rspec', '>= 3.8'
@@ -42,5 +43,5 @@ Gem::Specification.new do |spec|
42
43
  spec.add_development_dependency 'pry', '>= 0.12'
43
44
 
44
45
  spec.add_runtime_dependency 'gruf', '>= 2.7'
45
- spec.add_runtime_dependency 'bc-prometheus-ruby', '~> 0.1.3'
46
+ spec.add_runtime_dependency 'bc-prometheus-ruby', '~> 0.3'
46
47
  end
@@ -27,8 +27,8 @@ require 'bigcommerce/prometheus'
27
27
 
28
28
  require_relative 'prometheus/version'
29
29
  require_relative 'prometheus/configuration'
30
- require_relative 'prometheus/collectors/grpc'
31
- require_relative 'prometheus/type_collectors/grpc'
30
+ require_relative 'prometheus/collector'
31
+ require_relative 'prometheus/type_collector'
32
32
  require_relative 'prometheus/hook'
33
33
 
34
34
  module Gruf
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2019-present, BigCommerce Pty. Ltd. All rights reserved
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
+ # Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
+ #
18
+ module Gruf
19
+ module Prometheus
20
+ ##
21
+ # Prometheus instrumentor for gRPC servers
22
+ #
23
+ class Collector < Bigcommerce::Prometheus::Collectors::Base
24
+ def collect(metrics = {})
25
+ metrics[:type] = 'grpc'
26
+ rpc_server = grpc_server
27
+ return metrics unless rpc_server
28
+
29
+ rpc_server.instance_variable_get(:@run_mutex).synchronize do
30
+ collect_server_metrics(rpc_server, metrics)
31
+ end
32
+ metrics
33
+ end
34
+
35
+ ##
36
+ # @param [GRPC::RpcServer] rpc_server
37
+ # @param [Hash] metrics
38
+ #
39
+ def collect_server_metrics(rpc_server, metrics)
40
+ pool = rpc_server.instance_variable_get(:@pool)
41
+ metrics[:pool_jobs_waiting_total] = pool.jobs_waiting.to_i
42
+ metrics[:pool_ready_workers_total] = pool.instance_variable_get(:@ready_workers).size
43
+ metrics[:pool_workers_total] = pool.instance_variable_get(:@workers)&.size
44
+ metrics[:pool_initial_size] = rpc_server.instance_variable_get(:@pool_size).to_i
45
+ metrics[:poll_period] = rpc_server.instance_variable_get(:@poll_period).to_i
46
+ end
47
+
48
+ ##
49
+ # @return [GRPC::RpcServer]
50
+ #
51
+ def grpc_server
52
+ @options.fetch(:server, nil)&.server
53
+ end
54
+ end
55
+ end
56
+ end
@@ -24,7 +24,9 @@ module Gruf
24
24
  VALID_CONFIG_KEYS = {
25
25
  process_label: 'grpc',
26
26
  process_name: 'grpc',
27
- collection_frequency: 30
27
+ collection_frequency: 30,
28
+ type_collectors: [],
29
+ collectors: []
28
30
  }.freeze
29
31
 
30
32
  attr_accessor *VALID_CONFIG_KEYS.keys
@@ -28,8 +28,11 @@ module Gruf
28
28
  #
29
29
  def before_server_start(server:)
30
30
  logger.info "[gruf-prometheus][#{::Gruf::Prometheus.process_name}] Starting #{server.class}"
31
- prometheus_server.add_type_collector(::Gruf::Prometheus::TypeCollectors::Grpc.new)
31
+ prometheus_server.add_type_collector(::Gruf::Prometheus::TypeCollector.new)
32
32
  prometheus_server.add_type_collector(::PrometheusExporter::Server::ActiveRecordCollector.new)
33
+ custom_type_collectors.each do |tc|
34
+ prometheus_server.add_type_collector(tc)
35
+ end
33
36
  prometheus_server.start
34
37
  sleep 2 unless ENV['RACK_ENV'] == 'test' # wait for server to come online
35
38
  start_collectors(server: server)
@@ -58,11 +61,17 @@ module Gruf
58
61
  client: ::Bigcommerce::Prometheus.client,
59
62
  frequency: ::Gruf::Prometheus.collection_frequency
60
63
  )
61
- ::Gruf::Prometheus::Collectors::Grpc.start(
62
- server: server,
64
+ ::Gruf::Prometheus::Collector.start(
65
+ options: {
66
+ server: server
67
+ },
68
+ type: 'grpc',
63
69
  client: ::Bigcommerce::Prometheus.client,
64
70
  frequency: ::Gruf::Prometheus.collection_frequency
65
71
  )
72
+ custom_collectors.each do |collector, arguments|
73
+ collector.start(arguments)
74
+ end
66
75
  end
67
76
 
68
77
  ##
@@ -70,7 +79,7 @@ module Gruf
70
79
  #
71
80
  def stop_collectors
72
81
  ::PrometheusExporter::Instrumentation::Process.stop
73
- ::Gruf::Prometheus::Collectors::Grpc.stop
82
+ ::Gruf::Prometheus::Collector.stop
74
83
  end
75
84
 
76
85
  ##
@@ -85,6 +94,20 @@ module Gruf
85
94
  logger: logger
86
95
  )
87
96
  end
97
+
98
+ ##
99
+ # @return [Array<Bigcommerce::Prometheus::TypeCollectors::Base>]
100
+ #
101
+ def custom_type_collectors
102
+ @options.fetch(:type_collectors, [])
103
+ end
104
+
105
+ ##
106
+ # @return [Array<Bigcommerce::Prometheus::Collectors::Base>]
107
+ #
108
+ def custom_collectors
109
+ @options.fetch(:collectors, [])
110
+ end
88
111
  end
89
112
  end
90
113
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2019-present, BigCommerce Pty. Ltd. All rights reserved
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
+ # Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
+ #
18
+ module Gruf
19
+ module Prometheus
20
+ ##
21
+ # Type Collector for prometheus and grpc instrumentation
22
+ #
23
+ class TypeCollector < Bigcommerce::Prometheus::TypeCollectors::Base
24
+ def type
25
+ 'grpc'
26
+ end
27
+
28
+ private
29
+
30
+ ##
31
+ # Initialize the collector
32
+ #
33
+ def build_metrics
34
+ {
35
+ pool_jobs_waiting_total: PrometheusExporter::Metric::Gauge.new('grpc_pool_jobs_waiting_total', 'Number jobs in the gRPC thread pool that are actively waiting'),
36
+ pool_ready_workers_total: PrometheusExporter::Metric::Gauge.new('grpc_pool_ready_workers_total', 'The amount of non-busy workers in the thread pool'),
37
+ pool_workers_total: PrometheusExporter::Metric::Gauge.new('grpc_pool_workers_total', 'Number of workers in the gRPC thread pool'),
38
+ pool_initial_size: PrometheusExporter::Metric::Gauge.new('grpc_pool_initial_size', 'Initial size of the gRPC thread pool'),
39
+ poll_period: PrometheusExporter::Metric::Gauge.new('grpc_poll_period', 'Polling period for the gRPC thread pool'),
40
+ thread_pool_exhausted: PrometheusExporter::Metric::Counter.new('grpc_thread_pool_exhausted', 'Times the gRPC thread pool has been exhausted')
41
+ }
42
+ end
43
+
44
+ ##
45
+ # Collect the object into the buffer
46
+ #
47
+ def collect_metrics(data: {}, labels: {})
48
+ metric(:pool_jobs_waiting_total)&.observe(data['pool_jobs_waiting_total'].to_i, labels)
49
+ metric(:pool_ready_workers_total)&.observe(data['pool_ready_workers_total'].to_i, labels)
50
+ metric(:pool_workers_total)&.observe(data['pool_workers_total'].to_i, labels)
51
+ metric(:pool_initial_size)&.observe(data['pool_initial_size'].to_i, labels)
52
+ metric(:poll_period)&.observe(data['poll_period'].to_i, labels)
53
+ metric(:thread_pool_exhausted)&.observe(data['thread_pool_exhausted'].to_i, labels)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -17,6 +17,6 @@
17
17
  #
18
18
  module Gruf
19
19
  module Prometheus
20
- VERSION = '1.0.0'
20
+ VERSION = '1.3.0'
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf-prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2020-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 0.1.3
145
+ version: '0.3'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 0.1.3
152
+ version: '0.3'
153
153
  description: Prometheus support for gruf
154
154
  email:
155
155
  - shaun.mccormick@bigcommerce.com
@@ -162,16 +162,16 @@ files:
162
162
  - README.md
163
163
  - gruf-prometheus.gemspec
164
164
  - lib/gruf/prometheus.rb
165
- - lib/gruf/prometheus/collectors/grpc.rb
165
+ - lib/gruf/prometheus/collector.rb
166
166
  - lib/gruf/prometheus/configuration.rb
167
167
  - lib/gruf/prometheus/hook.rb
168
- - lib/gruf/prometheus/type_collectors/grpc.rb
168
+ - lib/gruf/prometheus/type_collector.rb
169
169
  - lib/gruf/prometheus/version.rb
170
170
  homepage: https://github.com/bigcommerce/gruf-prometheus
171
171
  licenses:
172
172
  - MIT
173
173
  metadata: {}
174
- post_install_message:
174
+ post_install_message:
175
175
  rdoc_options: []
176
176
  require_paths:
177
177
  - lib
@@ -179,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
179
  requirements:
180
180
  - - ">="
181
181
  - !ruby/object:Gem::Version
182
- version: '0'
182
+ version: '2.6'
183
183
  required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  requirements: []
189
189
  rubygems_version: 3.0.6
190
- signing_key:
190
+ signing_key:
191
191
  specification_version: 4
192
192
  summary: Prometheus support for gruf
193
193
  test_files: []
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2019-present, BigCommerce Pty. Ltd. All rights reserved
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
- # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7
- # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8
- # persons to whom the Software is furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
- # Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
- # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
- # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
- #
18
- module Gruf
19
- module Prometheus
20
- module Collectors
21
- ##
22
- # Prometheus instrumentor for gRPC servers
23
- #
24
- class Grpc
25
- include Gruf::Loggable
26
-
27
- ##
28
- # @param [Gruf::Server] server
29
- # @param [Gruf::Prometheus::Client] client
30
- # @param [Integer] frequency
31
- #
32
- def initialize(server:, client:, frequency: nil)
33
- @server = server
34
- @client = client
35
- @frequency = frequency || 15
36
- end
37
-
38
- ##
39
- # Start the collector
40
- #
41
- # @param [Gruf::Server] server
42
- # @param [Gruf::Prometheus::Client] client
43
- # @param [Integer] frequency
44
- #
45
- def self.start(server:, client: nil, frequency: nil)
46
- stop if @thread
47
-
48
- client ||= Bigcommerce::Prometheus::Client.instance
49
- collector = new(server: server, client: client, frequency: frequency)
50
- @thread = Thread.new do
51
- loop do
52
- collector.run
53
- end
54
- end
55
- end
56
-
57
- ##
58
- # Stop the collector
59
- #
60
- def self.stop
61
- t = @thread
62
- return unless t
63
-
64
- t.kill
65
- @thread = nil
66
- end
67
-
68
- def run
69
- metric = collect
70
- logger.debug "[gruf-prometheus] Pushing gruf metrics to type collector: #{metric.inspect}"
71
- @client.send_json metric
72
- rescue StandardError => e
73
- logger.error "[gruf-prometheus] Failed to collect gruf-prometheus stats: #{e.message}"
74
- ensure
75
- sleep @frequency
76
- end
77
-
78
- private
79
-
80
- def collect
81
- metric = {}
82
- metric[:type] = 'grpc'
83
- rpc_server = @server.server
84
- rpc_server.instance_variable_get(:@run_mutex).synchronize do
85
- collect_server_metrics(rpc_server, metric)
86
- end
87
- metric
88
- end
89
-
90
- ##
91
- # @param [GRPC::RpcServer] rpc_server
92
- #
93
- def collect_server_metrics(rpc_server, metric)
94
- pool = rpc_server.instance_variable_get(:@pool)
95
- metric[:pool_jobs_waiting_total] = pool.jobs_waiting.to_i
96
- metric[:pool_ready_workers_total] = pool.instance_variable_get(:@ready_workers).size
97
- metric[:pool_workers_total] = pool.instance_variable_get(:@workers)&.size
98
- metric[:pool_initial_size] = rpc_server.instance_variable_get(:@pool_size).to_i
99
- metric[:poll_period] = rpc_server.instance_variable_get(:@poll_period).to_i
100
- end
101
-
102
- ##
103
- # @return [GRPC::RpcServer]
104
- #
105
- def grpc_server
106
- @server.server
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2019-present, BigCommerce Pty. Ltd. All rights reserved
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
- # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7
- # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8
- # persons to whom the Software is furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
- # Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
- # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
- # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
- #
18
- module Gruf
19
- module Prometheus
20
- module TypeCollectors
21
- ##
22
- # Type Collector for prometheus and grpc instrumentation
23
- #
24
- class Grpc < PrometheusExporter::Server::TypeCollector
25
- ##
26
- # Initialize the collector
27
- #
28
- def initialize
29
- @pool_jobs_waiting_total = PrometheusExporter::Metric::Gauge.new('grpc_pool_jobs_waiting_total', 'Number jobs in the gRPC thread pool that are actively waiting')
30
- @pool_ready_workers_total = PrometheusExporter::Metric::Gauge.new('grpc_pool_ready_workers_total', 'The amount of non-busy workers in the thread pool')
31
- @pool_workers_total = PrometheusExporter::Metric::Gauge.new('grpc_pool_workers_total', 'Number of workers in the gRPC thread pool')
32
- @pool_initial_size = PrometheusExporter::Metric::Gauge.new('grpc_pool_initial_size', 'Initial size of the gRPC thread pool')
33
- @poll_period = PrometheusExporter::Metric::Gauge.new('grpc_poll_period', 'Polling period for the gRPC thread pool')
34
- @thread_pool_exhausted = PrometheusExporter::Metric::Counter.new('grpc_thread_pool_exhausted', 'Times the gRPC thread pool has been exhausted')
35
- end
36
-
37
- ##
38
- # @return [String]
39
- #
40
- def type
41
- 'grpc'
42
- end
43
-
44
- ##
45
- # @return [Array]
46
- #
47
- def metrics
48
- return [] unless @pool_jobs_waiting_total
49
-
50
- [
51
- @pool_jobs_waiting_total,
52
- @pool_ready_workers_total,
53
- @pool_workers_total,
54
- @pool_initial_size,
55
- @poll_period,
56
- @thread_pool_exhausted
57
- ]
58
- end
59
-
60
- ##
61
- # Collect the object into the buffer
62
- #
63
- def collect(obj)
64
- default_labels = {}
65
- default_labels['environment'] = obj['environment'] if obj['environment']
66
-
67
- custom_labels = obj['custom_labels'] || {}
68
- labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)
69
-
70
- @pool_jobs_waiting_total.observe(obj['pool_jobs_waiting_total'].to_i, labels)
71
- @pool_ready_workers_total.observe(obj['pool_ready_workers_total'].to_i, labels)
72
- @pool_workers_total.observe(obj['pool_workers_total'].to_i, labels)
73
- @pool_initial_size.observe(obj['pool_initial_size'].to_i, labels)
74
- @poll_period.observe(obj['poll_period'].to_i, labels)
75
- @thread_pool_exhausted.observe(obj['thread_pool_exhausted'].to_i, labels)
76
- end
77
- end
78
- end
79
- end
80
- end