Class: Liquid::Server
- Inherits:
-
Object
show all
- Defined in:
- lib/liquid/server.rb
Defined Under Namespace
Classes: HealthGauge, UptimeGauge
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Server
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/liquid/server.rb', line 13
def initialize
@started_at = Time.now
$log.info("#{name} #{RUBY_DESCRIPTION}")
$log.info("#{name}", env: Env.mode)
Signal.register_shutdown_handler { System.exit(0) }
Signal.register_shutdown_handler { ZContext.destroy }
initialize_raven
initialize_tracker
initialize_metrics
initialize_health_checks
end
|
Instance Attribute Details
#started_at ⇒ Object
Returns the value of attribute started_at.
7
8
9
|
# File 'lib/liquid/server.rb', line 7
def started_at
@started_at
end
|
Instance Method Details
#initialize_health_checks ⇒ Object
79
80
81
82
83
84
|
# File 'lib/liquid/server.rb', line 79
def initialize_health_checks
Thread.new do
Thread.name = "Health Check"
HealthCheck.poll
end
end
|
#initialize_metrics ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/liquid/server.rb', line 71
def initialize_metrics
::Metrics.start
::Metrics::TrackerReporter.new($tracker.with_topic('metrics'))
::Metrics.gauge("#{name}.healthy", HealthGauge.new)
::Metrics.gauge("#{name}.uptime", UptimeGauge.new(self))
Signal.register_shutdown_handler { ::Metrics.stop }
end
|
#initialize_raven ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/liquid/server.rb', line 25
def initialize_raven
return unless $conf.raven
require 'raven'
Raven.configure do |config|
config.dsn = $conf.raven.dsn
config.logger = $log
end
$log.add_exception_handler do |exc, message, attribs|
Raven.capture_exception(exc)
end
end
|
#initialize_tracker ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/liquid/server.rb', line 37
def initialize_tracker
if $conf.tracker.kafka.enabled
properties = java.util.Properties.new
properties['metadata.broker.list'] = $conf.tracker.kafka.brokers.join(',')
properties['producer.type'] = 'async'
properties['serializer.class'] = 'kafka.serializer.StringEncoder'
$tracker = ::Tracker::KafkaTracker.new(properties, $conf.tracker.dimensions)
else
$tracker = ::Tracker::LoggerTracker.new($conf.tracker.dimensions)
end
Signal.register_shutdown_handler { $tracker.shutdown }
end
|
#initialize_zmachine ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/liquid/server.rb', line 86
def initialize_zmachine
require 'zmachine'
ZMachine.logger = $log
ZMachine.debug = true if $conf.zmachine.debug
ZMachine.heartbeat_interval = 0.1
Signal.register_shutdown_handler { ZMachine.stop }
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/liquid/server.rb', line 9
def name
@name ||= self.class.name.downcase.gsub(/::/, '.')
end
|
#run ⇒ Object
94
95
96
97
|
# File 'lib/liquid/server.rb', line 94
def run
Thread.join
end
|
#uptime ⇒ Object
99
100
101
|
# File 'lib/liquid/server.rb', line 99
def uptime
Time.now - @started_at
end
|