This file is indexed.

/usr/sbin/passenger-memory-stats is in passenger 5.0.27-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 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
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/ruby
#  Phusion Passenger - https://www.phusionpassenger.com/
#  Copyright (c) 2010-2015 Phusion Holding B.V.
#
#  "Passenger", "Phusion Passenger" and "Union Station" are registered
#  trademarks of Phusion Holding B.V.
#
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#  THE SOFTWARE.

## Magic comment: begin bootstrap ##
require 'phusion_passenger'
## Magic comment: end bootstrap ##

PhusionPassenger.locate_directories
PhusionPassenger.require_passenger_lib 'platform_info'
PhusionPassenger.require_passenger_lib 'platform_info/ruby'
PhusionPassenger.require_passenger_lib 'admin_tools/memory_stats'
PhusionPassenger.require_passenger_lib 'utils/ansi_colors'

include PhusionPassenger

# Container for tabular data.
class Table
  def initialize(column_names, colors)
    @column_names = column_names
    @rows = []
    @colors = colors
  end

  def add_row(values)
    @rows << values.to_a
  end

  def add_rows(list_of_rows)
    list_of_rows.each do |row|
      add_row(row)
    end
  end

  def remove_column(name)
    i = @column_names.index(name)
    @column_names.delete_at(i)
    @rows.each do |row|
      row.delete_at(i)
    end
  end

  def to_s(title = nil)
    max_column_widths = [1] * @column_names.size
    (@rows + [@column_names]).each do |row|
      row.each_with_index do |value, i|
        max_column_widths[i] = [value.to_s.size, max_column_widths[i]].max
      end
    end

    format_string = max_column_widths.map{ |i| "%#{-i}s" }.join("  ")
    header = sprintf(format_string, *@column_names).rstrip << "\n"
    if title
      free_space = header.size - title.size - 2
      if free_space <= 0
        left_bar_size = 3
        right_bar_size = 3
      else
        left_bar_size = free_space / 2
        right_bar_size = free_space - left_bar_size
      end
      result = "#{@colors.blue_bg}#{@colors.bold}#{@colors.yellow}\n"
      result << "#{"-" * left_bar_size} #{title} #{"-" * right_bar_size}\n"
      if !@rows.empty?
        result << @colors.white
        result << header
      end
    else
      result = header.dup
    end
    if @rows.empty?
      result << @colors.reset
    else
      result << ("-" * header.size) << "#{@colors.reset}\n"
      @rows.each do |row|
        result << sprintf(format_string, *row).rstrip << "\n"
      end
    end
    result
  end
end

class App
  def initialize
    @stats = AdminTools::MemoryStats.new
    @colors = Utils::AnsiColors.new
  end

  def start
    puts "Version: #{PhusionPassenger::VERSION_STRING}"
    puts "Date   : #{Time.now}"
    if @stats.apache_processes
      print_process_list("Apache processes", @stats.apache_processes)
    else
      puts "#{@colors.blue_bg}#{@colors.bold}#{@colors.yellow}------------- Apache processes -------------#{@colors.reset}\n"
      STDERR.puts "*** WARNING: The Apache executable cannot be found."
      STDERR.puts "Please set the APXS2 environment variable to your 'apxs2' " <<
        "executable's filename, or set the HTTPD environment variable " <<
        "to your 'httpd' or 'apache2' executable's filename."
    end

    puts
    print_process_list("Nginx processes", @stats.nginx_processes)

    puts
    print_process_list("Passenger processes", @stats.passenger_processes, :show_ppid => false)

    if @stats.platform_provides_private_dirty_rss_information? &&
       Process.euid != 0 &&
       @stats.root_privileges_required_for_private_dirty_rss?
      puts "*** WARNING: Please run this tool with #{@colors.bold}#{PlatformInfo.ruby_sudo_command}#{@colors.reset}. Otherwise the " <<
        "private dirty RSS (a reliable metric for real memory usage) of processes cannot be determined."
    end
  end

private
  def print_process_list(title, processes, options = {})
    table = Table.new(%w{PID PPID VMSize Private Resident Name}, @colors)
    table.add_rows(processes)
    if options.has_key?(:show_ppid) && !options[:show_ppid]
      table.remove_column('PPID')
    end
    if @stats.platform_provides_private_dirty_rss_information?
      table.remove_column('Resident')
    else
      table.remove_column('Private')
    end
    puts table.to_s(title)

    if @stats.platform_provides_private_dirty_rss_information?
      total_private_dirty_rss = 0
      some_private_dirty_rss_cannot_be_determined = false
      processes.each do |p|
        if p.private_dirty_rss.is_a?(Numeric)
          total_private_dirty_rss += p.private_dirty_rss
        else
          some_private_dirty_rss_cannot_be_determined = true
        end
      end
      puts   "### Processes: #{processes.size}"
      printf "### Total private dirty RSS: %.2f MB", total_private_dirty_rss / 1024.0
      if some_private_dirty_rss_cannot_be_determined
        puts " (?)"
      else
        puts
      end
    end
  end
end

App.new.start