puma-newrelic-codeur 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +10 -0
- data/lib/puma/newrelic/plugin.rb +23 -0
- data/lib/puma/newrelic/sampler.rb +64 -0
- data/lib/puma/newrelic/version.rb +7 -0
- data/lib/puma/newrelic.rb +12 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e195287b18055147b79b50cc78d44befa3c7b40ea72cc24cde2c69b9a67d546
|
4
|
+
data.tar.gz: ccdcf8d5f9f7cadd582cf8890240ed9d4d6898847bcd7287f99161646f5b6fb8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfe22844effa9205d4e819d9b450cd35abdb57f7af1ee88a42fb04c1781f6b2b1554e19fc91b2019c192c439a1eae6bba056c69db20db6f19fc70a3fd18a6781
|
7
|
+
data.tar.gz: 385b990229ef0eeb227fc0f32154af04a325c34dfff661ac94494306232c9ec8fbc2c8bfd9a5c989dcff6cefce9159627079f68f70ddb610d1c1c1ed1a0b4bdf
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Brice TEXIER
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Puma::NewRelic
|
2
|
+
|
3
|
+
This is a Puma plugin for NewRelic custom metrics.
|
4
|
+
It will sample the Puma stats and create a custom metric for NewRelic.
|
5
|
+
You can view the information in the NewRelic insights or in NewRelic One.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'puma-newrelic'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install puma-newrelic
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
- Install the gem
|
26
|
+
- Add `plugin 'newrelic'` to your puma.rb
|
27
|
+
- Create a dashboard on the NewRelic insights or NewRelic One
|
28
|
+
|
29
|
+
NQRL example:
|
30
|
+
|
31
|
+
```SQL
|
32
|
+
SELECT rate(average(newrelic.timeslice.value), 1 minute)
|
33
|
+
FROM Metric
|
34
|
+
WHERE appName ='My App Name'
|
35
|
+
WITH METRIC_FORMAT 'Custom/Puma/pool_capacity'
|
36
|
+
TIMESERIES FACET `host` LIMIT 10 SINCE 1800 seconds ago
|
37
|
+
```
|
38
|
+
|
39
|
+
## Extra config in newrelic.yml
|
40
|
+
|
41
|
+
```yaml
|
42
|
+
common: &default_settings
|
43
|
+
puma:
|
44
|
+
sample_rate: 15
|
45
|
+
keys:
|
46
|
+
- backlog
|
47
|
+
- running
|
48
|
+
- pool_capacity
|
49
|
+
- max_threads
|
50
|
+
```
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/codeur/puma-newrelic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/codeur/puma-newrelic/blob/main/CODE_OF_CONDUCT.md).
|
61
|
+
|
62
|
+
## Code of Conduct
|
63
|
+
|
64
|
+
Everyone interacting in the Puma::NewRelic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/codeur/puma-newrelic/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "sampler"
|
2
|
+
require "puma/plugin"
|
3
|
+
|
4
|
+
module Puma
|
5
|
+
module NewRelic
|
6
|
+
class Plugin < Puma::Plugin
|
7
|
+
def start(launcher)
|
8
|
+
sampler = Puma::NewRelic::Sampler.new(launcher)
|
9
|
+
launcher.events.register(:state) do |state|
|
10
|
+
if %i[halt restart stop].include?(state)
|
11
|
+
sampler.stop
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
in_background do
|
16
|
+
sampler.start
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Puma::Plugins.register "newrelic", Plugin
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "newrelic_rpm"
|
2
|
+
|
3
|
+
module Puma
|
4
|
+
module NewRelic
|
5
|
+
class Sampler
|
6
|
+
def initialize(launcher)
|
7
|
+
config = ::NewRelic::Agent.config[:puma] || {}
|
8
|
+
@launcher = launcher
|
9
|
+
@sample_rate = config.fetch("sample_rate", 15)
|
10
|
+
@keys = config.fetch("keys", %w[backlog running pool_capacity max_threads]).map(&:to_s)
|
11
|
+
@last_sample_at = Time.now
|
12
|
+
end
|
13
|
+
|
14
|
+
def start
|
15
|
+
@running = true
|
16
|
+
while @running
|
17
|
+
sleep 1
|
18
|
+
begin
|
19
|
+
if should_sample?
|
20
|
+
@last_sample_at = Time.now
|
21
|
+
puma_stats = @launcher.stats
|
22
|
+
if puma_stats.is_a?(Hash)
|
23
|
+
parse puma_stats
|
24
|
+
else
|
25
|
+
parse JSON.parse(puma_stats, symbolize_names: true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
29
|
+
::NewRelic::Agent.logger.error(e.message)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def should_sample?
|
35
|
+
Time.now - @last_sample_at > @sample_rate
|
36
|
+
end
|
37
|
+
|
38
|
+
def stop
|
39
|
+
@running = false
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse(stats)
|
43
|
+
metrics = Hash.new { |h, k| h[k] = 0 }
|
44
|
+
|
45
|
+
if stats[:workers]
|
46
|
+
metrics[:workers] = stats[:workers]
|
47
|
+
stats[:worker_status].each do |worker|
|
48
|
+
worker[:last_status].each { |key, value| metrics[key.to_s] += value if @keys.include?(key.to_s) }
|
49
|
+
end
|
50
|
+
else
|
51
|
+
stats.each { |key, value| metrics[key.to_s] += value if @keys.include?(key.to_s) }
|
52
|
+
end
|
53
|
+
report_metrics(metrics)
|
54
|
+
end
|
55
|
+
|
56
|
+
def report_metrics(metrics)
|
57
|
+
metrics.each do |key, value|
|
58
|
+
::NewRelic::Agent.logger.debug("Recorded metric: Custom/Puma/#{key}=#{value}")
|
59
|
+
::NewRelic::Agent.record_metric("Custom/Puma/#{key}", value)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puma-newrelic-codeur
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benoist Claassen
|
8
|
+
- Codeur SAS
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2025-01-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: puma
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '6.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '6.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: newrelic_rpm
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '9.0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '9.0'
|
42
|
+
description: Samples the puma stats and creates a custom metric for NewRelic
|
43
|
+
email:
|
44
|
+
- benoist.claassen@gmail.com
|
45
|
+
- dev@codeur.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".standard.yml"
|
51
|
+
- CHANGELOG.md
|
52
|
+
- CODE_OF_CONDUCT.md
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/puma/newrelic.rb
|
57
|
+
- lib/puma/newrelic/plugin.rb
|
58
|
+
- lib/puma/newrelic/sampler.rb
|
59
|
+
- lib/puma/newrelic/version.rb
|
60
|
+
homepage: https://github.com/codeur/puma-newrelic
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
allowed_push_host: https://rubygems.org
|
65
|
+
homepage_uri: https://github.com/codeur/puma-newrelic
|
66
|
+
source_code_uri: https://github.com/codeur/puma-newrelic
|
67
|
+
changelog_uri: https://github.com/codeur/puma-newrelic/blob/main/CHANGELOG.md
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 3.0.0
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.5.22
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: New Relic Puma Stats sampler
|
87
|
+
test_files: []
|