puma-metrics 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +10 -0
- data/.github/workflows/workflow.yml +41 -0
- data/.rubocop.yml +3 -1
- data/CHANGELOG.md +35 -0
- data/Gemfile.lock +29 -28
- data/Rakefile +2 -0
- data/lib/puma/metrics/app.rb +12 -1
- data/lib/puma/metrics/dsl.rb +3 -1
- data/lib/puma/metrics/parser.rb +33 -13
- data/lib/puma/metrics/version.rb +3 -1
- data/lib/puma/plugin/metrics.rb +9 -2
- data/puma-metrics.gemspec +4 -2
- metadata +11 -11
- data/.travis.yml +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6bfb3829a8b3f020867676ad2d06696602f9b3e9cdba9677c9d0cd96516d952
|
4
|
+
data.tar.gz: 9b22b853444c9f8eb9945582e6debd9676c0ac83487178fe056840c8cb438b96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79d9e90b3dc95a9508622a6142a044dd682b072dcfd3971a2bfa06b5651ba414b2dd1667be0896779ae9a08be677d9607db2e0f6e3ba2f7417581c59e4be0b37
|
7
|
+
data.tar.gz: 38a134598cb7f50faded591f745832423aedcc9b4c7589a796ff25a67479104348675bc2e6dea82e2f08b440ba54616fc1d81951038aa6a6195cd922d84313e7
|
data/.editorconfig
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
name: steps
|
2
|
+
on: [push]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
name: test on ruby ${{ matrix.ruby }}
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
steps:
|
8
|
+
- uses: actions/checkout@master
|
9
|
+
- uses: actions/setup-ruby@master
|
10
|
+
with:
|
11
|
+
ruby-version: ${{ matrix.ruby }}
|
12
|
+
- run: gem install bundler
|
13
|
+
- run: bundle install
|
14
|
+
- run: bundle exec rake
|
15
|
+
- run: bundle exec overcommit --sign
|
16
|
+
- env:
|
17
|
+
GIT_AUTHOR_NAME: John Doe
|
18
|
+
GIT_AUTHOR_EMAIL: johndoe@example.com
|
19
|
+
run: bundle exec overcommit --run
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby: ['2.5', '2.5', '2.7']
|
23
|
+
deploy:
|
24
|
+
if: github.ref == 'refs/heads/master'
|
25
|
+
name: to rubygems
|
26
|
+
needs: test
|
27
|
+
runs-on: ubuntu-latest
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@master
|
30
|
+
- uses: actions/setup-ruby@master
|
31
|
+
with:
|
32
|
+
ruby-version: 2.7
|
33
|
+
- env:
|
34
|
+
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
35
|
+
run: |
|
36
|
+
mkdir -p $HOME/.gem
|
37
|
+
touch $HOME/.gem/credentials
|
38
|
+
chmod 0600 $HOME/.gem/credentials
|
39
|
+
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
|
40
|
+
gem build *.gemspec
|
41
|
+
gem push *.gem
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.6
|
3
3
|
|
4
4
|
Naming/FileName:
|
5
5
|
Exclude:
|
@@ -10,6 +10,8 @@ Metrics/LineLength:
|
|
10
10
|
|
11
11
|
Style/Documentation:
|
12
12
|
Enabled: false
|
13
|
+
Style/NumericPredicate:
|
14
|
+
Enabled: false
|
13
15
|
Style/MethodMissingSuper:
|
14
16
|
Exclude:
|
15
17
|
- lib/puma/metrics/parser.rb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,40 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
## 1.2.0
|
6
|
+
|
7
|
+
Changes:
|
8
|
+
- Drop support for ruby 2.4
|
9
|
+
- Relax prometheus-client to '>= 0.10'
|
10
|
+
|
11
|
+
Housekeeping:
|
12
|
+
- Update development dependencies
|
13
|
+
|
14
|
+
## 1.1.0
|
15
|
+
|
16
|
+
Changes:
|
17
|
+
- Upgrade prometheus-client to '~> 0.10'
|
18
|
+
|
19
|
+
Housekeeping:
|
20
|
+
- Set target version to 2.6
|
21
|
+
- Added editorconfig
|
22
|
+
|
23
|
+
## 1.0.3
|
24
|
+
|
25
|
+
Features:
|
26
|
+
- can be used with puma 3 or puma 4
|
27
|
+
|
28
|
+
## 1.0.2
|
29
|
+
|
30
|
+
Bugfixes:
|
31
|
+
- terminate metrics server without IO errors [#7](https://github.com/harmjanblok/puma-metrics/pull/7)
|
32
|
+
|
33
|
+
## 1.0.1
|
34
|
+
|
35
|
+
Bugfixes:
|
36
|
+
- `metrics_url` in `config/puma.rb` should be optional
|
37
|
+
|
3
38
|
## 1.0.0
|
4
39
|
|
5
40
|
Initial release of the `puma-metrics` gem.
|
data/Gemfile.lock
CHANGED
@@ -1,43 +1,44 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
puma-metrics (1.
|
5
|
-
prometheus-client (
|
6
|
-
puma (
|
4
|
+
puma-metrics (1.2.0)
|
5
|
+
prometheus-client (>= 0.10)
|
6
|
+
puma (>= 3.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
ast (2.4.
|
12
|
-
childprocess (0.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
overcommit (0.46.0)
|
19
|
-
childprocess (~> 0.6, >= 0.6.3)
|
11
|
+
ast (2.4.1)
|
12
|
+
childprocess (3.0.0)
|
13
|
+
iniparse (1.5.0)
|
14
|
+
minitest (5.14.1)
|
15
|
+
nio4r (2.5.2)
|
16
|
+
overcommit (0.53.0)
|
17
|
+
childprocess (>= 0.6.3, < 4)
|
20
18
|
iniparse (~> 1.4)
|
21
|
-
parallel (1.
|
22
|
-
parser (2.
|
19
|
+
parallel (1.19.1)
|
20
|
+
parser (2.7.1.3)
|
23
21
|
ast (~> 2.4.0)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
puma (3.12.0)
|
28
|
-
quantile (0.2.1)
|
22
|
+
prometheus-client (2.0.0)
|
23
|
+
puma (4.3.5)
|
24
|
+
nio4r (~> 2.0)
|
29
25
|
rainbow (3.0.0)
|
30
|
-
rake (
|
31
|
-
|
32
|
-
|
26
|
+
rake (13.0.1)
|
27
|
+
regexp_parser (1.7.1)
|
28
|
+
rexml (3.2.4)
|
29
|
+
rubocop (0.85.1)
|
33
30
|
parallel (~> 1.10)
|
34
|
-
parser (>= 2.
|
35
|
-
powerpack (~> 0.1)
|
31
|
+
parser (>= 2.7.0.1)
|
36
32
|
rainbow (>= 2.2.2, < 4.0)
|
33
|
+
regexp_parser (>= 1.7)
|
34
|
+
rexml
|
35
|
+
rubocop-ast (>= 0.0.3)
|
37
36
|
ruby-progressbar (~> 1.7)
|
38
|
-
unicode-display_width (
|
39
|
-
|
40
|
-
|
37
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
38
|
+
rubocop-ast (0.0.3)
|
39
|
+
parser (>= 2.7.0.1)
|
40
|
+
ruby-progressbar (1.10.1)
|
41
|
+
unicode-display_width (1.7.0)
|
41
42
|
|
42
43
|
PLATFORMS
|
43
44
|
ruby
|
@@ -51,4 +52,4 @@ DEPENDENCIES
|
|
51
52
|
rubocop
|
52
53
|
|
53
54
|
BUNDLED WITH
|
54
|
-
1.
|
55
|
+
2.1.2
|
data/Rakefile
CHANGED
data/lib/puma/metrics/app.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require 'prometheus/client/formats/text'
|
3
5
|
require 'puma/metrics/parser'
|
@@ -12,13 +14,22 @@ module Puma
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def call(_env)
|
15
|
-
|
17
|
+
retrieve_and_parse_stats!
|
16
18
|
[
|
17
19
|
200,
|
18
20
|
{ 'Content-Type' => 'text/plain' },
|
19
21
|
[Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)]
|
20
22
|
]
|
21
23
|
end
|
24
|
+
|
25
|
+
def retrieve_and_parse_stats!
|
26
|
+
puma_stats = @launcher.stats
|
27
|
+
if puma_stats.is_a?(Hash) # Modern Puma outputs stats as a Symbol-keyed Hash
|
28
|
+
@parser.parse(puma_stats)
|
29
|
+
else
|
30
|
+
@parser.parse(JSON.parse(puma_stats, symbolize_names: true))
|
31
|
+
end
|
32
|
+
end
|
22
33
|
end
|
23
34
|
end
|
24
35
|
end
|
data/lib/puma/metrics/dsl.rb
CHANGED
data/lib/puma/metrics/parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'prometheus/client'
|
2
4
|
|
3
5
|
module Puma
|
@@ -8,10 +10,10 @@ module Puma
|
|
8
10
|
register_clustered_metrics if clustered
|
9
11
|
end
|
10
12
|
|
11
|
-
def parse(
|
12
|
-
|
13
|
-
value.each { |s| parse(s, labels.merge(index: s[
|
14
|
-
parse(value, labels) if key ==
|
13
|
+
def parse(symbol_keyed_stats, labels = {})
|
14
|
+
symbol_keyed_stats.each do |key, value|
|
15
|
+
value.each { |s| parse(s, labels.merge(index: s[:index])) } if key == :worker_status
|
16
|
+
parse(value, labels) if key == :last_status
|
15
17
|
update_metric(key, value, labels)
|
16
18
|
end
|
17
19
|
end
|
@@ -19,16 +21,34 @@ module Puma
|
|
19
21
|
private
|
20
22
|
|
21
23
|
def register_clustered_metrics
|
22
|
-
registry.gauge(:puma_booted_workers,
|
23
|
-
|
24
|
+
registry.gauge(:puma_booted_workers,
|
25
|
+
docstring: 'Number of booted workers')
|
26
|
+
.set(1)
|
27
|
+
registry.gauge(:puma_old_workers,
|
28
|
+
docstring: 'Number of old workers')
|
29
|
+
.set(0)
|
24
30
|
end
|
25
31
|
|
26
|
-
def register_default_metrics
|
27
|
-
registry.gauge(:puma_backlog,
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
registry.gauge(:
|
32
|
+
def register_default_metrics # rubocop:disable Metrics/MethodLength
|
33
|
+
registry.gauge(:puma_backlog,
|
34
|
+
docstring: 'Number of established but unaccepted connections in the backlog',
|
35
|
+
labels: [:index],
|
36
|
+
preset_labels: { index: 0 })
|
37
|
+
registry.gauge(:puma_running,
|
38
|
+
docstring: 'Number of running worker threads',
|
39
|
+
labels: [:index],
|
40
|
+
preset_labels: { index: 0 })
|
41
|
+
registry.gauge(:puma_pool_capacity,
|
42
|
+
docstring: 'Number of allocatable worker threads',
|
43
|
+
labels: [:index],
|
44
|
+
preset_labels: { index: 0 })
|
45
|
+
registry.gauge(:puma_max_threads,
|
46
|
+
docstring: 'Maximum number of worker threads',
|
47
|
+
labels: [:index],
|
48
|
+
preset_labels: { index: 0 })
|
49
|
+
registry.gauge(:puma_workers,
|
50
|
+
docstring: 'Number of configured workers')
|
51
|
+
.set(1)
|
32
52
|
end
|
33
53
|
|
34
54
|
def registry
|
@@ -38,7 +58,7 @@ module Puma
|
|
38
58
|
def update_metric(key, value, labels)
|
39
59
|
return if registry.get("puma_#{key}").nil?
|
40
60
|
|
41
|
-
registry.get("puma_#{key}").set(
|
61
|
+
registry.get("puma_#{key}").set(value, labels: labels)
|
42
62
|
end
|
43
63
|
end
|
44
64
|
end
|
data/lib/puma/metrics/version.rb
CHANGED
data/lib/puma/plugin/metrics.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puma/metrics/dsl'
|
2
4
|
|
3
5
|
Puma::Plugin.create do
|
4
6
|
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
5
7
|
def start(launcher)
|
6
|
-
str = launcher.options[:metrics_url]
|
7
|
-
return unless str
|
8
|
+
str = launcher.options[:metrics_url] || 'tcp://0.0.0.0:9393'
|
8
9
|
|
9
10
|
require 'puma/metrics/app'
|
10
11
|
|
@@ -23,6 +24,12 @@ Puma::Plugin.create do
|
|
23
24
|
launcher.events.error "Invalid control URI: #{str}"
|
24
25
|
end
|
25
26
|
|
27
|
+
launcher.events.register(:state) do |state|
|
28
|
+
if %i[halt restart stop].include?(state)
|
29
|
+
metrics.stop(true) unless metrics.shutting_down?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
26
33
|
metrics.run
|
27
34
|
end
|
28
35
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
data/puma-metrics.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
|
@@ -15,8 +17,8 @@ Gem::Specification.new do |spec|
|
|
15
17
|
|
16
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
19
|
|
18
|
-
spec.add_runtime_dependency 'prometheus-client', '
|
19
|
-
spec.add_runtime_dependency 'puma', '
|
20
|
+
spec.add_runtime_dependency 'prometheus-client', '>= 0.10'
|
21
|
+
spec.add_runtime_dependency 'puma', '>= 3.0'
|
20
22
|
|
21
23
|
spec.add_development_dependency 'bundler'
|
22
24
|
spec.add_development_dependency 'minitest'
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puma-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harm-Jan Blok
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prometheus-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.10'
|
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
|
-
version: '0.
|
26
|
+
version: '0.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: puma
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -114,9 +114,10 @@ executables: []
|
|
114
114
|
extensions: []
|
115
115
|
extra_rdoc_files: []
|
116
116
|
files:
|
117
|
+
- ".editorconfig"
|
118
|
+
- ".github/workflows/workflow.yml"
|
117
119
|
- ".overcommit.yml"
|
118
120
|
- ".rubocop.yml"
|
119
|
-
- ".travis.yml"
|
120
121
|
- CHANGELOG.md
|
121
122
|
- Gemfile
|
122
123
|
- Gemfile.lock
|
@@ -148,8 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
149
|
- !ruby/object:Gem::Version
|
149
150
|
version: '0'
|
150
151
|
requirements: []
|
151
|
-
|
152
|
-
rubygems_version: 2.7.7
|
152
|
+
rubygems_version: 3.1.2
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: Puma plugin to export puma stats as prometheus metrics
|
data/.travis.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.2
|
4
|
-
- 2.3
|
5
|
-
- 2.4
|
6
|
-
- 2.5
|
7
|
-
script:
|
8
|
-
- bundle exec rake
|
9
|
-
- bundle exec overcommit --sign
|
10
|
-
- bundle exec overcommit --run
|
11
|
-
deploy:
|
12
|
-
provider: rubygems
|
13
|
-
api_key:
|
14
|
-
secure: WxQuGnHli0eOu/xYcO8fh8eK5sWxBQHwo5MaGhlZpdCvzELJ943gbfzhaZ7sK9okfLHPiY1uXYYA657KhlnDcrSLg16uI+HmPTi1RoKqQ3VmqQ6YoGhdl2GROlctCfHRO2iRuu7ujz9gf80OBH5ojHOwV+IrNsl911s6/4zhBY8uhFmdVb87zq1ZCPABNxanhlr0x51T6Q+JpdDW8c6FDGqUNtzqxEVMxS81tPhXnpDcUf/H0M8LOIQMyI21WyqUdo2vNqF6hCmRDogpZceJHtECboxgKoGJNEnOZdvAeX48Ysiu4O83Rq/mgBq30JBAgUe4TZPNwDjND+NJQktkzx/+IOJ+52G90VsJiUuBWsyh4IQKK+HqQr2CZyiEBybWU6FHCLifhuXfnOFA/VS2JNme16NiROrgrxoqtezbQ8yO8pgZ0PdtmL6hjBUknmZCyVDCdB1SPQGvo+b4AqkzY/SLuNCuJmOBBE5sMT6xFAiHU94rJViXMeJvF1pSQXIRFSuAQZ7ILOUC/GwqxIUmPk80p893itoFs3ExBPe2tBmzBVWyr+Dvu1SS2of+4JbBNbtOZr+nOT5pl7s4Zk4GG3b9UuozJn5yWi0Aj9iAju8T1r2tMpZ9zQtjrXtZJRi8ri8rQ2lC5ha63XLGGbDQon0bXs656GKKupaUS/BUboI=
|
15
|
-
gem: puma-metrics
|
16
|
-
on:
|
17
|
-
repo: harmjanblok/puma-metrics
|
18
|
-
rvm: 2.5
|