bc-prometheus-ruby 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +11 -10
- data/bc-prometheus-ruby.gemspec +5 -5
- data/lib/bigcommerce/prometheus.rb +3 -0
- data/lib/bigcommerce/prometheus/client.rb +8 -0
- data/lib/bigcommerce/prometheus/configuration.rb +4 -2
- data/lib/bigcommerce/prometheus/server.rb +10 -4
- data/lib/bigcommerce/prometheus/servers/thin/controllers/send_metrics_controller.rb +1 -0
- data/lib/bigcommerce/prometheus/servers/thin/server.rb +2 -1
- data/lib/bigcommerce/prometheus/servers/thin/server_metrics.rb +1 -1
- data/lib/bigcommerce/prometheus/type_collectors/base.rb +1 -0
- data/lib/bigcommerce/prometheus/type_collectors/resque.rb +2 -0
- data/lib/bigcommerce/prometheus/version.rb +1 -1
- metadata +23 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de359169baf99c96908a67831d9a5142db365714798b31578ab9dd2ab11b18cf
|
4
|
+
data.tar.gz: f34aa10e6c1052f6671baee6d9e1fcdcd88f67f74f1e02345d31e18339ede799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19570ec1281b97b652eacf07f5cbe1669e17cc244e1468c0d5134b19dcbc4bc1dd4aabaf916ef94f85da1ef5f05dd0d430b1c84278962aee8a18d7d553703fa9
|
7
|
+
data.tar.gz: 5632f7e03d4b913c71fe5835b8b2e16b5fd35f86246787d9a3f99d32da27fe2fa229db4ccf479540bcbbe04835d54a8ba9f834170e8e209c464993273a6c97bb
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@ Changelog for the bc-prometheus-ruby gem.
|
|
2
2
|
|
3
3
|
### Pending Release
|
4
4
|
|
5
|
+
### 0.4.0
|
6
|
+
|
7
|
+
- Add configuration to control Thin web server thread pool size. Note that the default number of threads is changing from 20 to 3. You can configure this using an environment variable or initializer.
|
8
|
+
- Update rubocop to 1.0
|
9
|
+
|
5
10
|
### 0.3.1
|
6
11
|
|
7
12
|
- Update prometheus_exporter dependency to ~> 0.5 to fix memory leaks
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# bc-prometheus-ruby - Drop-in Prometheus metrics
|
2
2
|
|
3
|
-
[![CircleCI](https://circleci.com/gh/bigcommerce/bc-prometheus-ruby.svg?style=svg&circle-token=fc3e2c4405a1f53a31e298f0ef981c2d0dfdee90)](https://circleci.com/gh/bigcommerce/bc-prometheus-ruby) [![Gem Version](https://badge.fury.io/rb/bc-prometheus-ruby.svg)](https://badge.fury.io/rb/bc-prometheus-ruby) [![Documentation](https://inch-ci.org/github/bigcommerce/bc-prometheus-ruby.svg?branch=
|
3
|
+
[![CircleCI](https://circleci.com/gh/bigcommerce/bc-prometheus-ruby.svg?style=svg&circle-token=fc3e2c4405a1f53a31e298f0ef981c2d0dfdee90)](https://circleci.com/gh/bigcommerce/bc-prometheus-ruby) [![Gem Version](https://badge.fury.io/rb/bc-prometheus-ruby.svg)](https://badge.fury.io/rb/bc-prometheus-ruby) [![Documentation](https://inch-ci.org/github/bigcommerce/bc-prometheus-ruby.svg?branch=main)](https://inch-ci.org/github/bigcommerce/bc-prometheus-ruby?branch=main)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -39,15 +39,16 @@ Bigcommerce::Prometheus::Instrumentors::Resque.new(app: Rails.application).start
|
|
39
39
|
|
40
40
|
After requiring the main file, you can further configure with:
|
41
41
|
|
42
|
-
| Option | Description | Default |
|
43
|
-
| ------ | ----------- | ------- |
|
44
|
-
| client_custom_labels | A hash of custom labels to send with each client request | `{}` |
|
45
|
-
| client_max_queue_size | The max amount of metrics to send before flushing | 10000 |
|
46
|
-
| client_thread_sleep | How often to sleep the worker thread that manages the client buffer (seconds) | 0.5 |
|
47
|
-
| puma_collection_frequency | How often to poll puma collection metrics (seconds) | 30 |
|
48
|
-
| server_host | The host to run the exporter on | 0.0.0.0 |
|
49
|
-
| server_port | The port to run the exporter on | 9394 |
|
50
|
-
|
|
42
|
+
| Option | Description | Default | Environment Variable |
|
43
|
+
| ------ | ----------- | ------- | -------------------- |
|
44
|
+
| client_custom_labels | A hash of custom labels to send with each client request | `{}` | None |
|
45
|
+
| client_max_queue_size | The max amount of metrics to send before flushing | `10000` | `ENV['PROMETHEUS_CLIENT_MAX_QUEUE_SIZE']` |
|
46
|
+
| client_thread_sleep | How often to sleep the worker thread that manages the client buffer (seconds) | `0.5` | `ENV['PROMETHEUS_CLIENT_THREAD_SLEEP']` |
|
47
|
+
| puma_collection_frequency | How often to poll puma collection metrics (seconds) | `30` | `ENV['PROMETHEUS_PUMA_COLLECTION_FREQUENCY']` |
|
48
|
+
| server_host | The host to run the exporter on | `"0.0.0.0"` | `ENV['PROMETHEUS_SERVER_HOST']` |
|
49
|
+
| server_port | The port to run the exporter on | `9394` | `ENV['PROMETHEUS_SERVER_PORT']` |
|
50
|
+
| server_thread_pool_size | The number of threads used for the exporter server | `3` | `ENV['PROMETHEUS_SERVER_THREAD_POOL_SIZE']` |
|
51
|
+
| process_name | What the current process name is (used in logging) | `"unknown"` | `ENV['PROCESS']` |
|
51
52
|
|
52
53
|
## Custom Collectors
|
53
54
|
|
data/bc-prometheus-ruby.gemspec
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
16
16
|
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
17
|
#
|
18
|
-
|
18
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
19
19
|
require 'bigcommerce/prometheus/version'
|
20
20
|
|
21
21
|
Gem::Specification.new do |spec|
|
@@ -33,13 +33,13 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.require_paths = ['lib']
|
34
34
|
spec.required_ruby_version = '>= 2.6'
|
35
35
|
|
36
|
-
spec.add_development_dependency 'rake', '>= 10.0'
|
37
|
-
spec.add_development_dependency 'rspec', '>= 3.8'
|
38
|
-
spec.add_development_dependency 'rspec_junit_formatter', '>= 0.4'
|
39
36
|
spec.add_development_dependency 'bundler-audit', '>= 0.6'
|
40
37
|
spec.add_development_dependency 'null-logger', '>= 0.1'
|
41
38
|
spec.add_development_dependency 'pry', '>= 0.12'
|
42
|
-
spec.add_development_dependency '
|
39
|
+
spec.add_development_dependency 'rake', '>= 10.0'
|
40
|
+
spec.add_development_dependency 'rspec', '>= 3.8'
|
41
|
+
spec.add_development_dependency 'rspec_junit_formatter', '>= 0.4'
|
42
|
+
spec.add_development_dependency 'rubocop', '>= 1.0'
|
43
43
|
spec.add_development_dependency 'simplecov', '>= 0.16'
|
44
44
|
|
45
45
|
spec.add_runtime_dependency 'bigcommerce-multitrap', '~> 0.1'
|
@@ -24,6 +24,14 @@ module Bigcommerce
|
|
24
24
|
include Singleton
|
25
25
|
include Loggable
|
26
26
|
|
27
|
+
##
|
28
|
+
# @param [String] host
|
29
|
+
# @param [Integer] port
|
30
|
+
# @param [Integer] max_queue_size
|
31
|
+
# @param [Integer|Float] thread_sleep
|
32
|
+
# @param [Hash] custom_labels
|
33
|
+
# @param [String] process_name
|
34
|
+
#
|
27
35
|
def initialize(host: nil, port: nil, max_queue_size: nil, thread_sleep: nil, custom_labels: nil, process_name: nil)
|
28
36
|
super(
|
29
37
|
host: host || Bigcommerce::Prometheus.server_host,
|
@@ -42,6 +42,7 @@ module Bigcommerce
|
|
42
42
|
server_port: ENV.fetch('PROMETHEUS_SERVER_PORT', PrometheusExporter::DEFAULT_PORT).to_i,
|
43
43
|
server_timeout: ENV.fetch('PROMETHEUS_DEFAULT_TIMEOUT', PrometheusExporter::DEFAULT_TIMEOUT).to_i,
|
44
44
|
server_prefix: ENV.fetch('PROMETHEUS_DEFAULT_PREFIX', PrometheusExporter::DEFAULT_PREFIX).to_s,
|
45
|
+
server_thread_pool_size: ENV.fetch('PROMETHEUS_SERVER_THREAD_POOL_SIZE', 3).to_i,
|
45
46
|
|
46
47
|
# Custom collector configuration
|
47
48
|
collector_collection_frequency: ENV.fetch('PROMETHEUS_DEFAULT_COLLECTOR_COLLECTION_FREQUENCY_SEC', 15).to_i,
|
@@ -76,6 +77,7 @@ module Bigcommerce
|
|
76
77
|
reset unless @configured
|
77
78
|
yield self
|
78
79
|
@configured = true
|
80
|
+
self
|
79
81
|
end
|
80
82
|
|
81
83
|
##
|
@@ -118,8 +120,8 @@ module Bigcommerce
|
|
118
120
|
self.logger = Application.logger
|
119
121
|
else
|
120
122
|
require 'logger'
|
121
|
-
self.logger = ::Logger.new(
|
122
|
-
|
123
|
+
self.logger = ::Logger.new($stdout)
|
124
|
+
logger.level = ::Logger::Severity::INFO
|
123
125
|
end
|
124
126
|
end
|
125
127
|
|
@@ -26,15 +26,21 @@ module Bigcommerce
|
|
26
26
|
# @param [Integer] port
|
27
27
|
# @param [Integer] timeout
|
28
28
|
# @param [String] prefix
|
29
|
+
# @param [Integer] thread_pool_size
|
29
30
|
#
|
30
|
-
def initialize(host: nil, port: nil, timeout: nil, prefix: nil, logger: nil)
|
31
|
+
def initialize(host: nil, port: nil, timeout: nil, prefix: nil, logger: nil, thread_pool_size: nil)
|
31
32
|
@host = host || ::Bigcommerce::Prometheus.server_host
|
32
33
|
@port = (port || ::Bigcommerce::Prometheus.server_port).to_i
|
33
34
|
@timeout = (timeout || ::Bigcommerce::Prometheus.server_timeout).to_i
|
34
35
|
@prefix = (prefix || ::PrometheusExporter::DEFAULT_PREFIX).to_s
|
35
36
|
@process_name = ::Bigcommerce::Prometheus.process_name
|
36
37
|
@logger = logger || ::Bigcommerce::Prometheus.logger
|
37
|
-
@server = ::Bigcommerce::Prometheus::Servers::Thin::Server.new(
|
38
|
+
@server = ::Bigcommerce::Prometheus::Servers::Thin::Server.new(
|
39
|
+
port: @port,
|
40
|
+
timeout: @timeout,
|
41
|
+
logger: @logger,
|
42
|
+
thread_pool_size: (thread_pool_size || ::Bigcommerce::Prometheus.server_thread_pool_size).to_i
|
43
|
+
)
|
38
44
|
@running = false
|
39
45
|
::PrometheusExporter::Metric::Base.default_prefix = @prefix
|
40
46
|
setup_signal_handlers
|
@@ -51,7 +57,7 @@ module Bigcommerce
|
|
51
57
|
end
|
52
58
|
@running = true
|
53
59
|
|
54
|
-
@logger.info "[bigcommerce-prometheus][#{@process_name}] Prometheus exporter started on #{@host}:#{@port}"
|
60
|
+
@logger.info "[bigcommerce-prometheus][#{@process_name}] Prometheus exporter started on #{@host}:#{@port} with #{@server.threadpool_size} threads"
|
55
61
|
|
56
62
|
@server
|
57
63
|
rescue ::StandardError => e
|
@@ -78,7 +84,7 @@ module Bigcommerce
|
|
78
84
|
@server.stop!
|
79
85
|
@run_thread.kill
|
80
86
|
@running = false
|
81
|
-
|
87
|
+
$stdout.puts "[bigcommerce-prometheus][#{@process_name}] Prometheus exporter cleanly shut down"
|
82
88
|
rescue ::StandardError => e
|
83
89
|
warn "[bigcommerce-prometheus][#{@process_name}] Failed to stop exporter: #{e.message}"
|
84
90
|
end
|
@@ -23,7 +23,7 @@ module Bigcommerce
|
|
23
23
|
# Thin adapter for server
|
24
24
|
#
|
25
25
|
class Server < ::Thin::Server
|
26
|
-
def initialize(port
|
26
|
+
def initialize(port: nil, host: nil, timeout: nil, logger: nil, thread_pool_size: nil)
|
27
27
|
@port = port || ::Bigcommerce::Prometheus.server_port
|
28
28
|
@host = host || ::Bigcommerce::Prometheus.server_host
|
29
29
|
@timeout = timeout || ::Bigcommerce::Prometheus.server_timeout
|
@@ -31,6 +31,7 @@ module Bigcommerce
|
|
31
31
|
@rack_app = ::Bigcommerce::Prometheus::Servers::Thin::RackApp.new(timeout: timeout, logger: logger)
|
32
32
|
super(@host, @port, @rack_app)
|
33
33
|
::Thin::Logging.logger = @logger
|
34
|
+
self.threadpool_size = (thread_pool_size || ::Bigcommerce::Prometheus.server_thread_pool_size).to_i
|
34
35
|
end
|
35
36
|
|
36
37
|
##
|
@@ -35,7 +35,7 @@ module Bigcommerce
|
|
35
35
|
@metrics_total = ::PrometheusExporter::Metric::Counter.new('collector_metrics_total', 'Total metrics processed by exporter.')
|
36
36
|
@sessions_total = ::PrometheusExporter::Metric::Counter.new('collector_sessions_total', 'Total send_metric sessions processed by exporter.')
|
37
37
|
@bad_metrics_total = ::PrometheusExporter::Metric::Counter.new('collector_bad_metrics_total', 'Total mis-handled metrics by collector.')
|
38
|
-
@collector_working_gauge = ::PrometheusExporter::Metric::Gauge.new('collector_working', 'Is the
|
38
|
+
@collector_working_gauge = ::PrometheusExporter::Metric::Gauge.new('collector_working', 'Is the main process collector able to collect metrics')
|
39
39
|
@collector_rss_gauge = ::PrometheusExporter::Metric::Gauge.new('collector_rss', 'total memory used by collector process')
|
40
40
|
end
|
41
41
|
|
@@ -29,6 +29,7 @@ module Bigcommerce
|
|
29
29
|
# @param [Hash] default_labels
|
30
30
|
#
|
31
31
|
def initialize(type: nil, default_labels: {})
|
32
|
+
super()
|
32
33
|
@type = type || self.class.to_s.downcase.gsub('::', '_').gsub('typecollector', '')
|
33
34
|
@default_labels = default_labels || {}
|
34
35
|
@metrics = build_metrics
|
metadata
CHANGED
@@ -1,113 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bc-prometheus-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shaun McCormick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler-audit
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: null-logger
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.12'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.12'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '10.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
68
|
+
version: '10.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.8'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3.8'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rspec_junit_formatter
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.4'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.4'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0
|
103
|
+
version: '1.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0
|
110
|
+
version: '1.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
- !ruby/object:Gem::Version
|
219
219
|
version: '0'
|
220
220
|
requirements: []
|
221
|
-
rubygems_version: 3.0.
|
221
|
+
rubygems_version: 3.0.9
|
222
222
|
signing_key:
|
223
223
|
specification_version: 4
|
224
224
|
summary: Simple integration of ruby and puma servers with prometheus
|