### Home Classes Methods

### In Files

- lib/phusion_passenger/admin_tools/memory_stats.rb

### Parent

Object

### Namespace

- CLASS PhusionPassenger::AdminTools::MemoryStats::Process

### Methods

- #apache_processes
- #nginx_processes
- #passenger_processes
- #platform_provides_private_dirty_rss_information?
- #root_privileges_required_for_private_dirty_rss?
- #should_show_private_dirty_rss?
- #sum_memory_usage
- #system_ram_usage

### Class/Module Index

Quicksearch

- PhusionPassenger
- PhusionPassenger::AbstractInstaller
- PhusionPassenger::AbstractInstaller::Abort
- PhusionPassenger::AbstractInstaller::CommandError
- PhusionPassenger::AdminTools
- PhusionPassenger::AdminTools::MemoryStats
- PhusionPassenger::AdminTools::MemoryStats::Process
- PhusionPassenger::AdminTools::ServerInstance
- PhusionPassenger::AdminTools::ServerInstance::CorruptedDirectoryError
- PhusionPassenger::AdminTools::ServerInstance::GenerationsAbsentError
- PhusionPassenger::AdminTools::ServerInstance::Group
- PhusionPassenger::AdminTools::ServerInstance::Process
- PhusionPassenger::AdminTools::ServerInstance::RoleDeniedError
- PhusionPassenger::AdminTools::ServerInstance::StaleDirectoryError
- PhusionPassenger::AdminTools::ServerInstance::Stats
- PhusionPassenger::AdminTools::ServerInstance::UnsupportedGenerationStructureVersionError
- PhusionPassenger::AnalyticsLogger
- PhusionPassenger::AnalyticsLogger::Connection
- PhusionPassenger::AnalyticsLogger::Lock
- PhusionPassenger::AnalyticsLogger::Log
- PhusionPassenger::ClassicRails
- PhusionPassenger::ClassicRails::CGIFixed
- PhusionPassenger::ClassicRails::ThreadHandlerExtension
- PhusionPassenger::ConsoleTextTemplate
- PhusionPassenger::DebugLogging
- PhusionPassenger::LoaderSharedHelpers
- PhusionPassenger::MessageChannel
- PhusionPassenger::MessageChannel::InvalidHashError
- PhusionPassenger::MessageClient
- PhusionPassenger::NativeSupportLoader
- PhusionPassenger::Packaging
- PhusionPassenger::PlatformInfo
- PhusionPassenger::PlatformInfo::ApacheDetector
- PhusionPassenger::PlatformInfo::ApacheDetector::Result
- PhusionPassenger::PlatformInfo::Depcheck
- PhusionPassenger::PlatformInfo::Depcheck::ConsoleRunner
- PhusionPassenger::PlatformInfo::Depcheck::Dependency
- PhusionPassenger::PlatformInfo::RuntimeError
- PhusionPassenger::Plugin
- PhusionPassenger::PreloaderSharedHelpers
- PhusionPassenger::Rack
- PhusionPassenger::Rack::OutOfBandGc
- PhusionPassenger::Rack::ThreadHandlerExtension
- PhusionPassenger::Rails3Extensions
- PhusionPassenger::Rails3Extensions::AnalyticsLogging
- PhusionPassenger::Rails3Extensions::AnalyticsLogging::ACExtension
- PhusionPassenger::Rails3Extensions::AnalyticsLogging::ASBenchmarkableExtension
- PhusionPassenger::Rails3Extensions::AnalyticsLogging::ExceptionLogger
- PhusionPassenger::RequestHandler
- PhusionPassenger::RequestHandler::ThreadHandler
- PhusionPassenger::RequestHandler::ThreadHandler::Interrupted
- PhusionPassenger::SharedConstants
- PhusionPassenger::Standalone
- PhusionPassenger::Standalone::AppFinder
- PhusionPassenger::Standalone::Command
- PhusionPassenger::Standalone::ConfigFile
- PhusionPassenger::Standalone::ConfigFile::DisallowedContextError
- PhusionPassenger::Standalone::HelpCommand
- PhusionPassenger::Standalone::Main
- PhusionPassenger::Standalone::PackageRuntimeCommand
- PhusionPassenger::Standalone::RuntimeInstaller
- PhusionPassenger::Standalone::RuntimeLocator
- PhusionPassenger::Standalone::StartCommand
- PhusionPassenger::Standalone::StatusCommand
- PhusionPassenger::Standalone::StopCommand
- PhusionPassenger::Standalone::Utils
- PhusionPassenger::Standalone::VersionCommand
- PhusionPassenger::Utils
- PhusionPassenger::Utils::AnsiColors
- PhusionPassenger::Utils::FileSystemWatcher
- PhusionPassenger::Utils::FileSystemWatcher::DirInfo
- PhusionPassenger::Utils::FileSystemWatcher::FileInfo
- PhusionPassenger::Utils::GeneratorTest
- PhusionPassenger::Utils::HostsFileParser
- PhusionPassenger::Utils::JSON
- PhusionPassenger::Utils::JSON::Generator
- PhusionPassenger::Utils::ParserTest
- PhusionPassenger::Utils::TeeInput
- PhusionPassenger::Utils::TmpIO
- PhusionPassenger::Utils::UnseekableSocket
- CommonLibraryBuilder
- Exception
- GC
- IO
- Object
- Signal

No matching classes.

# PhusionPassenger::AdminTools::MemoryStats

### Public Instance Methods

apache_processes() click to toggle source

