puma-plugin-dogstatsd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +50 -0
- data/lib/puma/plugin/PumaPluginDogstastd.rb +69 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7485381db49f9439d5e1557addb60ecd5b57366050de80b719c56406ffc69165
|
4
|
+
data.tar.gz: f500f66e8fc090a19c1e0260786d2c9a93a51ae67f470c6f58de6eac9fc002d5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34360f459578b50e4677a5c61f7f593602c767c05b614a6a215a0aec186d500d38f5a6ece409802d0db4b51cc10c25958f5b4ef997e9a0079f11b4ff64504ddc
|
7
|
+
data.tar.gz: 7e2d31cbf1c413fa3f156dc8405b044fd79c2dabf7e16109c94ee7c59a18fb87a7f868b8808bb39388f300d78c3644638695a4b1885b9d59dc09da6d05c0ce83
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2018 James Healy
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Puma Dogstatsd Plugin
|
2
|
+
|
3
|
+
[Puma](https://github.com/puma/puma) integration with [dogstatsd](https://github.com/DataDog/dogstatsd-ruby) for easy tracking of key metrics that puma can provide:
|
4
|
+
|
5
|
+
* puma.workers
|
6
|
+
* puma.booted_workers
|
7
|
+
* puma.running
|
8
|
+
* puma.backlog
|
9
|
+
* puma.pool_capacity
|
10
|
+
* puma.max_threads
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this gem to your Gemfile with puma and then bundle:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem "puma"
|
18
|
+
gem "puma-plugin-dogstatsd"
|
19
|
+
```
|
20
|
+
|
21
|
+
Add it to your puma config:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# config/puma.rb
|
25
|
+
|
26
|
+
bind "http://127.0.0.1:9292"
|
27
|
+
|
28
|
+
workers 1
|
29
|
+
threads 8, 16
|
30
|
+
|
31
|
+
PumaPluginDogstastd.activate(self, an_instance_of_a_dogstatsd_client)
|
32
|
+
```
|
33
|
+
|
34
|
+
## Acknowledgements
|
35
|
+
|
36
|
+
This gem is a fork of the excellent [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) by James Healy.
|
37
|
+
|
38
|
+
Other puma plugins that were helpful references:
|
39
|
+
|
40
|
+
* [puma-heroku](https://github.com/evanphx/puma-heroku)
|
41
|
+
* [tmp-restart](https://github.com/puma/puma/blob/master/lib/puma/plugin/tmp_restart.rb)
|
42
|
+
* [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd)
|
43
|
+
|
44
|
+
The [puma docs](https://github.com/puma/puma/blob/master/docs/plugins.md) were also helpful.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License][license].
|
49
|
+
|
50
|
+
[license]: http://opensource.org/licenses/MIT
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# coding: utf-8, frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'puma'
|
5
|
+
require 'puma/plugin'
|
6
|
+
|
7
|
+
module PumaPluginDogstastd
|
8
|
+
|
9
|
+
KEY = :puma_plugin_datadog_statsd_client
|
10
|
+
|
11
|
+
def activate(puma_config, datadog_statsd_client)
|
12
|
+
puma_config.inject { @options[KEY] = datadog_statsd_client }
|
13
|
+
puma_config.plugin(:PumaPluginDogstastd)
|
14
|
+
end
|
15
|
+
module_function :activate
|
16
|
+
|
17
|
+
def get_dogstatsd_client(puma_config)
|
18
|
+
puma_config.instance_variable_get(:@options)[KEY]
|
19
|
+
end
|
20
|
+
module_function :get_dogstatsd_client
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
Puma::Plugin.create do
|
25
|
+
|
26
|
+
def start(launcher)
|
27
|
+
dogstatsd_client = PumaPluginDogstastd.get_dogstatsd_client(launcher)
|
28
|
+
|
29
|
+
clustered = launcher.send(:clustered?) # See https://github.com/puma/puma/blob/master/lib/puma/launcher.rb#L285
|
30
|
+
|
31
|
+
launcher.events.debug "PumaPluginDatadogStastd: enabled"
|
32
|
+
|
33
|
+
in_background do
|
34
|
+
sleep 5
|
35
|
+
loop do
|
36
|
+
launcher.events.debug 'PumaPluginDatadogStastd: notify statsd'
|
37
|
+
begin
|
38
|
+
stats = fetch_stats
|
39
|
+
|
40
|
+
dogstatsd_client.gauge('puma.workers', stats.fetch('workers', 1))
|
41
|
+
dogstatsd_client.gauge('puma.booted_workers', stats.fetch('booted_workers', 1))
|
42
|
+
dogstatsd_client.gauge('puma.running', count_value_for_key(clustered, stats, 'running'))
|
43
|
+
dogstatsd_client.gauge('puma.backlog', count_value_for_key(clustered, stats, 'backlog'))
|
44
|
+
dogstatsd_client.gauge('puma.pool_capacity', count_value_for_key(clustered, stats, 'pool_capacity'))
|
45
|
+
dogstatsd_client.gauge('puma.max_threads', count_value_for_key(clustered, stats, 'max_threads'))
|
46
|
+
rescue StandardError => e
|
47
|
+
launcher.events.error "PumaPluginDatadogStastd: notify stats failed:\n #{e.to_s}\n #{e.backtrace.join("\n ")}"
|
48
|
+
ensure
|
49
|
+
sleep 2
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def count_value_for_key(clustered, stats, key)
|
58
|
+
if clustered
|
59
|
+
stats['worker_status'].reduce(0) { |acc, s| acc + s['last_status'].fetch(key, 0) }
|
60
|
+
else
|
61
|
+
stats.fetch(key, 0)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def fetch_stats
|
66
|
+
JSON.parse(Puma.stats)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puma-plugin-dogstatsd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jules Ivanic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '3.12'
|
19
|
+
name: puma
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
name: json
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
name: bundler
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
name: rake
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5.0'
|
75
|
+
name: minitest
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
description:
|
84
|
+
email: jules.ivanic@gmail.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- MIT-LICENSE
|
90
|
+
- README.md
|
91
|
+
- lib/puma/plugin/PumaPluginDogstastd.rb
|
92
|
+
homepage: https://github.com/guizmaii/puma-plugin-statsd
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubygems_version: 3.0.3
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Send puma metrics to Dogstatsd via a background thread
|
115
|
+
test_files: []
|