forked from jondot/vitals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitals.rb
75 lines (62 loc) · 1.58 KB
/
vitals.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require "vitals/version"
module Vitals
module Formats;end
module Reporters;end
module Integrations
module Notifications;end
end
end
require 'vitals/configuration'
require 'vitals/utils'
require 'vitals/reporters/base_reporter'
require 'vitals/reporters/inmem_reporter'
require 'vitals/reporters/console_reporter'
require 'vitals/reporters/multi_reporter'
require 'vitals/reporters/statsd_reporter'
require 'vitals/reporters/dns_resolving_statsd_reporter'
require 'vitals/formats/production_format'
require 'vitals/formats/host_last_format'
require 'vitals/formats/no_host_format'
module Vitals
def self.configure!
@config = Configuration.new
yield(@config) if block_given?
@reporter = @config.reporter
@reporter.format = @config.build_format
end
def self.reporter=(r)
@reporter = r
end
def self.reporter
@reporter
end
def self.subscribe!(*modules)
# give out a list of subscribers too
modules.map do |mod|
require "vitals/integrations/notifications/#{ mod }"
klass = Object.const_get("Vitals::Integrations::Notifications::#{classify(mod)}")
klass.subscribe!
end
end
#
# reporter delegators
#
# hardwired for performance
# (forwardable delegators go through __send__ and generate gc waste)
def self.inc(m)
reporter.inc(m)
end
def self.timing(m, val)
reporter.timing(m, val)
end
def self.count(m, val)
reporter.count(m, val)
end
def self.gauge(m, val)
reporter.gauge(m, val)
end
private
def self.classify(sym)
sym.to_s.split('_').collect!{ |w| w.capitalize }.join
end
end