munin_passenger 1.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.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +16 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.md +69 -0
  8. data/Rakefile +19 -0
  9. data/Vagrantfile +172 -0
  10. data/bin/munin_passenger-install +10 -0
  11. data/bin/munin_passenger-install.sh +13 -0
  12. data/bin/passenger_cpu +9 -0
  13. data/bin/passenger_last_used +9 -0
  14. data/bin/passenger_munin-install.sh +13 -0
  15. data/bin/passenger_processed +9 -0
  16. data/bin/passenger_queue +9 -0
  17. data/bin/passenger_ram +9 -0
  18. data/bin/passenger_uptime +9 -0
  19. data/example/.gitignore +23 -0
  20. data/example/Gemfile +45 -0
  21. data/example/Gemfile.lock +194 -0
  22. data/example/README.md +24 -0
  23. data/example/Rakefile +6 -0
  24. data/example/app/assets/config/manifest.js +3 -0
  25. data/example/app/assets/images/.keep +0 -0
  26. data/example/app/assets/javascripts/application.js +15 -0
  27. data/example/app/assets/javascripts/cable.js +13 -0
  28. data/example/app/assets/javascripts/channels/.keep +0 -0
  29. data/example/app/assets/stylesheets/application.css +15 -0
  30. data/example/app/channels/application_cable/channel.rb +4 -0
  31. data/example/app/channels/application_cable/connection.rb +4 -0
  32. data/example/app/controllers/application_controller.rb +8 -0
  33. data/example/app/controllers/concerns/.keep +0 -0
  34. data/example/app/helpers/application_helper.rb +2 -0
  35. data/example/app/jobs/application_job.rb +2 -0
  36. data/example/app/mailers/application_mailer.rb +4 -0
  37. data/example/app/models/application_record.rb +3 -0
  38. data/example/app/models/concerns/.keep +0 -0
  39. data/example/app/views/layouts/application.html.erb +14 -0
  40. data/example/app/views/layouts/mailer.html.erb +13 -0
  41. data/example/app/views/layouts/mailer.text.erb +1 -0
  42. data/example/bin/bundle +3 -0
  43. data/example/bin/rails +9 -0
  44. data/example/bin/rake +9 -0
  45. data/example/bin/setup +38 -0
  46. data/example/bin/spring +17 -0
  47. data/example/bin/update +29 -0
  48. data/example/bin/yarn +11 -0
  49. data/example/config/application.rb +18 -0
  50. data/example/config/boot.rb +3 -0
  51. data/example/config/cable.yml +10 -0
  52. data/example/config/database.yml +7 -0
  53. data/example/config/environment.rb +5 -0
  54. data/example/config/environments/development.rb +54 -0
  55. data/example/config/environments/production.rb +91 -0
  56. data/example/config/environments/test.rb +42 -0
  57. data/example/config/initializers/application_controller_renderer.rb +8 -0
  58. data/example/config/initializers/assets.rb +14 -0
  59. data/example/config/initializers/backtrace_silencers.rb +7 -0
  60. data/example/config/initializers/cookies_serializer.rb +5 -0
  61. data/example/config/initializers/filter_parameter_logging.rb +4 -0
  62. data/example/config/initializers/inflections.rb +16 -0
  63. data/example/config/initializers/mime_types.rb +4 -0
  64. data/example/config/initializers/wrap_parameters.rb +14 -0
  65. data/example/config/locales/en.yml +33 -0
  66. data/example/config/puma.rb +56 -0
  67. data/example/config/routes.rb +4 -0
  68. data/example/config/secrets.yml +33 -0
  69. data/example/config/spring.rb +6 -0
  70. data/example/config.ru +5 -0
  71. data/example/db/seeds.rb +7 -0
  72. data/example/lib/assets/.keep +0 -0
  73. data/example/lib/tasks/.keep +0 -0
  74. data/example/log/.keep +0 -0
  75. data/example/package.json +5 -0
  76. data/example/public/404.html +67 -0
  77. data/example/public/422.html +67 -0
  78. data/example/public/500.html +66 -0
  79. data/example/public/apple-touch-icon-precomposed.png +0 -0
  80. data/example/public/apple-touch-icon.png +0 -0
  81. data/example/public/favicon.ico +0 -0
  82. data/example/public/robots.txt +1 -0
  83. data/example/test/application_system_test_case.rb +5 -0
  84. data/example/test/controllers/.keep +0 -0
  85. data/example/test/fixtures/.keep +0 -0
  86. data/example/test/fixtures/files/.keep +0 -0
  87. data/example/test/helpers/.keep +0 -0
  88. data/example/test/integration/.keep +0 -0
  89. data/example/test/mailers/.keep +0 -0
  90. data/example/test/models/.keep +0 -0
  91. data/example/test/system/.keep +0 -0
  92. data/example/test/test_helper.rb +10 -0
  93. data/example/tmp/.keep +0 -0
  94. data/example/vendor/.keep +0 -0
  95. data/lib/munin_passenger/collect.rb +71 -0
  96. data/lib/munin_passenger/graphs.rb +213 -0
  97. data/lib/munin_passenger/version.rb +3 -0
  98. data/lib/munin_passenger.rb +2 -0
  99. data/munin_passenger.gemspec +34 -0
  100. data/scripts/capture-passenger-status.sh +3 -0
  101. data/scripts/load-test.sh +3 -0
  102. data/scripts/make-bins.rb +38 -0
  103. data/spec/mock/passenger-status +3 -0
  104. data/spec/mock/passenger-status.xml +2 -0
  105. data/spec/munin_passenger_spec.rb +139 -0
  106. data/spec/spec_helper.rb +15 -0
  107. metadata +255 -0
