Class: NginxStage::SocketFile

Inherits:
Object
  • Object
show all
Defined in:
lib/nginx_stage/socket_file.rb

Overview

A class describing a Unix domain socket

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ SocketFile

Returns a new instance of SocketFile.

Parameters:

  • socket (String)

    path to unix domain socket file

Raises:



11
12
13
14
15
16
# File 'lib/nginx_stage/socket_file.rb', line 11

def initialize(socket)
  @socket = socket
  raise MissingSocketFile, "missing socket file: #{socket}" unless File.exist?(socket)
  raise InvalidSocketFile, "invalid socket file: #{socket}" unless File.socket?(socket)
  @processes = get_processes
end

Instance Attribute Details

#socketString (readonly)

Path to Unix domain socket file

Returns:

  • (String)

    path to unix domain socket file



6
7
8
# File 'lib/nginx_stage/socket_file.rb', line 6

def socket
  @socket
end

Instance Method Details

#sessionsInteger

The number of active sessions connected to this socket

Returns:

  • (Integer)

    number of active connections



20
21
22
23
24
25
26
27
# File 'lib/nginx_stage/socket_file.rb', line 20

def sessions
  # generate array of inodes
  ary_inodes = @processes.map{|h| h[:inode]}.reduce([], :+)

  # count number of inodes without partner (assuming these are connected to
  # apache proxy instead of root nginx process)
  ary_inodes.group_by{|e| e}.select{|k,v| v.size == 1}.map(&:first).count
end

#to_sString

Convert object to string

Returns:

  • (String)

    path to socket file



31
32
33
# File 'lib/nginx_stage/socket_file.rb', line 31

def to_s
  socket
end