Returns a list of Apache processes, which may be the empty list if Apache is not running. If the Apache executable name is unknown then nil will be returned.

    # File lib/phusion_passenger/admin_tools/memory_stats.rb, line 64
    def apache_processes
            @apache_processes ||= begin
                    if PlatformInfo.httpd
                            processes = list_processes(:exe => PlatformInfo.httpd)
                            if processes.empty?
                                    # On some Linux distros, the Apache worker processes
                                    # are called "httpd.worker"
                                    processes = list_processes(:exe => "#{PlatformInfo.httpd}.worker")
                            end
                            processes
                    else
                            nil
                    end
            end
    end

nginx_processes() click to toggle source

Returns a list of Nginx processes, which may be the empty list if Nginx is not running.

    # File lib/phusion_passenger/admin_tools/memory_stats.rb, line 82
    def nginx_processes
            @nginx_processes ||= list_processes(:exe => "nginx")
    end

passenger_processes() click to toggle source

Returns a list of Phusion Passenger processes, which may be the empty list if Phusion Passenger is not running.

    # File lib/phusion_passenger/admin_tools/memory_stats.rb, line 88
    def passenger_processes
            @passenger_processes ||= list_processes(:match =>
                    /((^| )Passenger |(^| )Rails:|(^| )Rack:|PassengerHelperAgent|PassengerWatchdog|PassengerLoggingAgent|wsgi-loader.py)/)
    end

platform_provides_private_dirty_rss_information?() click to toggle source

    # File lib/phusion_passenger/admin_tools/memory_stats.rb, line 117
    def platform_provides_private_dirty_rss_information?
            return ruby_platform =~ /linux/
    end

root_privileges_required_for_private_dirty_rss?() click to toggle source

Returns whether root privileges are required in order to measure private dirty RSS. Only meaningful if platform_provides_private_dirty_rss_information? returns true.

    # File lib/phusion_passenger/admin_tools/memory_stats.rb, line 123
    def root_privileges_required_for_private_dirty_rss?
            all_processes = (apache_processes || []) + nginx_processes + passenger_processes
            return all_processes.any?{ |p| p.private_dirty_rss.nil? }
    end

should_show_private_dirty_rss?() click to toggle source

    # File lib/phusion_passenger/admin_tools/memory_stats.rb, line 128
    def should_show_private_dirty_rss?
            return platform_provides_private_dirty_rss_information? &&
                    (::Process.euid == 0 || root_privileges_required_for_private_dirty_rss?)
    end

sum_memory_usage(processes) click to toggle source

Returns the sum of the memory usages of all given processes. Returns a pair [usage, accurate]. `usage` is the summed memory usage in KB, and `accurate` indicates whether this sum is accurate. This may be false if some process's memory usage cannot be determined.

    # File lib/phusion_passenger/admin_tools/memory_stats.rb, line 97
    def sum_memory_usage(processes)
            total = 0
            if should_show_private_dirty_rss?
                    accurate = true
                    processes.each do |p|
                            if p.private_dirty_rss.is_a?(Numeric)
                                    total += p.private_dirty_rss
                            else
                                    accurate = true
                            end
                    end
                    return [total, accurate]
            else
                    processes.each do |p|
                            total += p.rss
                    end
                    return [total, true]
            end
    end

system_ram_usage() click to toggle source

Determine the system's RAM usage, not including swap. Returns a tuple [total, used] where both numbers are in KB, or nil if the system's RAM usage cannot be determined.

    # File lib/phusion_passenger/admin_tools/memory_stats.rb, line 136
    def system_ram_usage
            @total_system_ram ||= begin
                    case ruby_platform
                    when /linux/
                            free_text = `free -k`

                            free_text =~ %{Mem:(.+)$}
                            line = $1.strip
                            total = line.split(/ +/).first.to_i

                            free_text =~ %{buffers/cache:(.+)$}
                            line = $1.strip
                            used = line.split(/ +/).first.to_i

                            [total, used]
                    when /darwin/
                            vm_stat = `vm_stat`
                            vm_stat =~ /page size of (\d+) bytes/
                            page_size = $1
                            vm_stat =~ /Pages free: +(\d+)/
                            free = $1
                            vm_stat =~ /Pages active: +(\d+)/
                            active = $1
                            vm_stat =~ /Pages inactive: +(\d+)/
                            inactive = $1
                            vm_stat =~ /Pages wired down: +(\d+)/
                            wired = $1

                            if page_size && free && active && inactive && wired
                                    page_size = page_size.to_i
                                    free = free.to_i * page_size / 1024
                                    active = active.to_i * page_size / 1024
                                    inactive = inactive.to_i * page_size / 1024
                                    wired = wired.to_i * page_size / 1024

                                    used = active + wired
                                    [free + inactive + used, used]
                            else
                                    nil
                            end
                    else
                            `top` =~ /(\d+)(K|M) Active, (\d+)(K|M) Inact, (\d+)(K|M) Wired,.*?(\d+)(K|M) Free/
                            if $1 && $2 && $3 && $4 && $5 && $6 && $7 && $8
                                    to_kb = lambda do |number, unit|
                                            if unit == 'K'
                                                    number.to_i
                                            else
                                                    number.to_i * 1024
                                            end
                                    end

                                    active = to_kb.call($1, $2)
                                    inactive = to_kb.call($3, $4)
                                    wired = to_kb.call($5, $6)
                                    free = to_kb.call($7, $8)

                                    used = active + wired
                                    [free + inactive + used, used]
                            else
                                    nil
                            end
                    end
            end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.