metrics_machine 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/statsd.yml +7 -0
- data/lib/metrics_machine.rb +29 -28
- data/lib/metrics_machine/monitor.rb +13 -2
- data/lib/metrics_machine/mysql.rb +10 -9
- data/lib/metrics_machine/railtie.rb +4 -10
- data/lib/metrics_machine/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d63e2c33f29fd0071d4475d746503353ad13bcb3
|
4
|
+
data.tar.gz: c9dee614e7817bef5e0b91a2bc620983b54134eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a69a717a85bff5f6965e787a83236e36f3285bc0f747949916743b5cae7bdbcb298374edebec0d78f63da59e3c3639bf9d12e2eb90840393568f8c08ec277282
|
7
|
+
data.tar.gz: 681f7fdacd6e60f680559054408dab40eae050646fb368987511c8ad3f12d06ae9c5b24053d4f1f168f9460f2bc1e0370b9e23c58d8b241a4923bb215305409b
|
data/config/statsd.yml
ADDED
data/lib/metrics_machine.rb
CHANGED
@@ -2,37 +2,41 @@ require "metrics_machine/version"
|
|
2
2
|
require "metrics_machine/monitor"
|
3
3
|
require "statsd"
|
4
4
|
require "eventmachine"
|
5
|
+
require "erb"
|
5
6
|
require "psych"
|
6
7
|
|
7
8
|
module MetricsMachine
|
8
9
|
autoload :Monitor, "metrics_machine/monitor"
|
9
|
-
|
10
|
+
require "metrics_machine/railtie" if defined? Rails
|
11
|
+
autoload :Mysql, "metrics_machine/mysql"
|
10
12
|
|
11
13
|
def self.start options = {}, &block
|
14
|
+
monitor.configure &block if block_given?
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
p = lambda { EM.run { monitor.run! } }
|
17
|
+
if defined?(PhusionPassenger)
|
18
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
19
|
+
if forked && EM.reactor_running?
|
20
|
+
EM.stop
|
21
|
+
end
|
22
|
+
|
23
|
+
Thread.new &p
|
24
|
+
die_gracefully_on_signal
|
25
|
+
end
|
26
|
+
else
|
27
|
+
# faciliates debugging
|
28
|
+
Thread.abort_on_exception = true
|
29
|
+
# just spawn a thread and start it up
|
30
|
+
Thread.new &p
|
31
|
+
end
|
32
|
+
end
|
29
33
|
|
30
|
-
|
31
|
-
|
34
|
+
def self.monitor
|
35
|
+
@monitor ||= Monitor.new reporter
|
32
36
|
end
|
33
37
|
|
34
|
-
def self.configure
|
35
|
-
|
38
|
+
def self.configure &block
|
39
|
+
monitor.configure &block
|
36
40
|
end
|
37
41
|
|
38
42
|
def self.die_gracefully_on_signal
|
@@ -47,14 +51,14 @@ module MetricsMachine
|
|
47
51
|
private
|
48
52
|
def self.reporter_config
|
49
53
|
@reporter_config ||= begin
|
50
|
-
path = if
|
54
|
+
path = if defined? Rails and File.exists? "#{Rails.root}/config/statsd.yml"
|
51
55
|
"#{Rails.root}/config/statsd.yml"
|
52
56
|
else
|
53
|
-
File.expand_path(File.join(File.dirname(__FILE__), "..", "
|
57
|
+
File.expand_path(File.join(File.dirname(__FILE__), "..", "config", "statsd.yml"))
|
54
58
|
end
|
55
|
-
data = Psych.
|
59
|
+
data = Psych.load(ERB.new(IO.read(path)).result(binding))
|
56
60
|
|
57
|
-
if
|
61
|
+
if defined? Rails
|
58
62
|
data[Rails.env]
|
59
63
|
else
|
60
64
|
data["default"]
|
@@ -62,7 +66,4 @@ module MetricsMachine
|
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
65
|
-
def self.has_rails?
|
66
|
-
const_defined? "Rails"
|
67
|
-
end
|
68
69
|
end
|
@@ -4,14 +4,25 @@ require 'active_support/inflector/transliterate'
|
|
4
4
|
module MetricsMachine
|
5
5
|
class Monitor
|
6
6
|
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :monitors, :reporter
|
8
8
|
|
9
9
|
def initialize reporter, options = {}, &block
|
10
10
|
@reporter = reporter
|
11
11
|
@monitors = {}
|
12
12
|
@prefix = options.fetch(:prefix, self.class.default_prefix)
|
13
|
+
configure &block if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def prefix *args
|
17
|
+
if args.empty?
|
18
|
+
@prefix
|
19
|
+
else
|
20
|
+
@prefix = args.first
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def configure &block
|
13
25
|
instance_eval &block
|
14
|
-
run!
|
15
26
|
end
|
16
27
|
|
17
28
|
def run!
|
@@ -1,21 +1,22 @@
|
|
1
1
|
module MetricsMachine
|
2
2
|
class Mysql
|
3
|
-
INTERVAL = 15
|
4
3
|
|
5
|
-
attr_reader :
|
4
|
+
attr_reader :base, :options
|
6
5
|
|
7
|
-
def initialize
|
6
|
+
def initialize base, *args
|
8
7
|
@options = args.extract_options!
|
9
|
-
@
|
8
|
+
@base = base
|
10
9
|
end
|
11
10
|
|
12
11
|
def interval
|
13
|
-
|
12
|
+
15
|
14
13
|
end
|
15
14
|
|
16
15
|
def statistics
|
17
|
-
|
18
|
-
|
16
|
+
status = fetch_status
|
17
|
+
|
18
|
+
status.each do |k,v|
|
19
|
+
status[k] = case v
|
19
20
|
when "OFF", "NULL", "NONE"
|
20
21
|
0
|
21
22
|
when "ON", "TRUE"
|
@@ -29,11 +30,11 @@ module MetricsMachine
|
|
29
30
|
private
|
30
31
|
|
31
32
|
def fetch_status
|
32
|
-
Hash[*connection.execute("SHOW GLOBAL STATUS").map.to_a.flatten]
|
33
|
+
Hash[*base.connection.execute("SHOW GLOBAL STATUS").map.to_a.flatten]
|
33
34
|
end
|
34
35
|
|
35
36
|
def fetch_variables
|
36
|
-
Hash[*connection.execute("SHOW GLOBAL VARIABLES").map.to_a.flatten]
|
37
|
+
Hash[*base.connection.execute("SHOW GLOBAL VARIABLES").map.to_a.flatten]
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -1,16 +1,10 @@
|
|
1
1
|
module MetricsMachine
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
|
4
|
-
if Rails.env.production?
|
5
|
-
initializer "metricsmachine.
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
initializer "metricsmachine.configure_rails_initialization" do
|
12
|
-
MetricsMachine.configure do
|
13
|
-
monitor :mysql, ActiveRecord::Base.connection if ActiveRecord::Base.connection.is_a? ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
4
|
+
if Rails.env.production? || ENV['METRICS'] == "true"
|
5
|
+
initializer "metricsmachine.initialization" do
|
6
|
+
MetricsMachine.start do
|
7
|
+
monitor :mysql, ActiveRecord::Base if ActiveRecord::Base.connection.is_a? ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
14
8
|
end
|
15
9
|
end
|
16
10
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metrics_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: statsd-ruby
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- LICENSE.txt
|
109
109
|
- README.md
|
110
110
|
- Rakefile
|
111
|
+
- config/statsd.yml
|
111
112
|
- lib/metrics_machine.rb
|
112
113
|
- lib/metrics_machine/monitor.rb
|
113
114
|
- lib/metrics_machine/mysql.rb
|