typhon 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/typhon +0 -0
- data/lib/typhon.rb +23 -5
- data/lib/typhon/config.rb +1 -1
- data/lib/typhon/head.rb +4 -0
- data/lib/typhon/natsclient.rb +87 -0
- metadata +56 -49
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0f620a55bca225c8a321096fa493007e100bce1
|
4
|
+
data.tar.gz: 69c947a4ee7252d849af62550cf7b21d8bf27f8e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 444add8afafed466bf126d238256c34de2c8be811d8b081ac9d7704f972780cbb71c15789a369441f2afead0db8683cda86c3cc155580c5ccd13c5f60febaa19
|
7
|
+
data.tar.gz: 428c51446717bb049dddfcf5081cab70ec40fbd0cdc2f0ee42d01534c608744f0bbaec249ed5f31bbed27e4768c3f1c2628f4fe5806959e885d640321901405a
|
data/bin/typhon
CHANGED
File without changes
|
data/lib/typhon.rb
CHANGED
@@ -7,6 +7,7 @@ class Typhon
|
|
7
7
|
require 'typhon/log'
|
8
8
|
require 'typhon/config'
|
9
9
|
require 'typhon/stompclient'
|
10
|
+
require 'typhon/natsclient'
|
10
11
|
require 'typhon/ratelimit'
|
11
12
|
require 'typhon/head'
|
12
13
|
|
@@ -26,6 +27,14 @@ class Typhon
|
|
26
27
|
Heads.register_head(options[:name], options[:files], blk)
|
27
28
|
end
|
28
29
|
|
30
|
+
def nats=(nats)
|
31
|
+
@nats = nats
|
32
|
+
end
|
33
|
+
|
34
|
+
def nats
|
35
|
+
@nats
|
36
|
+
end
|
37
|
+
|
29
38
|
def stomp=(stomp)
|
30
39
|
@stomp = stomp
|
31
40
|
end
|
@@ -58,17 +67,26 @@ class Typhon
|
|
58
67
|
|
59
68
|
@heads = Heads.new
|
60
69
|
@stomp = nil
|
70
|
+
@nats = nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def start_nats
|
74
|
+
@nats = Typhon::NatsClient.new(Config[:nats])
|
75
|
+
Typhon.nats = @nats
|
76
|
+
end
|
77
|
+
|
78
|
+
def start_stomp
|
79
|
+
Log.debug("Connecting to Stomp Server %s:%d" % [ Config[:stomp][:server], Config[:stomp][:port] ])
|
80
|
+
@stomp = EM.connect Config[:stomp][:server], Config[:stomp][:port], Typhon::StompClient, {:auto_reconnect => true, :timeout => 2}
|
81
|
+
Typhon.stomp = @stomp
|
61
82
|
end
|
62
83
|
|
63
84
|
def tail
|
64
85
|
EM.run do
|
65
86
|
@heads.loadheads
|
66
87
|
|
67
|
-
if Config[:stomp]
|
68
|
-
|
69
|
-
@stomp = EM.connect Config[:stomp][:server], Config[:stomp][:port], Typhon::StompClient, {:auto_reconnect => true, :timeout => 2}
|
70
|
-
Typhon.stomp = @stomp
|
71
|
-
end
|
88
|
+
start_stomp if Config[:stomp]
|
89
|
+
start_nats if Config[:nats]
|
72
90
|
|
73
91
|
EM.add_periodic_timer(10) do
|
74
92
|
@heads.loadheads
|
data/lib/typhon/config.rb
CHANGED
@@ -2,7 +2,7 @@ class Typhon
|
|
2
2
|
class Config
|
3
3
|
include Enumerable
|
4
4
|
|
5
|
-
@settings = {:loglevel => :info, :stomp => false, :stat_log_frequency => 3600}
|
5
|
+
@settings = {:loglevel => :info, :stomp => false, :nats => false, :stat_log_frequency => 3600}
|
6
6
|
|
7
7
|
class << self
|
8
8
|
attr_reader :settings
|
data/lib/typhon/head.rb
CHANGED
@@ -0,0 +1,87 @@
|
|
1
|
+
require "nats/client"
|
2
|
+
|
3
|
+
class Typhon
|
4
|
+
class NatsClient
|
5
|
+
def initialize(options={})
|
6
|
+
@options = {
|
7
|
+
:max_reconnect_attempts => -1,
|
8
|
+
:reconnect_time_wait => 1,
|
9
|
+
:dont_randomize_servers => true,
|
10
|
+
:name => "typhon"
|
11
|
+
}.merge(options)
|
12
|
+
|
13
|
+
start
|
14
|
+
end
|
15
|
+
|
16
|
+
def publish(subject, message)
|
17
|
+
NATS.publish(subject, message)
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_client?
|
21
|
+
!!NATS.client
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
NATS.on_error do |e|
|
26
|
+
Log.error("Error in NATS connection: %s: %s" % [e.class, e.to_s])
|
27
|
+
|
28
|
+
backoff_sleep
|
29
|
+
|
30
|
+
raise(e)
|
31
|
+
end
|
32
|
+
|
33
|
+
NATS.start(@options) do |c|
|
34
|
+
Log.info("NATS is connected to %s" % c.connected_server)
|
35
|
+
log_nats_pool
|
36
|
+
|
37
|
+
c.on_reconnect do |connection|
|
38
|
+
Log.warn("Reconnected after connection failure: %s" % connection.connected_server)
|
39
|
+
log_nats_pool
|
40
|
+
@backoffcount = 1
|
41
|
+
end
|
42
|
+
|
43
|
+
c.on_disconnect do |reason|
|
44
|
+
Log.warn("Disconnected from NATS: %s" % reason)
|
45
|
+
end
|
46
|
+
|
47
|
+
c.on_close do
|
48
|
+
Log.info("Connection to NATS server closed")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
sleep(0.01) until has_client?
|
53
|
+
rescue
|
54
|
+
Log.error("Error during initial NATS setup: %s: %s" % [$!.class, $!.message])
|
55
|
+
Log.debug($!.backtrace.join("\n\t"))
|
56
|
+
|
57
|
+
sleep 1
|
58
|
+
|
59
|
+
Log.error("Retrying NATS initial setup")
|
60
|
+
|
61
|
+
retry
|
62
|
+
end
|
63
|
+
|
64
|
+
def backoff_sleep
|
65
|
+
@backoffcount ||= 1
|
66
|
+
|
67
|
+
if @backoffcount >= 50
|
68
|
+
sleep(2)
|
69
|
+
else
|
70
|
+
sleep(0.04 * @backoffcount)
|
71
|
+
end
|
72
|
+
|
73
|
+
@backoffcount += 1
|
74
|
+
end
|
75
|
+
|
76
|
+
def log_nats_pool
|
77
|
+
return unless NATS.client
|
78
|
+
|
79
|
+
servers = NATS.client.server_pool.map do |server|
|
80
|
+
server[:uri].to_s
|
81
|
+
end
|
82
|
+
|
83
|
+
Log.info("Current server pool: %s" % servers.join(", "))
|
84
|
+
rescue
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
CHANGED
@@ -1,74 +1,81 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: typhon
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- R.I.Pienaar
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
date: 2016-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nats
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: eventmachine-tail
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.6'
|
41
|
+
description: Single daemon that tails many files and route lines through your own
|
42
|
+
logic
|
23
43
|
email: rip@devco.net
|
24
|
-
executables:
|
44
|
+
executables:
|
25
45
|
- typhon
|
26
46
|
extensions: []
|
27
|
-
|
28
47
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
48
|
+
files:
|
31
49
|
- bin/typhon
|
50
|
+
- lib/typhon.rb
|
32
51
|
- lib/typhon/config.rb
|
33
|
-
- lib/typhon/
|
52
|
+
- lib/typhon/head.rb
|
34
53
|
- lib/typhon/heads.rb
|
54
|
+
- lib/typhon/log.rb
|
55
|
+
- lib/typhon/natsclient.rb
|
35
56
|
- lib/typhon/ratelimit.rb
|
36
|
-
- lib/typhon/head.rb
|
37
57
|
- lib/typhon/stompclient.rb
|
38
|
-
- lib/typhon.rb
|
39
|
-
has_rdoc: true
|
40
58
|
homepage: https://github.com/ripienaar/typhon/
|
41
59
|
licenses: []
|
42
|
-
|
60
|
+
metadata: {}
|
43
61
|
post_install_message:
|
44
62
|
rdoc_options: []
|
45
|
-
|
46
|
-
require_paths:
|
63
|
+
require_paths:
|
47
64
|
- lib
|
48
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
none: false
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
hash: 3
|
63
|
-
segments:
|
64
|
-
- 0
|
65
|
-
version: "0"
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
66
75
|
requirements: []
|
67
|
-
|
68
76
|
rubyforge_project:
|
69
|
-
rubygems_version:
|
77
|
+
rubygems_version: 2.0.14
|
70
78
|
signing_key:
|
71
|
-
specification_version:
|
79
|
+
specification_version: 4
|
72
80
|
summary: Wrapper around eventmachine-tail to make writing custom logtailers easy
|
73
81
|
test_files: []
|
74
|
-
|