Class: Typhon

Inherits:
Object
  • Object
show all
Defined in:
lib/typhon.rb,
lib/typhon/log.rb,
lib/typhon/head.rb,
lib/typhon/heads.rb,
lib/typhon/config.rb,
lib/typhon/ratelimit.rb,
lib/typhon/stompclient.rb

Defined Under Namespace

Classes: Config, Head, Heads, Log, RateLimit, StompClient

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = "/etc/typhon") ⇒ Typhon

Returns a new instance of Typhon.



53
54
55
56
57
58
59
60
61
# File 'lib/typhon.rb', line 53

def initialize(path="/etc/typhon")
  @configdir = path

  Config[:configdir] = path
  Config.loadconfig

  @heads = Heads.new
  @stomp = nil
end

Instance Attribute Details

#headsObject (readonly)

Returns the value of attribute heads.



51
52
53
# File 'lib/typhon.rb', line 51

def heads
  @heads
end

Class Method Details

.daemonizeObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/typhon.rb', line 37

def daemonize
  fork do
    Process.setsid
    exit if fork
    Dir.chdir('/tmp')
    STDIN.reopen('/dev/null')
    STDOUT.reopen('/dev/null', 'a')
    STDERR.reopen('/dev/null', 'a')

    yield
  end
end

.filesObject



18
19
20
# File 'lib/typhon.rb', line 18

def files
  Heads.heads.keys
end

.grow(options, &blk) ⇒ Object



22
23
24
25
26
27
# File 'lib/typhon.rb', line 22

def grow(options, &blk)
  raise "Heads need a name" unless options[:name]
  raise "Heads need files" unless options[:files]

  Heads.register_head(options[:name], options[:files], blk)
end

.headsObject



14
15
16
# File 'lib/typhon.rb', line 14

def heads
  Heads.heads
end

.stompObject



33
34
35
# File 'lib/typhon.rb', line 33

def stomp
  @stomp
end

.stomp=(stomp) ⇒ Object



29
30
31
# File 'lib/typhon.rb', line 29

def stomp=(stomp)
  @stomp = stomp
end

Instance Method Details

#tailObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/typhon.rb', line 63

def tail
  EM.run do
    @heads.loadheads

    if Config[:stomp]
      Log.debug("Connecting to Stomp Server %s:%d" % [ Config[:stomp][:server], Config[:stomp][:port] ])
      @stomp = EM.connect Config[:stomp][:server], Config[:stomp][:port], Typhon::StompClient, {:auto_reconnect => true, :timeout => 2}
      Typhon.stomp = @stomp
    end

    EM.add_periodic_timer(10) do
      @heads.loadheads
    end

    if Config[:stat_log_frequency] > 0
      EM.add_periodic_timer(Config[:stat_log_frequency]) do
        @heads.log_stats
      end
    end
  end
end