Class: Takwimu::Instruments::PassengerStats
- Inherits:
-
Object
- Object
- Takwimu::Instruments::PassengerStats
- Defined in:
- lib/takwimu/instruments/passenger_stats.rb
Constant Summary collapse
- PROCESS_ELEMENTS =
%w(concurrency sessions busyness processed rss pss private_dirty swap real_memory cpu vmsize)
Instance Method Summary collapse
-
#initialize(sample_rate = nil) ⇒ PassengerStats
constructor
A new instance of PassengerStats.
- #instrument!(state, counters, gauges, timers) ⇒ Object
- #json_stats ⇒ Object
- #start!(state) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(sample_rate = nil) ⇒ PassengerStats
Returns a new instance of PassengerStats.
9 10 |
# File 'lib/takwimu/instruments/passenger_stats.rb', line 9 def initialize(sample_rate=nil) end |
Instance Method Details
#instrument!(state, counters, gauges, timers) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/takwimu/instruments/passenger_stats.rb', line 54 def instrument!(state, counters, gauges, timers) Takwimu.config.logger.debug "Takwimu.PassengerStats.instrument!" if Takwimu.config.logger stats = self.json_stats Takwimu.config.logger.debug "Takwimu.PassengerStats.instrument! Stats - #{stats.inspect}" if Takwimu.config.logger return if stats.empty? gauges[:"passenger.process_count"] = stats[:process_count] gauges[:"passenger.max_pool_size"] = stats[:max_pool_size] gauges[:"passenger.capacity_used"] = stats[:capacity_used] gauges[:"passenger.top_level_queue"] = stats[:top_level_queue] stats[:processes].each_with_index do |process, i| PROCESS_ELEMENTS.each do |element| gauges[:"passenger.process.#{i}.#{element}"] = process[element.to_sym] end end end |
#json_stats ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/takwimu/instruments/passenger_stats.rb', line 21 def json_stats doc = Nokogiri::XML(`sudo /usr/sbin/passenger-status --show=xml`) Takwimu.config.logger.error "Takwimu.json_stats - doc.blank? = #{doc.blank?}" if Takwimu.config.logger return {} if doc.blank? stats = { process_count: doc.xpath('//process_count').children[0].to_s, max_pool_size: doc.xpath('//max').children[0].to_s, capacity_used: doc.xpath('//capacity_used').children[0].to_s, top_level_queue: doc.xpath('//get_wait_list_size').children[0].to_s, processes: [] } doc.xpath('//supergroups')[0].xpath('./supergroup').each do |supergroup| supergroup.xpath('./group/processes/process').each_with_index do |process, i| process_element = {} PROCESS_ELEMENTS.each do |element| process_element[element.to_sym] = process.xpath("./#{element}").children[0].to_s end stats[:processes][i] = process_element end end return stats rescue StandardError => e #raise e unless e.message =~ /nil/ #raise e unless e.message =~ /stats/ Takwimu.config.logger.error "Takwimu.PassengerStats #{e.}" if Takwimu.config.logger Takwimu.config.logger.error "Takwimu.PassengerStats #{e.backtrace.inspect}" if Takwimu.config.logger return {} end |
#start!(state) ⇒ Object
16 17 18 19 |
# File 'lib/takwimu/instruments/passenger_stats.rb', line 16 def start!(state) require 'nokogiri' require 'open-uri' end |
#valid? ⇒ Boolean
12 13 14 |
# File 'lib/takwimu/instruments/passenger_stats.rb', line 12 def valid? defined?(PhusionPassenger) end |