### Home Classes Methods

### In Files

- lib/phusion_passenger/analytics_logger.rb

### Parent

Object

### Namespace

- CLASS PhusionPassenger::AnalyticsLogger::Connection
- CLASS PhusionPassenger::AnalyticsLogger::Lock
- CLASS PhusionPassenger::AnalyticsLogger::Log

### Methods

- ::new
- ::new_from_options
- #clear_connection
- #close
- #continue_transaction
- #new_transaction

### Included Modules

- PhusionPassenger::Utils

### 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::AnalyticsLogger

### Constants

NETWORK_ERRORS
RANDOM_CHARS
RETRY_SLEEP

### Attributes

max_connect_tries[RW]
reconnect_timeout[RW]

### Public Class Methods

new(logging_agent_address, username, password, node_name) click to toggle source

    # File lib/phusion_passenger/analytics_logger.rb, line 186
    def initialize(logging_agent_address, username, password, node_name)
            @server_address = logging_agent_address
            @username = username
            @password = password
            if node_name && !node_name.empty?
                    @node_name = node_name
            else
                    @node_name = `hostname`.strip
            end
            @random_dev = File.open("/dev/urandom")

            # This mutex protects the following instance variables, but
            # not the contents of @connection.
            @mutex = Mutex.new

            @connection = Connection.new(nil)
            if @server_address && local_socket_address?(@server_address)
                    @max_connect_tries = 10
            else
                    @max_connect_tries = 1
            end
            @reconnect_timeout = 1
            @next_reconnect_time = Time.utc(1980, 1, 1)
    end

new_from_options(options) click to toggle source

    # File lib/phusion_passenger/analytics_logger.rb, line 172
    def self.new_from_options(options)
            if options["analytics"] && options["logging_agent_address"]
                    return new(options["logging_agent_address"],
                            options["logging_agent_username"],
                            options["logging_agent_password"],
                            options["node_name"])
            else
                    return nil
            end
    end

### Public Instance Methods

clear_connection() click to toggle source

    # File lib/phusion_passenger/analytics_logger.rb, line 211
    def clear_connection
            @mutex.synchronize do
                    @connection.synchronize do
                            @random_dev = File.open("/dev/urandom") if @random_dev.closed?
                            @connection.unref
                            @connection = Connection.new(nil)
                    end
            end
    end

close() click to toggle source

    # File lib/phusion_passenger/analytics_logger.rb, line 221
    def close
            @mutex.synchronize do
                    @connection.synchronize do
                            @random_dev.close
                            @connection.unref
                            @connection = nil
                    end
            end
    end

continue_transaction(txn_id, group_name, category = :requests, union_station_key = nil) click to toggle source

    # File lib/phusion_passenger/analytics_logger.rb, line 290
    def continue_transaction(txn_id, group_name, category = :requests, union_station_key = nil)
            if !@server_address
                    return Log.new
            elsif !txn_id || txn_id.empty?
                    raise ArgumentError, "Transaction ID may not be empty"
            end

            Lock.new(@mutex).synchronize do |lock|
                    if current_time < @next_reconnect_time
                            return Log.new
                    end

                    Lock.new(@connection.mutex).synchronize do |connection_lock|
                            if !@connection.connected?
                                    begin
                                            connect
                                            connection_lock.reset(@connection.mutex)
                                    rescue SystemCallError, IOError
                                            @connection.disconnect
                                            DebugLogging.warn("Cannot connect to the logging agent at #{@server_address}; " +
                                                    "retrying in #{@reconnect_timeout} second(s).")
                                            @next_reconnect_time = current_time + @reconnect_timeout
                                            return Log.new
                                    rescue Exception => e
                                            @connection.disconnect
                                            raise e
                                    end
                            end

                            begin
                                    @connection.channel.write("openTransaction",
                                            txn_id, group_name, "", category,
                                            AnalyticsLogger.timestamp_string,
                                            union_station_key,
                                            true)
                                    return Log.new(@connection, txn_id)
                            rescue SystemCallError, IOError
                                    @connection.disconnect
                                    DebugLogging.warn("The logging agent at #{@server_address}" <<
                                            " closed the connection; will reconnect in " <<
                                            "#{@reconnect_timeout} second(s).")
                                    @next_reconnect_time = current_time + @reconnect_timeout
                                    return Log.new
                            rescue Exception => e
                                    @connection.disconnect
                                    raise e
                            end
                    end
            end
    end

new_transaction(group_name, category = :requests, union_station_key = nil) click to toggle source

    # File lib/phusion_passenger/analytics_logger.rb, line 231
    def new_transaction(group_name, category = :requests, union_station_key = nil)
            if !@server_address
                    return Log.new
            elsif !group_name || group_name.empty?
                    raise ArgumentError, "Group name may not be empty"
            end

            txn_id = (AnalyticsLogger.current_time.to_i / 60).to_s(36)
            txn_id << "-#{random_token(11)}"

            Lock.new(@mutex).synchronize do |lock|
                    if current_time < @next_reconnect_time
                            return Log.new
                    end

                    Lock.new(@connection.mutex).synchronize do |connection_lock|
                            if !@connection.connected?
                                    begin
                                            connect
                                            connection_lock.reset(@connection.mutex)
                                    rescue SystemCallError, IOError
                                            @connection.disconnect
                                            DebugLogging.warn("Cannot connect to the logging agent at #{@server_address}; " +
                                                    "retrying in #{@reconnect_timeout} second(s).")
                                            @next_reconnect_time = current_time + @reconnect_timeout
                                            return Log.new
                                    rescue Exception => e
                                            @connection.disconnect
                                            raise e
                                    end
                            end

                            begin
                                    @connection.channel.write("openTransaction",
                                            txn_id, group_name, "", category,
                                            AnalyticsLogger.timestamp_string,
                                            union_station_key,
                                            true,
                                            true)
                                    result = @connection.channel.read
                                    if result != ["ok"]
                                            raise "Expected logging server to respond with 'ok', but got #{result.inspect} instead"
                                    end
                                    return Log.new(@connection, txn_id)
                            rescue SystemCallError, IOError
                                    @connection.disconnect
                                    DebugLogging.warn("The logging agent at #{@server_address}" <<
                                            " closed the connection; will reconnect in " <<
                                            "#{@reconnect_timeout} second(s).")
                                    @next_reconnect_time = current_time + @reconnect_timeout
                                    return Log.new
                            rescue Exception => e
                                    @connection.disconnect
                                    raise e
                            end
                    end
            end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.