passenger_datadog 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8ebcdb70d77fe46e3f3976f75285406d71acec62
4
- data.tar.gz: 5158eb6481792eaeaa9932958213fdffe406fe11
2
+ SHA256:
3
+ metadata.gz: bcd2feda9565c77acdc7c00907f17e4d8ce0c72c3ccc98b82784fb74ab76034f
4
+ data.tar.gz: 547946b6569710669c3134452c2d572483d0fe147f705da37adc38803bff545d
5
5
  SHA512:
6
- metadata.gz: 68e52f68e05cf76db97b2c45a0bd03e2c524e8daa093eebdbb551ed028ebab854a2d6571d8c4015ddedac8d4288a56e4cc4cec358fd407576ab9d9eafd7ead3e
7
- data.tar.gz: ee12b91958a59e4c821c0195b586adde46152282db03b66324267e163aaf0e10bfc33d5c3382bb8f14933d25cddca51e9ee162db73276e1230e4e262e316105c
6
+ metadata.gz: 8f7458d200f7917a6d99b369a919d527134c96f31a5ad7ce4e37223203a172b6f49914c964e5d065a374e044f4ff6c1397dc963d359a9e1ccaded62e9e531320
7
+ data.tar.gz: 23a566e3c0819ee22d668b9dd251706d4d4fcb390d9996f0a44e60fc60253252ef08731d6ad9e581e600ddb60d6b0ebd0f72301c7d2a986d0d292ed6e2075213
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Ryan
3
+ Copyright (c) 2015-2018 Ryan Rosenblum
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
-
data/README.md CHANGED
@@ -24,6 +24,7 @@ $ gem install passenger_datadog
24
24
  ```
25
25
  ## Support
26
26
  1.x Ruby >= 2.2
27
+
27
28
  0.x Ruby < 2.2
28
29
 
29
30
  ## Usage
@@ -7,7 +7,7 @@ require 'passenger_datadog'
7
7
 
8
8
  Daemons.run_proc('passenger-datadog', dir_mode: :system) do
9
9
  loop do
10
- PassengerDatadog.run
10
+ PassengerDatadog.new.run
11
11
  sleep(30)
12
12
  end
13
13
  end
@@ -0,0 +1,31 @@
1
+ module Parsers
2
+ class Base
3
+ PREFIX = 'passenger'.freeze
4
+
5
+ attr_reader :batch, :xml, :prefix, :tags
6
+
7
+ def initialize(batch, xml, prefix: nil, tags: nil)
8
+ @batch = batch
9
+ @xml = xml
10
+ @prefix = prefix
11
+ @tags = tags
12
+ end
13
+
14
+ protected
15
+
16
+ def gauge(xml_key, key)
17
+ value = xml.xpath(xml_key).text
18
+ return if value.empty?
19
+
20
+ if tags
21
+ batch.gauge(key_for(key), value, tags: tags)
22
+ else
23
+ batch.gauge(key_for(key), value)
24
+ end
25
+ end
26
+
27
+ def key_for(key)
28
+ [PREFIX, prefix, key].compact.join('.')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module Parsers
2
+ class Group < Base
3
+ STATS = %w[
4
+ capacity_used
5
+ get_wait_list_size
6
+ disable_wait_list_size
7
+ processes_being_spawned
8
+ enabled_process_count
9
+ disabling_process_count
10
+ disabled_process_count
11
+ ].freeze
12
+
13
+ def run
14
+ STATS.each do |key|
15
+ gauge(key, key)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Parsers
2
+ class Process < Base
3
+ STATS = %w[
4
+ processed
5
+ sessions
6
+ busyness
7
+ concurrency
8
+ cpu
9
+ rss
10
+ private_dirty
11
+ pss
12
+ swap
13
+ real_memory
14
+ vmsize
15
+ ].freeze
16
+
17
+ def run
18
+ STATS.each do |key|
19
+ gauge(key, key)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ module Parsers
2
+ class Root < Base
3
+ STATS = {
4
+ 'process_count' => 'pool.used',
5
+ 'max' => 'pool.max',
6
+ 'get_wait_list_size' => 'request_queue'
7
+ }.freeze
8
+
9
+ def run
10
+ STATS.each do |xml_key, key|
11
+ gauge(xml_key, key)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -3,49 +3,44 @@
3
3
  require 'nokogiri'
4
4
  require 'datadog/statsd'
5
5
 
6
+ require 'parsers/base'
7
+ require 'parsers/root'
8
+ require 'parsers/group'
9
+ require 'parsers/process'
10
+
6
11
  class PassengerDatadog
7
- GROUP_STATS = %w[capacity_used processes_being_spawned enabled_process_count
8
- disabling_process_count disabled_process_count].freeze
9
- PROCESS_STATS = %w[processed sessions busyness concurrency cpu rss
10
- private_dirty pss swap real_memory vmsize].freeze
11
-
12
- class << self
13
- def run
14
- status = `passenger-status --show=xml`
15
- return if status.empty?
16
-
17
- statsd = Datadog::Statsd.new
18
-
19
- statsd.batch do |s|
20
- # Good job Passenger 4.0.10. Return non xml in your xml output.
21
- status = status.split("\n")[3..-1].join("\n") unless status.start_with?('<?xml')
22
- parsed = Nokogiri::XML(status)
23
-
24
- pool_used = parsed.xpath('//process_count').text
25
- s.gauge('passenger.pool.used', pool_used)
26
-
27
- pool_max = parsed.xpath('//max').text
28
- s.gauge('passenger.pool.max', pool_max)
29
-
30
- request_queue = parsed.xpath('//supergroups/supergroup/group/get_wait_list_size').text
31
- s.gauge('passenger.request_queue', request_queue)
32
-
33
- parsed.xpath('//supergroups/supergroup/group').each do |group|
34
- GROUP_STATS.each do |stat|
35
- value = group.xpath(stat).text
36
- next if value.empty?
37
- s.gauge("passenger.#{stat}", value)
38
- end
39
- end
40
-
41
- parsed.xpath('//supergroups/supergroup/group/processes/process').each_with_index do |process, index|
42
- PROCESS_STATS.each do |stat|
43
- value = process.xpath(stat).text
44
- next if value.empty?
45
- s.gauge("passenger.#{stat}", value, tags: ["passenger-process:#{index}"])
46
- end
47
- end
12
+ def run
13
+ status = `passenger-status --show=xml`
14
+ return if status.empty?
15
+
16
+ # Good job Passenger 4.0.10. Return non xml in your xml output.
17
+ status = status.split("\n")[3..-1].join("\n") unless status.start_with?('<?xml')
18
+
19
+ statsd = Datadog::Statsd.new
20
+ parsed = Nokogiri::XML(status)
21
+
22
+ statsd.batch do |batch|
23
+ run_in_batch(batch, parsed)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def run_in_batch(batch, parsed)
30
+ Parsers::Root.new(batch, parsed.xpath('//info')).run
31
+
32
+ multiple_supergroups = parsed.xpath('//supergroups/supergroup').count > 1
33
+ parsed.xpath('//supergroups/supergroup').each do |supergroup|
34
+ prefix = multiple_supergroups ? normalize_prefix(supergroup.xpath('name').text) : nil
35
+ Parsers::Group.new(batch, supergroup.xpath('group'), prefix: prefix).run
36
+
37
+ supergroup.xpath('group/processes/process').each_with_index do |process, index|
38
+ Parsers::Process.new(batch, process, prefix: prefix, tags: ["passenger-process:#{index}"]).run
48
39
  end
49
40
  end
50
41
  end
42
+
43
+ def normalize_prefix(prefix)
44
+ prefix.gsub(/(-|\s)/, '_').gsub(/(\W|\d)/i, '')
45
+ end
51
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passenger_datadog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Rosenblum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-17 00:00:00.000000000 Z
11
+ date: 2018-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daemons
@@ -84,14 +84,14 @@ dependencies:
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '10.1'
87
+ version: '12.0'
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
- version: '10.1'
94
+ version: '12.0'
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: rspec
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -112,26 +112,30 @@ dependencies:
112
112
  requirements:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: 0.52.0
115
+ version: 0.55.0
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: 0.52.0
122
+ version: 0.55.0
123
123
  description: " A tool for sending Passenger stats to Datadog.\n"
124
124
  email: passenger_datadog@manheim.com
125
125
  executables:
126
126
  - passenger-datadog
127
127
  extensions: []
128
128
  extra_rdoc_files:
129
- - LICENSE
129
+ - LICENSE.txt
130
130
  - README.md
131
131
  files:
132
- - LICENSE
132
+ - LICENSE.txt
133
133
  - README.md
134
134
  - bin/passenger-datadog
135
+ - lib/parsers/base.rb
136
+ - lib/parsers/group.rb
137
+ - lib/parsers/process.rb
138
+ - lib/parsers/root.rb
135
139
  - lib/passenger_datadog.rb
136
140
  homepage: https://github.com/manheim/passenger-datadog
137
141
  licenses:
@@ -153,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
157
  version: '0'
154
158
  requirements: []
155
159
  rubyforge_project:
156
- rubygems_version: 2.6.13
160
+ rubygems_version: 2.7.6
157
161
  signing_key:
158
162
  specification_version: 4
159
163
  summary: A tool for sending Passenger stats to Datadog