passenger-datadog-stats 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +84 -0
- data/bin/passenger-datadog +111 -0
- data/lib/parsers/base.rb +36 -0
- data/lib/parsers/group.rb +21 -0
- data/lib/parsers/process.rb +25 -0
- data/lib/parsers/root.rb +17 -0
- data/lib/passenger_datadog.rb +73 -0
- data/lib/service_installer.rb +151 -0
- metadata +102 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8bc0e787fc9893416d00067ad84087104b49f4e139003d4372eb621d0d6a14a8
|
|
4
|
+
data.tar.gz: 8b3996476e600f6fb499e4704c628d03c64b9ad277a35d2eeaeaf6ece5e1e9a7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 361618468fcb659ed9f5042d02d333b8f3d5dc41add0c6caadb5c186de4afe5179f5749ec10a9e0d7d74ef6722d724f644110efc4b0415327bad9ee51a22dc1e
|
|
7
|
+
data.tar.gz: 60be8a6b8001e5231dd327c3d6347feaea9da5c2b40344bdcce4a11a4a935919367612b7c52d4c46c951641fc601484bf257910067d0376a31961007c7cedc0c
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015-2018 Ryan Rosenblum
|
|
4
|
+
Copyright (c) 2026 IronCloud
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
[](https://badge.fury.io/rb/passenger-datadog-stats)
|
|
2
|
+
[](https://github.com/IronCloud/passenger-datadog/actions/workflows/ci.yml)
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
|
|
5
|
+
# passenger-datadog-stats
|
|
6
|
+
|
|
7
|
+
A continuation of the abandoned [passenger_datadog](https://rubygems.org/gems/passenger_datadog)
|
|
8
|
+
gem by [Ryan Rosenblum](https://github.com/rrosenblum), maintained by IronCloud.
|
|
9
|
+
It is published as `passenger-datadog-stats` because RubyGems treats
|
|
10
|
+
`passenger-datadog` as the same name as the original. The executable is still
|
|
11
|
+
`passenger-datadog`, so existing commands and systemd units keep working.
|
|
12
|
+
|
|
13
|
+
Inspired by [passengeri-datadog-monitor](https://github.com/Sjeanpierre/passenger-datadog-monitor)
|
|
14
|
+
|
|
15
|
+
This gem can be used to send stats from Passenger to Datadog. It makes use of
|
|
16
|
+
the command `passenger-status`, and the Ruby implementation of `statsd`
|
|
17
|
+
provided by [dogstatsd-ruby](https://github.com/DataDog/dogstatsd-ruby).
|
|
18
|
+
|
|
19
|
+
In order to gather stats on all Passenger instances, Passenger recommends
|
|
20
|
+
running `passenger-status` as `root`. Therefore, it is recommended that
|
|
21
|
+
`passenger-datadog` be run as `root` as well.
|
|
22
|
+
|
|
23
|
+
If running `passenger-datadog` as a user other than the user that owns the application
|
|
24
|
+
in Passenger, make sure that same version of Passenger is installed for both users.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
```
|
|
28
|
+
$ gem install passenger-datadog-stats
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Support
|
|
32
|
+
* Ruby >= 3.3 (tested on 3.3, 3.4, and 4.0)
|
|
33
|
+
* Passenger >= 6.0
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### Foreground process
|
|
38
|
+
```
|
|
39
|
+
$ passenger-datadog
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The process collects Passenger stats and sends them to Datadog every 30
|
|
43
|
+
seconds. It runs in the foreground and shuts down cleanly on `SIGTERM`/`SIGINT`.
|
|
44
|
+
|
|
45
|
+
### As a systemd service
|
|
46
|
+
Generate and install a unit for this host, then start it:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
$ sudo passenger-datadog install-service
|
|
50
|
+
$ sudo systemctl enable --now passenger-datadog
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`install-service` resolves the Ruby interpreter, the executable, and
|
|
54
|
+
`passenger-status` on the machine it runs on, and writes those absolute paths
|
|
55
|
+
into `/etc/systemd/system/passenger-datadog.service`. Use `--dry-run` to print
|
|
56
|
+
the unit without writing it, and `uninstall-service` to remove it.
|
|
57
|
+
|
|
58
|
+
Under rvm/rbenv/asdf, `sudo` drops the gem environment, so pass it through:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
$ sudo env PATH="$PATH" GEM_HOME="$GEM_HOME" GEM_PATH="$GEM_PATH" \
|
|
62
|
+
passenger-datadog install-service
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Regenerate the unit with `--force` after a Ruby upgrade. See
|
|
66
|
+
[docs/systemd.md](docs/systemd.md) for the full guide.
|
|
67
|
+
|
|
68
|
+
## Release
|
|
69
|
+
|
|
70
|
+
Releases use RubyGems [trusted publishing](https://guides.rubygems.org/trusted-publishing) —
|
|
71
|
+
no API tokens. The trusted publisher must be registered for this repo and the
|
|
72
|
+
`release.yml` workflow on RubyGems.org (a pending publisher becomes a normal
|
|
73
|
+
one after its first push). To release:
|
|
74
|
+
|
|
75
|
+
1. Bump the version in `passenger-datadog-stats.gemspec` and add a `CHANGELOG.md` entry.
|
|
76
|
+
2. Commit, tag, and push:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
$ git tag v2.0.0
|
|
80
|
+
$ git push origin v2.0.0
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`.github/workflows/release.yml` builds the gem and pushes it to RubyGems.org,
|
|
84
|
+
authenticating with an OIDC token scoped to this gem.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
$LOAD_PATH.unshift("#{File.dirname(File.expand_path(__FILE__))}/../lib")
|
|
5
|
+
require 'optparse'
|
|
6
|
+
require 'passenger_datadog'
|
|
7
|
+
require 'service_installer'
|
|
8
|
+
|
|
9
|
+
INTERVAL = 30
|
|
10
|
+
|
|
11
|
+
USAGE = <<~USAGE
|
|
12
|
+
Usage: passenger-datadog [command] [options]
|
|
13
|
+
|
|
14
|
+
Commands:
|
|
15
|
+
(none) Run the collector in the foreground (default).
|
|
16
|
+
install-service Generate and install the systemd unit for this host.
|
|
17
|
+
uninstall-service Disable and remove the systemd unit.
|
|
18
|
+
|
|
19
|
+
Options for install-service:
|
|
20
|
+
--dry-run Print the generated unit instead of writing it.
|
|
21
|
+
--force Overwrite an existing unit file.
|
|
22
|
+
--enable-now Also run `systemctl enable --now` after installing.
|
|
23
|
+
--user USER User= for the unit (default: root).
|
|
24
|
+
--group GROUP Group= for the unit (default: root).
|
|
25
|
+
--passenger-status PATH
|
|
26
|
+
Path to passenger-status (default: auto-detected).
|
|
27
|
+
USAGE
|
|
28
|
+
|
|
29
|
+
SWITCHES = { '--dry-run' => :dry_run, '--force' => :force, '--enable-now' => :enable_now }.freeze
|
|
30
|
+
VALUE_FLAGS = { '--user USER' => :user, '--group GROUP' => :group,
|
|
31
|
+
'--passenger-status PATH' => :passenger_status }.freeze
|
|
32
|
+
|
|
33
|
+
def parse_options(argv)
|
|
34
|
+
options = { user: 'root', group: 'root' }
|
|
35
|
+
OptionParser.new do |parser|
|
|
36
|
+
SWITCHES.each { |flag, key| parser.on(flag) { options[key] = true } }
|
|
37
|
+
VALUE_FLAGS.each { |flag, key| parser.on(flag) { |value| options[key] = value } }
|
|
38
|
+
parser.on('-h', '--help') { abort(USAGE) }
|
|
39
|
+
end.parse!(argv)
|
|
40
|
+
options
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def install_service(options)
|
|
44
|
+
installer = ServiceInstaller.new(user: options[:user], group: options[:group],
|
|
45
|
+
passenger_status: options[:passenger_status])
|
|
46
|
+
return puts(installer.unit) if options[:dry_run]
|
|
47
|
+
|
|
48
|
+
path = installer.install(force: options[:force])
|
|
49
|
+
warn("wrote #{path}")
|
|
50
|
+
warn('ran systemctl daemon-reload')
|
|
51
|
+
enable_now if options[:enable_now]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def enable_now
|
|
55
|
+
raise ServiceInstaller::Error, 'systemctl enable --now failed' unless
|
|
56
|
+
system('systemctl', 'enable', '--now', ServiceInstaller::UNIT_NAME)
|
|
57
|
+
|
|
58
|
+
warn("ran systemctl enable --now #{ServiceInstaller::UNIT_NAME}")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def uninstall_service(options)
|
|
62
|
+
path = ServiceInstaller.new(user: options[:user], group: options[:group]).uninstall
|
|
63
|
+
warn(path ? "removed #{path}" : 'no unit installed')
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def collect_forever
|
|
67
|
+
trap('TERM') { exit }
|
|
68
|
+
trap('INT') { exit }
|
|
69
|
+
notify_ready
|
|
70
|
+
|
|
71
|
+
loop do
|
|
72
|
+
PassengerDatadog.new.run
|
|
73
|
+
sleep(INTERVAL)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def notify_address
|
|
78
|
+
address = ENV.fetch('NOTIFY_SOCKET', nil)
|
|
79
|
+
return nil if address.nil? || address.empty?
|
|
80
|
+
|
|
81
|
+
# A leading '@' denotes the abstract namespace, whose address starts with NUL.
|
|
82
|
+
address.start_with?('@') ? "\0#{address[1..]}" : address
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def notify_ready
|
|
86
|
+
address = notify_address
|
|
87
|
+
return if address.nil?
|
|
88
|
+
|
|
89
|
+
require 'socket'
|
|
90
|
+
# systemd's notify socket is SOCK_DGRAM; a stream socket gets EPROTOTYPE.
|
|
91
|
+
socket = Socket.new(:UNIX, :DGRAM)
|
|
92
|
+
socket.connect(Socket.pack_sockaddr_un(address))
|
|
93
|
+
socket.send('READY=1', 0)
|
|
94
|
+
socket.close
|
|
95
|
+
rescue StandardError => e
|
|
96
|
+
warn "sd_notify failed: #{e.message}"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
command = ARGV.first&.start_with?('-') ? nil : ARGV.shift
|
|
100
|
+
options = parse_options(ARGV)
|
|
101
|
+
|
|
102
|
+
begin
|
|
103
|
+
case command
|
|
104
|
+
when nil then collect_forever
|
|
105
|
+
when 'install-service' then install_service(options)
|
|
106
|
+
when 'uninstall-service' then uninstall_service(options)
|
|
107
|
+
else abort("unknown command: #{command}\n\n#{USAGE}")
|
|
108
|
+
end
|
|
109
|
+
rescue ServiceInstaller::Error => e
|
|
110
|
+
abort("passenger-datadog: #{e.message}")
|
|
111
|
+
end
|
data/lib/parsers/base.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Parsers
|
|
4
|
+
class Base
|
|
5
|
+
PREFIX = 'passenger'
|
|
6
|
+
|
|
7
|
+
attr_reader :batch, :xml, :prefix, :tags
|
|
8
|
+
|
|
9
|
+
def initialize(batch, xml, prefix: nil, tags: nil)
|
|
10
|
+
@batch = batch
|
|
11
|
+
@xml = xml
|
|
12
|
+
@prefix = prefix
|
|
13
|
+
@tags = tags
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
protected
|
|
17
|
+
|
|
18
|
+
def gauge(xml_key, key)
|
|
19
|
+
# Strip before the emptiness check: a pretty-printed element that holds
|
|
20
|
+
# only whitespace carries no value, and forwarding " " to Datadog would
|
|
21
|
+
# record a bogus zero rather than nothing at all.
|
|
22
|
+
value = xml.xpath(xml_key).text.strip
|
|
23
|
+
return if value.empty?
|
|
24
|
+
|
|
25
|
+
if tags
|
|
26
|
+
batch.gauge(key_for(key), value, tags: tags)
|
|
27
|
+
else
|
|
28
|
+
batch.gauge(key_for(key), value)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def key_for(key)
|
|
33
|
+
[PREFIX, prefix, key].compact.join('.')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Parsers
|
|
4
|
+
class Group < Base
|
|
5
|
+
STATS = %w[
|
|
6
|
+
capacity_used
|
|
7
|
+
get_wait_list_size
|
|
8
|
+
disable_wait_list_size
|
|
9
|
+
processes_being_spawned
|
|
10
|
+
enabled_process_count
|
|
11
|
+
disabling_process_count
|
|
12
|
+
disabled_process_count
|
|
13
|
+
].freeze
|
|
14
|
+
|
|
15
|
+
def run
|
|
16
|
+
STATS.each do |key|
|
|
17
|
+
gauge(key, key)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Parsers
|
|
4
|
+
class Process < Base
|
|
5
|
+
STATS = %w[
|
|
6
|
+
processed
|
|
7
|
+
sessions
|
|
8
|
+
busyness
|
|
9
|
+
concurrency
|
|
10
|
+
cpu
|
|
11
|
+
rss
|
|
12
|
+
private_dirty
|
|
13
|
+
pss
|
|
14
|
+
swap
|
|
15
|
+
real_memory
|
|
16
|
+
vmsize
|
|
17
|
+
].freeze
|
|
18
|
+
|
|
19
|
+
def run
|
|
20
|
+
STATS.each do |key|
|
|
21
|
+
gauge(key, key)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/parsers/root.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Parsers
|
|
4
|
+
class Root < Base
|
|
5
|
+
STATS = {
|
|
6
|
+
'process_count' => 'pool.used',
|
|
7
|
+
'max' => 'pool.max',
|
|
8
|
+
'get_wait_list_size' => 'request_queue'
|
|
9
|
+
}.freeze
|
|
10
|
+
|
|
11
|
+
def run
|
|
12
|
+
STATS.each do |xml_key, key|
|
|
13
|
+
gauge(xml_key, key)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
require 'datadog/statsd'
|
|
5
|
+
|
|
6
|
+
require 'parsers/base'
|
|
7
|
+
require 'parsers/root'
|
|
8
|
+
require 'parsers/group'
|
|
9
|
+
require 'parsers/process'
|
|
10
|
+
|
|
11
|
+
class PassengerDatadog
|
|
12
|
+
def run
|
|
13
|
+
status = strip_header(collect)
|
|
14
|
+
return if status.nil?
|
|
15
|
+
|
|
16
|
+
statsd = Datadog::Statsd.new(single_thread: true, buffer_max_pool_size: 1)
|
|
17
|
+
begin
|
|
18
|
+
run_parsers(statsd, Nokogiri::XML(status))
|
|
19
|
+
ensure
|
|
20
|
+
# Closing releases the socket; skipping it on a parser error would leak one
|
|
21
|
+
# file descriptor per collection run for the life of the service.
|
|
22
|
+
statsd.close
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def collect
|
|
29
|
+
status = `passenger-status --show=xml`
|
|
30
|
+
return status unless status.empty?
|
|
31
|
+
|
|
32
|
+
# Usually a PATH problem under systemd rather than an idle Passenger, and
|
|
33
|
+
# silence here makes a misconfigured service look healthy.
|
|
34
|
+
warn('passenger-status produced no output; skipping this collection run')
|
|
35
|
+
nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Good job Passenger 4.0.10. Return non xml in your xml output. Look for the
|
|
39
|
+
# declaration rather than dropping a fixed number of lines: passenger-status
|
|
40
|
+
# can also print a short error to stdout, and dropping three lines from that
|
|
41
|
+
# leaves nothing to parse.
|
|
42
|
+
def strip_header(status)
|
|
43
|
+
return nil if status.nil?
|
|
44
|
+
return status if status.start_with?('<?xml')
|
|
45
|
+
|
|
46
|
+
lines = status.lines
|
|
47
|
+
index = lines.index { |line| line.start_with?('<?xml') }
|
|
48
|
+
if index.nil?
|
|
49
|
+
warn("passenger-status produced no XML; skipping this collection run: #{lines.first&.strip}")
|
|
50
|
+
return nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
lines[index..].join
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def run_parsers(statsd, parsed)
|
|
57
|
+
Parsers::Root.new(statsd, parsed.xpath('//info')).run
|
|
58
|
+
|
|
59
|
+
multiple_supergroups = parsed.xpath('//supergroups/supergroup').count > 1
|
|
60
|
+
parsed.xpath('//supergroups/supergroup').each do |supergroup|
|
|
61
|
+
prefix = multiple_supergroups ? normalize_prefix(supergroup.xpath('name').text) : nil
|
|
62
|
+
Parsers::Group.new(statsd, supergroup.xpath('group'), prefix: prefix).run
|
|
63
|
+
|
|
64
|
+
supergroup.xpath('group/processes/process').each_with_index do |process, index|
|
|
65
|
+
Parsers::Process.new(statsd, process, prefix: prefix, tags: ["passenger-process:#{index}"]).run
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def normalize_prefix(prefix)
|
|
71
|
+
prefix.gsub(/(-|\s)/, '_').gsub(/(\W|\d)/i, '')
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rbconfig'
|
|
4
|
+
|
|
5
|
+
# Generates and installs the systemd unit for the collector.
|
|
6
|
+
#
|
|
7
|
+
# The unit is generated rather than shipped because the correct paths are only
|
|
8
|
+
# knowable on the target host: under rvm/rbenv/asdf the executable does not live
|
|
9
|
+
# in /usr/local/bin, and systemd's minimal PATH does not include the gem bin
|
|
10
|
+
# directory that `passenger-status` is installed into.
|
|
11
|
+
class ServiceInstaller
|
|
12
|
+
class Error < StandardError; end
|
|
13
|
+
|
|
14
|
+
UNIT_NAME = 'passenger-datadog.service'
|
|
15
|
+
UNIT_DIR = '/etc/systemd/system'
|
|
16
|
+
|
|
17
|
+
# systemd starts services with a minimal PATH; these are its usual defaults,
|
|
18
|
+
# which we extend with the directories the resolved binaries actually live in.
|
|
19
|
+
BASE_PATH = %w[/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin].freeze
|
|
20
|
+
|
|
21
|
+
UNIT_TEMPLATE = <<~UNIT
|
|
22
|
+
# Generated by `passenger-datadog install-service` on this host.
|
|
23
|
+
# Paths are resolved for this machine's Ruby; regenerate after a Ruby upgrade.
|
|
24
|
+
[Unit]
|
|
25
|
+
Description=Send Passenger stats to Datadog
|
|
26
|
+
After=network-online.target
|
|
27
|
+
Wants=network-online.target
|
|
28
|
+
|
|
29
|
+
[Service]
|
|
30
|
+
Type=notify
|
|
31
|
+
NotifyAccess=main
|
|
32
|
+
ExecStart=%<exec_start>s
|
|
33
|
+
Environment=PATH=%<path>s
|
|
34
|
+
# systemd inherits no gem environment, so pin the one this Ruby is using.
|
|
35
|
+
Environment=GEM_HOME=%<gem_home>s
|
|
36
|
+
Environment=GEM_PATH=%<gem_path>s
|
|
37
|
+
Restart=on-failure
|
|
38
|
+
RestartSec=5s
|
|
39
|
+
# Passenger recommends running passenger-status as root so it can see every
|
|
40
|
+
# Passenger instance on the host.
|
|
41
|
+
User=%<user>s
|
|
42
|
+
Group=%<group>s
|
|
43
|
+
|
|
44
|
+
[Install]
|
|
45
|
+
WantedBy=multi-user.target
|
|
46
|
+
UNIT
|
|
47
|
+
|
|
48
|
+
attr_reader :user, :group, :unit_dir
|
|
49
|
+
|
|
50
|
+
def initialize(user: 'root', group: 'root', unit_dir: UNIT_DIR, executable: nil,
|
|
51
|
+
passenger_status: nil, search_paths: nil, env: ENV)
|
|
52
|
+
@user = user
|
|
53
|
+
@group = group
|
|
54
|
+
@unit_dir = unit_dir
|
|
55
|
+
@executable = executable
|
|
56
|
+
@passenger_status = passenger_status
|
|
57
|
+
@search_paths = search_paths
|
|
58
|
+
@env = env
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def unit_path
|
|
62
|
+
File.join(unit_dir, UNIT_NAME)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Invoke Ruby explicitly so the unit does not depend on the shebang line or on
|
|
66
|
+
# systemd's PATH resolving the executable.
|
|
67
|
+
def exec_start
|
|
68
|
+
"#{RbConfig.ruby} #{executable}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def executable
|
|
72
|
+
@executable ||= File.expand_path($PROGRAM_NAME)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Everything systemd would normally have, plus the directories holding the
|
|
76
|
+
# resolved Ruby and passenger-status, so the backtick call in the collector
|
|
77
|
+
# can find passenger-status.
|
|
78
|
+
def service_path
|
|
79
|
+
([File.dirname(passenger_status), File.dirname(RbConfig.ruby)] + BASE_PATH).uniq.join(':')
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def passenger_status
|
|
83
|
+
@passenger_status ||= which('passenger-status') ||
|
|
84
|
+
raise(Error, 'passenger-status not found; is the passenger gem installed for this ruby?')
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# `passenger` is a runtime dependency, so passenger-status is installed
|
|
88
|
+
# alongside this executable. Looking there first means the command still works
|
|
89
|
+
# under `sudo`, whose secure_path strips rvm/rbenv directories from PATH.
|
|
90
|
+
def search_paths
|
|
91
|
+
@search_paths ||= [File.dirname(executable), Gem.bindir] + @env.fetch('PATH', '').split(File::PATH_SEPARATOR)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Where this Ruby installs and looks up gems. Under rvm/rbenv these are set by
|
|
95
|
+
# shell integration that systemd never runs, so they have to be baked in.
|
|
96
|
+
def gem_home
|
|
97
|
+
Gem.dir
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def gem_path
|
|
101
|
+
Gem.path.uniq.join(File::PATH_SEPARATOR)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def unit
|
|
105
|
+
format(UNIT_TEMPLATE, exec_start: exec_start, path: service_path, gem_home: gem_home,
|
|
106
|
+
gem_path: gem_path, user: user, group: group)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Writes the unit and reloads systemd. Returns the path written.
|
|
110
|
+
def install(force: false)
|
|
111
|
+
require_root
|
|
112
|
+
raise Error, "#{unit_path} already exists; pass --force to overwrite" if File.exist?(unit_path) && !force
|
|
113
|
+
|
|
114
|
+
File.write(unit_path, unit)
|
|
115
|
+
File.chmod(0o644, unit_path)
|
|
116
|
+
daemon_reload
|
|
117
|
+
unit_path
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def uninstall
|
|
121
|
+
require_root
|
|
122
|
+
return nil unless File.exist?(unit_path)
|
|
123
|
+
|
|
124
|
+
system('systemctl', 'disable', '--now', UNIT_NAME, out: File::NULL, err: File::NULL)
|
|
125
|
+
File.delete(unit_path)
|
|
126
|
+
daemon_reload
|
|
127
|
+
unit_path
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
private
|
|
131
|
+
|
|
132
|
+
def daemon_reload
|
|
133
|
+
return if system('systemctl', 'daemon-reload')
|
|
134
|
+
|
|
135
|
+
raise Error, 'systemctl daemon-reload failed'
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def require_root
|
|
139
|
+
return if Process.uid.zero?
|
|
140
|
+
|
|
141
|
+
raise Error, 'must run as root to manage units in /etc/systemd/system (try sudo)'
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def which(command)
|
|
145
|
+
search_paths.each do |dir|
|
|
146
|
+
candidate = File.join(dir, command)
|
|
147
|
+
return candidate if File.executable?(candidate) && !File.directory?(candidate)
|
|
148
|
+
end
|
|
149
|
+
nil
|
|
150
|
+
end
|
|
151
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: passenger-datadog-stats
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- IronCloud
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-09-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: dogstatsd-ruby
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5.7'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '5.7'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: nokogiri
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.16'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.16'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: passenger
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '6.0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '6.0'
|
|
55
|
+
description: |2
|
|
56
|
+
A tool for sending Passenger stats to Datadog. A continuation of the
|
|
57
|
+
abandoned passenger_datadog gem by Ryan Rosenblum.
|
|
58
|
+
email: hello@ironcloud.co
|
|
59
|
+
executables:
|
|
60
|
+
- passenger-datadog
|
|
61
|
+
extensions: []
|
|
62
|
+
extra_rdoc_files:
|
|
63
|
+
- LICENSE
|
|
64
|
+
- README.md
|
|
65
|
+
files:
|
|
66
|
+
- LICENSE
|
|
67
|
+
- README.md
|
|
68
|
+
- bin/passenger-datadog
|
|
69
|
+
- lib/parsers/base.rb
|
|
70
|
+
- lib/parsers/group.rb
|
|
71
|
+
- lib/parsers/process.rb
|
|
72
|
+
- lib/parsers/root.rb
|
|
73
|
+
- lib/passenger_datadog.rb
|
|
74
|
+
- lib/service_installer.rb
|
|
75
|
+
homepage: https://github.com/IronCloud/passenger-datadog
|
|
76
|
+
licenses:
|
|
77
|
+
- MIT
|
|
78
|
+
metadata:
|
|
79
|
+
rubygems_mfa_required: 'true'
|
|
80
|
+
source_code_uri: https://github.com/IronCloud/passenger-datadog
|
|
81
|
+
changelog_uri: https://github.com/IronCloud/passenger-datadog/blob/main/CHANGELOG.md
|
|
82
|
+
documentation_uri: https://www.rubydoc.info/gems/passenger-datadog-stats
|
|
83
|
+
post_install_message:
|
|
84
|
+
rdoc_options: []
|
|
85
|
+
require_paths:
|
|
86
|
+
- lib
|
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
|
+
requirements:
|
|
89
|
+
- - ">="
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: 3.3.0
|
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
requirements: []
|
|
98
|
+
rubygems_version: 3.5.22
|
|
99
|
+
signing_key:
|
|
100
|
+
specification_version: 4
|
|
101
|
+
summary: A tool for sending Passenger stats to Datadog (continuation of passenger_datadog)
|
|
102
|
+
test_files: []
|