puma-metrics 1.0.2 → 1.2.2
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 +9 -5
- data/CHANGELOG.md +39 -0
- data/Gemfile.lock +30 -29
- data/Rakefile +4 -2
- data/lib/puma/metrics/app.rb +13 -2
- data/lib/puma/metrics/dsl.rb +2 -0
- data/lib/puma/metrics/parser.rb +38 -14
- data/lib/puma/metrics/version.rb +3 -1
- data/lib/puma/plugin/metrics.rb +4 -0
- data/puma-metrics.gemspec +6 -2
- metadata +12 -11
- data/.travis.yml +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 228a88de3862f938b3dc0c4e0c63ee42d88ab61a2fee230c5071824750a830a6
|
4
|
+
data.tar.gz: e35f415d1e4117f9258d185b112262dbf804da50f0b5f889aa754a2440e032c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d6391b87304cd0c7983e6b4dacbd9b7e6360e2781435aaa7b81bf5af64349400c2f5b653da2b655f77c8e4184943b44e72293ebf3abbdb81a0f39d21f237fdf
|
7
|
+
data.tar.gz: 91553b2e9c235ffce3931f0bd633a07ed7e825d340e28c0413db099147868ab558d57676c49cf8d26c5ba17858ee6cdeb35bb87880499e9902113196787dce3d
|
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.6', '2.7', '3.0']
|
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: 3.0
|
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,18 +1,22 @@
|
|
1
1
|
AllCops:
|
2
|
-
|
2
|
+
NewCops: enable
|
3
|
+
TargetRubyVersion: 2.6
|
3
4
|
|
4
5
|
Naming/FileName:
|
5
6
|
Exclude:
|
6
7
|
- puma-metrics.gemspec
|
7
8
|
|
8
|
-
|
9
|
+
Layout/LineLength:
|
9
10
|
Max: 120
|
10
11
|
|
11
|
-
|
12
|
-
Enabled: false
|
13
|
-
Style/MethodMissingSuper:
|
12
|
+
Lint/MissingSuper:
|
14
13
|
Exclude:
|
15
14
|
- lib/puma/metrics/parser.rb
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
Style/NumericPredicate:
|
19
|
+
Enabled: false
|
16
20
|
Style/MissingRespondToMissing:
|
17
21
|
Exclude:
|
18
22
|
- lib/puma/metrics/parser.rb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,44 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
## 1.2.2
|
6
|
+
|
7
|
+
Changes:
|
8
|
+
- Expose new metric `puma_requests_count` when using Puma 5
|
9
|
+
|
10
|
+
## 1.2.1
|
11
|
+
|
12
|
+
Changes:
|
13
|
+
- Drop support for ruby 2.5
|
14
|
+
|
15
|
+
Housekeeping:
|
16
|
+
- Update dependencies
|
17
|
+
- Updates for Puma 5
|
18
|
+
|
19
|
+
## 1.2.0
|
20
|
+
|
21
|
+
Changes:
|
22
|
+
- Drop support for ruby 2.4
|
23
|
+
- Relax prometheus-client to '>= 0.10'
|
24
|
+
|
25
|
+
Housekeeping:
|
26
|
+
- Update development dependencies
|
27
|
+
|
28
|
+
## 1.1.0
|
29
|
+
|
30
|
+
Changes:
|
31
|
+
- Upgrade prometheus-client to '~> 0.10'
|
32
|
+
|
33
|
+
Housekeeping:
|
34
|
+
- Set target version to 2.6
|
35
|
+
- Added editorconfig
|
36
|
+
|
37
|
+
## 1.0.3
|
38
|
+
|
39
|
+
Features:
|
40
|
+
- can be used with puma 3 or puma 4
|
41
|
+
|
3
42
|
## 1.0.2
|
4
43
|
|
5
44
|
Bugfixes:
|
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.2)
|
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.2)
|
12
|
+
childprocess (4.0.0)
|
13
|
+
iniparse (1.5.0)
|
14
|
+
minitest (5.14.3)
|
15
|
+
nio4r (2.5.5)
|
16
|
+
overcommit (0.57.0)
|
17
|
+
childprocess (>= 0.6.3, < 5)
|
20
18
|
iniparse (~> 1.4)
|
21
|
-
parallel (1.
|
22
|
-
parser (
|
23
|
-
ast (~> 2.4.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
puma (3.12.0)
|
28
|
-
quantile (0.2.1)
|
19
|
+
parallel (1.20.1)
|
20
|
+
parser (3.0.0.0)
|
21
|
+
ast (~> 2.4.1)
|
22
|
+
prometheus-client (2.1.0)
|
23
|
+
puma (5.2.1)
|
24
|
+
nio4r (~> 2.0)
|
29
25
|
rainbow (3.0.0)
|
30
|
-
rake (
|
31
|
-
|
32
|
-
|
26
|
+
rake (13.0.3)
|
27
|
+
regexp_parser (2.0.3)
|
28
|
+
rexml (3.2.4)
|
29
|
+
rubocop (1.10.0)
|
33
30
|
parallel (~> 1.10)
|
34
|
-
parser (>=
|
35
|
-
powerpack (~> 0.1)
|
31
|
+
parser (>= 3.0.0.0)
|
36
32
|
rainbow (>= 2.2.2, < 4.0)
|
33
|
+
regexp_parser (>= 1.8, < 3.0)
|
34
|
+
rexml
|
35
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
37
36
|
ruby-progressbar (~> 1.7)
|
38
|
-
unicode-display_width (
|
39
|
-
|
40
|
-
|
37
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
38
|
+
rubocop-ast (1.4.1)
|
39
|
+
parser (>= 2.7.1.5)
|
40
|
+
ruby-progressbar (1.11.0)
|
41
|
+
unicode-display_width (2.0.0)
|
41
42
|
|
42
43
|
PLATFORMS
|
43
44
|
ruby
|
@@ -51,4 +52,4 @@ DEPENDENCIES
|
|
51
52
|
rubocop
|
52
53
|
|
53
54
|
BUNDLED WITH
|
54
|
-
2.
|
55
|
+
2.2.3
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rake/testtask'
|
3
5
|
|
@@ -11,7 +13,7 @@ task :server do
|
|
11
13
|
require 'puma'
|
12
14
|
require 'puma/configuration'
|
13
15
|
require 'puma/events'
|
14
|
-
require 'puma/plugin/metrics
|
16
|
+
require 'puma/plugin/metrics'
|
15
17
|
|
16
18
|
configuration = Puma::Configuration.new do |config|
|
17
19
|
config.bind 'tcp://127.0.0.1:0'
|
@@ -23,7 +25,7 @@ task :server do
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
events = Puma::Events.new
|
28
|
+
events = Puma::Events.new $stdout, $stderr
|
27
29
|
launcher = Puma::Launcher.new(configuration, events: events)
|
28
30
|
launcher.run
|
29
31
|
end
|
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'
|
@@ -8,17 +10,26 @@ module Puma
|
|
8
10
|
def initialize(launcher)
|
9
11
|
@launcher = launcher
|
10
12
|
clustered = (@launcher.options[:workers] || 0) > 0
|
11
|
-
@parser = Parser.new clustered
|
13
|
+
@parser = Parser.new(clustered: clustered)
|
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,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'prometheus/client'
|
2
4
|
|
3
5
|
module Puma
|
4
6
|
module Metrics
|
5
7
|
class Parser
|
6
|
-
def initialize(clustered
|
8
|
+
def initialize(clustered: false)
|
7
9
|
register_default_metrics
|
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,38 @@ 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_requests_count,
|
50
|
+
docstring: 'Number of processed requests',
|
51
|
+
labels: [:index],
|
52
|
+
preset_labels: { index: 0 })
|
53
|
+
registry.gauge(:puma_workers,
|
54
|
+
docstring: 'Number of configured workers')
|
55
|
+
.set(1)
|
32
56
|
end
|
33
57
|
|
34
58
|
def registry
|
@@ -38,7 +62,7 @@ module Puma
|
|
38
62
|
def update_metric(key, value, labels)
|
39
63
|
return if registry.get("puma_#{key}").nil?
|
40
64
|
|
41
|
-
registry.get("puma_#{key}").set(
|
65
|
+
registry.get("puma_#{key}").set(value, labels: labels)
|
42
66
|
end
|
43
67
|
end
|
44
68
|
end
|
data/lib/puma/metrics/version.rb
CHANGED
data/lib/puma/plugin/metrics.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puma/metrics/dsl'
|
2
4
|
|
3
5
|
Puma::Plugin.create do
|
@@ -24,7 +26,9 @@ Puma::Plugin.create do
|
|
24
26
|
|
25
27
|
launcher.events.register(:state) do |state|
|
26
28
|
if %i[halt restart stop].include?(state)
|
29
|
+
# rubocop:disable Style/SoleNestedConditional
|
27
30
|
metrics.stop(true) unless metrics.shutting_down?
|
31
|
+
# rubocop:enable Style/SoleNestedConditional
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
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,10 @@ 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.
|
19
|
-
|
20
|
+
spec.required_ruby_version = '>= 2.6'
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'prometheus-client', '>= 0.10'
|
23
|
+
spec.add_runtime_dependency 'puma', '>= 3.0'
|
20
24
|
|
21
25
|
spec.add_development_dependency 'bundler'
|
22
26
|
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.2
|
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: 2021-02-17 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
|
@@ -141,14 +142,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
142
|
requirements:
|
142
143
|
- - ">="
|
143
144
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
145
|
+
version: '2.6'
|
145
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
147
|
requirements:
|
147
148
|
- - ">="
|
148
149
|
- !ruby/object:Gem::Version
|
149
150
|
version: '0'
|
150
151
|
requirements: []
|
151
|
-
rubygems_version: 3.
|
152
|
+
rubygems_version: 3.2.3
|
152
153
|
signing_key:
|
153
154
|
specification_version: 4
|
154
155
|
summary: Puma plugin to export puma stats as prometheus metrics
|
data/.travis.yml
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.4
|
4
|
-
- 2.5
|
5
|
-
- 2.6
|
6
|
-
script:
|
7
|
-
- bundle exec rake
|
8
|
-
- bundle exec overcommit --sign
|
9
|
-
- bundle exec overcommit --run
|
10
|
-
before_install:
|
11
|
-
- gem update --system
|
12
|
-
- gem install bundler
|
13
|
-
branches:
|
14
|
-
only:
|
15
|
-
- master
|
16
|
-
deploy:
|
17
|
-
provider: rubygems
|
18
|
-
api_key:
|
19
|
-
secure: WxQuGnHli0eOu/xYcO8fh8eK5sWxBQHwo5MaGhlZpdCvzELJ943gbfzhaZ7sK9okfLHPiY1uXYYA657KhlnDcrSLg16uI+HmPTi1RoKqQ3VmqQ6YoGhdl2GROlctCfHRO2iRuu7ujz9gf80OBH5ojHOwV+IrNsl911s6/4zhBY8uhFmdVb87zq1ZCPABNxanhlr0x51T6Q+JpdDW8c6FDGqUNtzqxEVMxS81tPhXnpDcUf/H0M8LOIQMyI21WyqUdo2vNqF6hCmRDogpZceJHtECboxgKoGJNEnOZdvAeX48Ysiu4O83Rq/mgBq30JBAgUe4TZPNwDjND+NJQktkzx/+IOJ+52G90VsJiUuBWsyh4IQKK+HqQr2CZyiEBybWU6FHCLifhuXfnOFA/VS2JNme16NiROrgrxoqtezbQ8yO8pgZ0PdtmL6hjBUknmZCyVDCdB1SPQGvo+b4AqkzY/SLuNCuJmOBBE5sMT6xFAiHU94rJViXMeJvF1pSQXIRFSuAQZ7ILOUC/GwqxIUmPk80p893itoFs3ExBPe2tBmzBVWyr+Dvu1SS2of+4JbBNbtOZr+nOT5pl7s4Zk4GG3b9UuozJn5yWi0Aj9iAju8T1r2tMpZ9zQtjrXtZJRi8ri8rQ2lC5ha63XLGGbDQon0bXs656GKKupaUS/BUboI=
|
20
|
-
gem: puma-metrics
|
21
|
-
on:
|
22
|
-
repo: harmjanblok/puma-metrics
|
23
|
-
rvm: 2.5
|