Class: Typhon

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

Defined Under Namespace

Classes: Config, Heads, Log, 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.



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

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.



49
50
51
# File 'lib/typhon.rb', line 49

def heads
  @heads
end

Class Method Details

.daemonizeObject



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

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



16
17
18
# File 'lib/typhon.rb', line 16

def files
    Heads.heads.keys
end

.grow(options, &blk) ⇒ Object



20
21
22
23
24
25
# File 'lib/typhon.rb', line 20

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



12
13
14
# File 'lib/typhon.rb', line 12

def heads
    Heads.heads
end

.stompObject



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

def stomp
    @stomp
end

.stomp=(stomp) ⇒ Object



27
28
29
# File 'lib/typhon.rb', line 27

def stomp=(stomp)
    @stomp = stomp
end

Instance Method Details

#tailObject



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

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