@@ -0,0 +1,71 @@
1
+ require 'nokogiri'
2
+ require 'ostruct'
3
+
4
+ module MuninPassenger
5
+ module Collect
6
+
7
+ def self.parse_stats(f)
8
+ Nokogiri::XML(f) do |config|
9
+ config.strict.
10
+ noblanks. # Exclude blank nodes
11
+ nonet # Don't make any network connections
12
+ end
13
+ end
14
+
15
+ def self.get_group_stats(doc)
16
+ ret = []
17
+ doc.xpath('//info/supergroups/supergroup').each do |x_supergroup|
18
+ x_supergroup.xpath('./group').each do |x_group|
19
+ g = OpenStruct.new
20
+ g.name = x_group.xpath('name').first.text
21
+ g.queue = x_group.xpath('get_wait_list_size').first.text
22
+ ret << g
23
+ end
24
+ end
25
+ ret
26
+ end
27
+
28
+ def self.get_ps_stats(doc)
29
+ ret = []
30
+ now = Time.now
31
+ doc.xpath('//info/supergroups/supergroup').each do |x_supergroup|
32
+ x_supergroup.xpath('./group').each do |x_group|
33
+ x_group.xpath('./processes/process').each do |x_ps|
34
+ ps = OpenStruct.new
35
+ ps.pid = x_ps.xpath('pid').first.text
36
+ ps.sessions = x_ps.xpath('sessions').first.text.to_i
37
+ ps.last_used = (now - Time.at(x_ps.xpath('last_used').first.text.to_i / 1000 / 1000).to_i).to_i # in seconds
38
+ ps.ram = x_ps.xpath('real_memory').first.text.to_i # in KB
39
+ ps.cpu = x_ps.xpath('cpu').first.text.to_i # in %
40
+ ps.uptime = (now - Time.at(x_ps.xpath('spawn_start_time').first.text.to_i / 1000 / 1000).to_i).to_i # in seconds
41
+ ps.processed = x_ps.xpath('processed').first.text.to_i # in requests
42
+ ret << ps
43
+ end
44
+ end
45
+ end
46
+ ret
47
+ end
48
+
49
+ def self.run_status
50
+ dir = if ENV['PASSENGER_ROOT']
51
+ "#{ENV['PASSENGER_ROOT']}/"
52
+ else
53
+ ''
54
+ end
55
+
56
+ sudo = if ENV['WITHOUT_SUDO']
57
+ ''
58
+ else
59
+ 'sudo '
60
+ end
61
+
62
+ status = `#{sudo}#{dir}passenger-status --show=xml`
63
+ if not $?.success?
64
+ $stderr.puts 'Error running passenger-status'
65
+ exit 1
66
+ end
67
+ status
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,213 @@
1
+ module MuninPassenger
2
+ module Graphs
3
+
4
+ def self.escape_group(g_name)
5
+ g_name.gsub(/^[^a-zA-Z_]/, '_').
6
+ gsub(/[^a-zA-Z0-9_]/, '_')
7
+ end
8
+
9
+ def self.get_stats
10
+ doc = MuninPassenger::Collect.parse_stats(MuninPassenger::Collect.run_status)
11
+ groups = MuninPassenger::Collect.get_group_stats(doc)
12
+ pses = MuninPassenger::Collect.get_ps_stats(doc)
13
+ [groups, pses]
14
+ end
15
+
16
+ # ###############
17
+ # passenger_queue
18
+ # ###############
19
+
20
+ def self.queue_config
21
+ groups, pses = get_stats
22
+ ret = ''
23
+ ret += <<-EOF
24
+ graph_category passenger
25
+ graph_title Passenger queue
26
+ graph_vlabel Requests
27
+ EOF
28
+ groups.each do |g|
29
+ ret += <<-EOF
30
+ _group_#{escape_group(g.name)}_queue.label #{g.name}
31
+ EOF
32
+ end
33
+ pses.each do |ps|
34
+ ret += <<-EOF
35
+ _pid_#{ps.pid}_sessions.label PID #{ps.pid}
36
+ EOF
37
+ end
38
+ ret
39
+ end
40
+
41
+ def self.queue_values
42
+ groups, pses = get_stats
43
+ ret = ''
44
+ groups.each do |g|
45
+ ret += <<-EOF
46
+ _group_#{escape_group(g.name)}_queue.value #{g.queue}
47
+ EOF
48
+ end
49
+ pses.each do |ps|
50
+ ret += <<-EOF
51
+ _pid_#{ps.pid}_sessions.value #{ps.sessions}
52
+ EOF
53
+ end
54
+ ret
55
+ end
56
+
57
+ # #############
58
+ # passenger_ram
59
+ # #############
60
+
61
+ def self.ram_config
62
+ groups, pses = get_stats
63
+ ret = ''
64
+ ret += <<-EOF
65
+ graph_category passenger
66
+ graph_title Passenger memory usage
67
+ graph_vlabel Bytes
68
+ EOF
69
+ pses.each do |ps|
70
+ ret += <<-EOF
71
+ _pid_#{ps.pid}_ram.label PID #{ps.pid}
72
+ EOF
73
+ end
74
+ ret
75
+ end
76
+
77
+ def self.ram_values
78
+ groups, pses = get_stats
79
+ ret = ''
80
+ pses.each do |ps|
81
+ ret += <<-EOF
82
+ _pid_#{ps.pid}_ram.value #{ps.ram * 1024}
83
+ EOF
84
+ end
85
+ ret
86
+ end
87
+
88
+ # #############
89
+ # passenger_cpu
90
+ # #############
91
+
92
+ def self.cpu_config
93
+ groups, pses = get_stats
94
+ ret = ''
95
+ ret += <<-EOF
96
+ graph_category passenger
97
+ graph_title Passenger CPU
98
+ graph_vlabel %
99
+ EOF
100
+ pses.each do |ps|
101
+ ret += <<-EOF
102
+ _pid_#{ps.pid}_cpu.label PID #{ps.pid}
103
+ EOF
104
+ end
105
+ ret
106
+ end
107
+
108
+ def self.cpu_values
109
+ groups, pses = get_stats
110
+ ret = ''
111
+ pses.each do |ps|
112
+ ret += <<-EOF
113
+ _pid_#{ps.pid}_cpu.value #{ps.cpu}
114
+ EOF
115
+ end
116
+ ret
117
+ end
118
+
119
+ # ###################
120
+ # passenger_processed
121
+ # ###################
122
+
123
+ def self.processed_config
124
+ groups, pses = get_stats
125
+ ret = ''
126
+ ret += <<-EOF
127
+ graph_category passenger
128
+ graph_title Requests processed
129
+ graph_vlabel Requests
130
+ EOF
131
+ pses.each do |ps|
132
+ ret += <<-EOF
133
+ _pid_#{ps.pid}_processed.label PID #{ps.pid}
134
+ EOF
135
+ end
136
+ ret
137
+ end
138
+
139
+ def self.processed_values
140
+ groups, pses = get_stats
141
+ ret = ''
142
+ pses.each do |ps|
143
+ ret += <<-EOF
144
+ _pid_#{ps.pid}_processed.value #{ps.processed}
145
+ EOF
146
+ end
147
+ ret
148
+ end
149
+
150
+ # ################
151
+ # passenger_uptime
152
+ # ################
153
+
154
+ def self.uptime_config
155
+ groups, pses = get_stats
156
+ ret = ''
157
+ ret += <<-EOF
158
+ graph_category passenger
159
+ graph_title Uptime
160
+ graph_vlabel Hours
161
+ EOF
162
+ pses.each do |ps|
163
+ ret += <<-EOF
164
+ _pid_#{ps.pid}_uptime.label PID #{ps.pid}
165
+ EOF
166
+ end
167
+ ret
168
+ end
169
+
170
+ def self.uptime_values
171
+ groups, pses = get_stats
172
+ ret = ''
173
+ pses.each do |ps|
174
+ ret += <<-EOF
175
+ _pid_#{ps.pid}_uptime.value #{ps.uptime.to_f / 60 / 60}
176
+ EOF
177
+ end
178
+ ret
179
+ end
180
+
181
+ # ###################
182
+ # passenger_last_used
183
+ # ###################
184
+
185
+ def self.last_used_config
186
+ groups, pses = get_stats
187
+ ret = ''
188
+ ret += <<-EOF
189
+ graph_category passenger
190
+ graph_title Last used
191
+ graph_vlabel Seconds
192
+ EOF
193
+ pses.each do |ps|
194
+ ret += <<-EOF
195
+ _pid_#{ps.pid}_last_used.label PID #{ps.pid}
196
+ EOF
197
+ end
198
+ ret
199
+ end
200
+
201
+ def self.last_used_values
202
+ groups, pses = get_stats
203
+ ret = ''
204
+ pses.each do |ps|
205
+ ret += <<-EOF
206
+ _pid_#{ps.pid}_last_used.value #{ps.last_used}
207
+ EOF
208
+ end
209
+ ret
210
+ end
211
+
212
+ end
213
+ end
@@ -0,0 +1,3 @@
1
+ module MuninPassenger
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'munin_passenger/collect'
2
+ require 'munin_passenger/graphs'
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'munin_passenger/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "munin_passenger"
7
+ s.version = MuninPassenger::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+
10
+ s.summary = "Munin plugin for monitoring Phusion Passenger."
11
+ s.description = "Runs passenger-status to graph CPU, RAM, queue size, requests served, etc."
12
+
13
+ s.authors = ["Paul A. Jungwirth"]
14
+ s.homepage = "https://github.com/pjungwir/munin_passenger"
15
+ s.email = "pj@illuminatedcomputing.com"
16
+
17
+ s.licenses = ["MIT"]
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,fixtures}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}.reject{|f| f =~ /\.sh$/}
22
+ s.require_paths = ["lib"]
23
+ s.rdoc_options = ['--charset=UTF-8']
24
+
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'bundler'
27
+ s.add_development_dependency 'rspec'
28
+ s.add_development_dependency 'timecop'
29
+ s.add_development_dependency 'simplecov'
30
+ s.add_development_dependency 'rubocop'
31
+
32
+ s.add_dependency 'nokogiri'
33
+ end
34
+
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ vagrant ssh -c 'sudo passenger-status --show=xml 2>/dev/null' 2>/dev/null
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ ab -c 10 -n 10000 http://192.168.60.10/status
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ plugins = %w[queue ram cpu processed uptime last_used]
4
+
5
+ plugins.each do |g|
6
+ filename = "bin/passenger_#{g}"
7
+ File.open(filename, 'w') do |f|
8
+ f.puts <<~EOF
9
+ #!/usr/bin/env ruby
10
+
11
+ require 'munin_passenger'
12
+
13
+ if ARGV[0] == 'config'
14
+ puts MuninPassenger::Graphs.#{g}_config
15
+ else
16
+ puts MuninPassenger::Graphs.#{g}_values
17
+ end
18
+ EOF
19
+ end
20
+ system("chmod +x #{filename}")
21
+ end
22
+
23
+ filename = "bin/munin_passenger-install.sh"
24
+ File.open(filename, 'w') do |f|
25
+ f.puts <<~EOF
26
+ #/bin/bash
27
+
28
+ set -eu
29
+
30
+ dest="${1:-/etc/munin/plugins/}"
31
+ mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
32
+
33
+ EOF
34
+ plugins.each do |p|
35
+ f.puts %Q{ln -fs "${mydir}/passenger_#{p}" "$dest"}
36
+ end
37
+ end
38
+ system("chmod +x #{filename}")
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ puts File.read(File.dirname(__FILE__) + '/passenger-status.xml') {|f| f.read.strip}
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="iso8859-1" ?>
2
+ <info version="3"><passenger_version>5.3.4</passenger_version><group_count>1</group_count><process_count>4</process_count><max>4</max><capacity_used>4</capacity_used><get_wait_list_size>0</get_wait_list_size><supergroups><supergroup><name>/vagrant/example &#40;production&#41;</name><state>READY</state><get_wait_list_size>0</get_wait_list_size><capacity_used>4</capacity_used><group default="true"><name>/vagrant/example &#40;production&#41;</name><component_name>/vagrant/example &#40;production&#41;</component_name><app_root>/vagrant/example</app_root><app_type>rack</app_type><environment>production</environment><uuid>HmNUaXddYHxqdbDHhMlH</uuid><enabled_process_count>4</enabled_process_count><disabling_process_count>0</disabling_process_count><disabled_process_count>0</disabled_process_count><capacity_used>4</capacity_used><get_wait_list_size>4</get_wait_list_size><disable_wait_list_size>0</disable_wait_list_size><processes_being_spawned>0</processes_being_spawned><life_status>ALIVE</life_status><user>www-data</user><uid>33</uid><group>www-data</group><gid>33</gid><options><app_root>/vagrant/example</app_root><app_group_name>/vagrant/example &#40;production&#41;</app_group_name><app_type>rack</app_type><start_command>/usr/bin/passenger_free_ruby /usr/share/passenger/helper-scripts/rack-loader.rb</start_command><startup_file>/vagrant/example/config.ru</startup_file><process_title>Passenger RubyApp</process_title><log_level>3</log_level><start_timeout>90000</start_timeout><environment>production</environment><base_uri>/</base_uri><spawn_method>smart</spawn_method><default_user>www-data</default_user><default_group>www-data</default_group><restart_dir>tmp</restart_dir><integration_mode>nginx</integration_mode><ruby>/usr/bin/passenger_free_ruby</ruby><python>python</python><nodejs>node</nodejs><debugger>false</debugger><api_key>SslPEpMlXcKPv4DX</api_key><min_processes>4</min_processes><max_processes>0</max_processes><max_preloader_idle_time>300</max_preloader_idle_time><max_out_of_band_work_instances>1</max_out_of_band_work_instances></options><processes><process><pid>4510</pid><sticky_session_id>1463048305</sticky_session_id><gupid>186d826-q9scApl4BE</gupid><concurrency>1</concurrency><sessions>1</sessions><busyness>2147483647</busyness><processed>139</processed><spawner_creation_time>1536862465405912</spawner_creation_time><spawn_start_time>1536862469897396</spawn_start_time><spawn_end_time>1536862469995617</spawn_end_time><last_used>1536862501524427</last_used><last_used_desc>0s ago</last_used_desc><uptime>32s</uptime><life_status>ALIVE</life_status><enabled>ENABLED</enabled><has_metrics>true</has_metrics><cpu>2</cpu><rss>74332</rss><pss>46755</pss><private_dirty>40400</private_dirty><swap>0</swap><real_memory>40400</real_memory><vmsize>403004</vmsize><process_group_id>4447</process_group_id><command>Passenger AppPreloader: /vagrant/example &#40;forking...&#41;</command></process><process><pid>4529</pid><sticky_session_id>1881688971</sticky_session_id><gupid>186d826-0gXXbEbmmP</gupid><concurrency>1</concurrency><sessions>1</sessions><busyness>2147483647</busyness><processed>138</processed><spawner_creation_time>1536862465405912</spawner_creation_time><spawn_start_time>1536862470006804</spawn_start_time><spawn_end_time>1536862470078273</spawn_end_time><last_used>1536862501513463</last_used><last_used_desc>0s ago</last_used_desc><uptime>31s</uptime><life_status>ALIVE</life_status><enabled>ENABLED</enabled><has_metrics>true</has_metrics><cpu>3</cpu><rss>73824</rss><pss>34705</pss><private_dirty>24396</private_dirty><swap>0</swap><real_memory>24396</real_memory><vmsize>403100</vmsize><process_group_id>4447</process_group_id><command>Passenger AppPreloader: /vagrant/example &#40;forking...&#41;</command></process><process><pid>4548</pid><sticky_session_id>1153287320</sticky_session_id><gupid>186d826-BeArKZIXdV</gupid><concurrency>1</concurrency><sessions>1</sessions><busyness>2147483647</busyness><processed>138</processed><spawner_creation_time>1536862465405912</spawner_creation_time><spawn_start_time>1536862470085976</spawn_start_time><spawn_end_time>1536862470135512</spawn_end_time><last_used>1536862501526424</last_used><last_used_desc>0s ago</last_used_desc><uptime>31s</uptime><life_status>ALIVE</life_status><enabled>ENABLED</enabled><has_metrics>true</has_metrics><cpu>2</cpu><rss>73836</rss><pss>34607</pss><private_dirty>24268</private_dirty><swap>0</swap><real_memory>24268</real_memory><vmsize>403196</vmsize><process_group_id>4447</process_group_id><command>Passenger AppPreloader: /vagrant/example &#40;forking...&#41;</command></process><process><pid>4567</pid><sticky_session_id>929143326</sticky_session_id><gupid>186d826-Gf2fJwkxHL</gupid><concurrency>1</concurrency><sessions>1</sessions><busyness>2147483647</busyness><processed>138</processed><spawner_creation_time>1536862465405912</spawner_creation_time><spawn_start_time>1536862470144900</spawn_start_time><spawn_end_time>1536862470218102</spawn_end_time><last_used>1536862501522542</last_used><last_used_desc>0s ago</last_used_desc><uptime>31s</uptime><life_status>ALIVE</life_status><enabled>ENABLED</enabled><has_metrics>true</has_metrics><cpu>2</cpu><rss>73848</rss><pss>34428</pss><private_dirty>23872</private_dirty><swap>0</swap><real_memory>23872</real_memory><vmsize>403292</vmsize><process_group_id>4447</process_group_id><command>Passenger AppPreloader: /vagrant/example &#40;forking...&#41;</command></process></processes></group></supergroup></supergroups></info>
@@ -0,0 +1,139 @@
1
+ describe 'munin_passenger plugin' do
2
+
3
+ before do
4
+ ENV['PASSENGER_ROOT'] = File.dirname(__FILE__) + '/mock'
5
+ end
6
+
7
+ it "gives the queue configuration" do
8
+ expect(MuninPassenger::Graphs.queue_config).to eq <<-EOF
9
+ graph_category passenger
10
+ graph_title Passenger queue
11
+ graph_vlabel Requests
12
+ _group__vagrant_example__production__queue.label /vagrant/example (production)
13
+ _pid_4510_sessions.label PID 4510
14
+ _pid_4529_sessions.label PID 4529
15
+ _pid_4548_sessions.label PID 4548
16
+ _pid_4567_sessions.label PID 4567
17
+ EOF
18
+ end
19
+
20
+ it "gives the queue values" do
21
+ expect(MuninPassenger::Graphs.queue_values).to eq <<-EOF
22
+ _group__vagrant_example__production__queue.value 4
23
+ _pid_4510_sessions.value 1
24
+ _pid_4529_sessions.value 1
25
+ _pid_4548_sessions.value 1
26
+ _pid_4567_sessions.value 1
27
+ EOF
28
+ end
29
+
30
+ it "gives the ram configuration" do
31
+ expect(MuninPassenger::Graphs.ram_config).to eq <<-EOF
32
+ graph_category passenger
33
+ graph_title Passenger memory usage
34
+ graph_vlabel Bytes
35
+ _pid_4510_ram.label PID 4510
36
+ _pid_4529_ram.label PID 4529
37
+ _pid_4548_ram.label PID 4548
38
+ _pid_4567_ram.label PID 4567
39
+ EOF
40
+ end
41
+
42
+ it "gives the ram values" do
43
+ expect(MuninPassenger::Graphs.ram_values).to eq <<-EOF
44
+ _pid_4510_ram.value #{40400 * 1024}
45
+ _pid_4529_ram.value #{24396 * 1024}
46
+ _pid_4548_ram.value #{24268 * 1024}
47
+ _pid_4567_ram.value #{23872 * 1024}
48
+ EOF
49
+ end
50
+
51
+ it "gives the cpu configuration" do
52
+ expect(MuninPassenger::Graphs.cpu_config).to eq <<-EOF
53
+ graph_category passenger
54
+ graph_title Passenger CPU
55
+ graph_vlabel %
56
+ _pid_4510_cpu.label PID 4510
57
+ _pid_4529_cpu.label PID 4529
58
+ _pid_4548_cpu.label PID 4548
59
+ _pid_4567_cpu.label PID 4567
60
+ EOF
61
+ end
62
+
63
+ it "gives the cpu values" do
64
+ expect(MuninPassenger::Graphs.cpu_values).to eq <<-EOF
65
+ _pid_4510_cpu.value 2
66
+ _pid_4529_cpu.value 3
67
+ _pid_4548_cpu.value 2
68
+ _pid_4567_cpu.value 2
69
+ EOF
70
+ end
71
+
72
+ it "gives the processed configuration" do
73
+ expect(MuninPassenger::Graphs.processed_config).to eq <<-EOF
74
+ graph_category passenger
75
+ graph_title Requests processed
76
+ graph_vlabel Requests
77
+ _pid_4510_processed.label PID 4510
78
+ _pid_4529_processed.label PID 4529
79
+ _pid_4548_processed.label PID 4548
80
+ _pid_4567_processed.label PID 4567
81
+ EOF
82
+ end
83
+
84
+ it "gives the processed values" do
85
+ expect(MuninPassenger::Graphs.processed_values).to eq <<-EOF
86
+ _pid_4510_processed.value 139
87
+ _pid_4529_processed.value 138
88
+ _pid_4548_processed.value 138
89
+ _pid_4567_processed.value 138
90
+ EOF
91
+ end
92
+
93
+ it "gives the uptime configuration" do
94
+ expect(MuninPassenger::Graphs.uptime_config).to eq <<-EOF
95
+ graph_category passenger
96
+ graph_title Uptime
97
+ graph_vlabel Hours
98
+ _pid_4510_uptime.label PID 4510
99
+ _pid_4529_uptime.label PID 4529
100
+ _pid_4548_uptime.label PID 4548
101
+ _pid_4567_uptime.label PID 4567
102
+ EOF
103
+ end
104
+
105
+ it "gives the uptime values" do
106
+ Timecop.travel('Thu Sep 13 20:36:38 PDT 2018') do
107
+ expect(MuninPassenger::Graphs.uptime_values).to eq <<-EOF
108
+ _pid_4510_uptime.value 9.369166666666667
109
+ _pid_4529_uptime.value 9.368888888888888
110
+ _pid_4548_uptime.value 9.368888888888888
111
+ _pid_4567_uptime.value 9.368888888888888
112
+ EOF
113
+ end
114
+ end
115
+
116
+ it "gives the last_used configuration" do
117
+ expect(MuninPassenger::Graphs.last_used_config).to eq <<-EOF
118
+ graph_category passenger
119
+ graph_title Last used
120
+ graph_vlabel Seconds
121
+ _pid_4510_last_used.label PID 4510
122
+ _pid_4529_last_used.label PID 4529
123
+ _pid_4548_last_used.label PID 4548
124
+ _pid_4567_last_used.label PID 4567
125
+ EOF
126
+ end
127
+
128
+ it "gives the last_used values" do
129
+ Timecop.travel('Thu Sep 13 20:36:38 PDT 2018') do
130
+ expect(MuninPassenger::Graphs.last_used_values).to eq <<-EOF
131
+ _pid_4510_last_used.value 33697
132
+ _pid_4529_last_used.value 33697
133
+ _pid_4548_last_used.value 33697
134
+ _pid_4567_last_used.value 33697
135
+ EOF
136
+ end
137
+ end
138
+
139
+ end
@@ -0,0 +1,15 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter %r{^/spec/}
4
+ end
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'rspec'
9
+ require 'rspec/matchers'
10
+ require 'munin_passenger'
11
+ require 'timecop'
12
+
13
+ RSpec.configure do |config|
14
+
15
+ end