mettric 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mettric/client.rb +18 -2
- data/lib/mettric/errors.rb +7 -4
- data/lib/mettric/mettric.rb +17 -0
- data/lib/mettric/scnr.rb +11 -0
- data/lib/mettric/sidekiq_middleware.rb +21 -0
- data/lib/mettric/version.rb +1 -1
- data/lib/mettric/worker.rb +1 -1
- data/lib/mettric.rb +2 -1
- metadata +4 -3
- data/lib/mettric/thermometer.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2af9edc95eb1c3558bb3423c92c17e7d7232c795
|
4
|
+
data.tar.gz: 4b6c218c4eb1622494cfa1c122b0880ea4e4097e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4603b57739d6dcb6bd1d3b72e7caf8fe26efdc4f89fc80fce2553aeb9f6e8db4940066335bbd0f79572d11957c5d6dae36904a29433f80c07c9414d6b17dca83
|
7
|
+
data.tar.gz: ee41d7cfbcd0f875d7123ee605a41003f53cdb5d7c3be90a5eeba9d20a4984075e5ae590902f096780fe02bdd3c4af31d0a765e63cc3d21f43dd2260b3d14a46
|
data/lib/mettric/client.rb
CHANGED
@@ -45,7 +45,7 @@ class Mettric::Client
|
|
45
45
|
def <<(payload)
|
46
46
|
@riemann.tcp << standardize_payload(payload)
|
47
47
|
rescue => e
|
48
|
-
|
48
|
+
track_exception(e, payload)
|
49
49
|
end
|
50
50
|
|
51
51
|
def [](*args)
|
@@ -62,17 +62,33 @@ class Mettric::Client
|
|
62
62
|
|
63
63
|
private
|
64
64
|
|
65
|
+
def track_exception(e, payload)
|
66
|
+
@riemann.tcp << { service: 'Mettric error', description: e.to_s }
|
67
|
+
return unless Kernel.const_defined?(:NewRelic)
|
68
|
+
NewRelic::Agent.notice_error(e, payload) rescue nil
|
69
|
+
end
|
70
|
+
|
65
71
|
def standardize_payload(payload)
|
66
|
-
out = payload
|
72
|
+
out = stringify(payload)
|
67
73
|
raise Mettric::MissingService, out if out[:service].blank?
|
74
|
+
|
68
75
|
out[:tags] ||= []
|
69
76
|
out[:tags] << 'mettric'
|
70
77
|
out[:tags] << env if env.present?
|
78
|
+
|
71
79
|
out[:host] = host
|
80
|
+
|
72
81
|
out[:service] = "#{app}.#{out[:service]}"
|
73
82
|
out
|
74
83
|
end
|
75
84
|
|
85
|
+
def stringify(payload)
|
86
|
+
out = payload.symbolize_keys
|
87
|
+
out.each do |k,v|
|
88
|
+
out[k] = v.to_s if v.is_a?(Symbol)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
76
92
|
def rails_app_name
|
77
93
|
return unless Kernel.const_defined?(:Rails)
|
78
94
|
Rails.application.class.parent.to_s.underscore
|
data/lib/mettric/errors.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
2
|
-
class Mettric::
|
3
|
-
|
4
|
-
class Mettric::
|
1
|
+
# So other people can recognize mettric errors
|
2
|
+
class Mettric::Error < StandardError; end
|
3
|
+
|
4
|
+
class Mettric::CouldNotStartWorkerThread < Mettric::Error; end
|
5
|
+
class Mettric::MissingAppName < Mettric::Error; end
|
6
|
+
class Mettric::MissingHostName < Mettric::Error; end
|
7
|
+
class Mettric::MissingService < Mettric::Error; end
|
data/lib/mettric/mettric.rb
CHANGED
@@ -19,6 +19,23 @@ class Mettric
|
|
19
19
|
QUEUE.size
|
20
20
|
end
|
21
21
|
|
22
|
+
def self.time(payload)
|
23
|
+
exception = nil
|
24
|
+
state = 'success'
|
25
|
+
start = Time.now
|
26
|
+
begin
|
27
|
+
yield
|
28
|
+
rescue => e
|
29
|
+
exception = e
|
30
|
+
state = 'failure'
|
31
|
+
end
|
32
|
+
payload[:service] = "#{payload[:service]} ms" unless payload[:service].to_s.end_with?(' ms')
|
33
|
+
payload[:metric] = ((Time.now - start) * 1000).to_i
|
34
|
+
payload[:tags] ||= []
|
35
|
+
payload[:tags] << 'timing'
|
36
|
+
track(payload)
|
37
|
+
end
|
38
|
+
|
22
39
|
def self.ensure_worker_running
|
23
40
|
return if worker_running?
|
24
41
|
LOCK.synchronize do
|
data/lib/mettric/scnr.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
class Mettric::SidekiqMiddleware
|
4
|
+
def initialize(_options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(worker, msg, queue)
|
8
|
+
service = "sidekiq.queue.#{queue}.workers.#{worker.class.name.underscore}",
|
9
|
+
Mettric.time(service: service, tags: ['sidekiq']) do
|
10
|
+
yield
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if Kernel.const_defined?(:Sidekiq)
|
16
|
+
Sidekiq.configure_server do |config|
|
17
|
+
config.server_middleware do |chain|
|
18
|
+
chain.add Mettric::SidekiqMiddleware
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/mettric/version.rb
CHANGED
data/lib/mettric/worker.rb
CHANGED
@@ -15,7 +15,7 @@ class Mettric::Worker
|
|
15
15
|
|
16
16
|
def loop
|
17
17
|
Mettric::Client.new(@config) do |client|
|
18
|
-
deliver(client, service: '
|
18
|
+
deliver(client, service: 'mettric.worker.start') rescue nil
|
19
19
|
while payload = @queue.pop
|
20
20
|
deliver(client, payload)
|
21
21
|
end
|
data/lib/mettric.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mettric
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jannis Hermanns
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -144,7 +144,8 @@ files:
|
|
144
144
|
- lib/mettric/client.rb
|
145
145
|
- lib/mettric/errors.rb
|
146
146
|
- lib/mettric/mettric.rb
|
147
|
-
- lib/mettric/
|
147
|
+
- lib/mettric/scnr.rb
|
148
|
+
- lib/mettric/sidekiq_middleware.rb
|
148
149
|
- lib/mettric/version.rb
|
149
150
|
- lib/mettric/worker.rb
|
150
151
|
- mettric.gemspec
|
data/lib/mettric/thermometer.rb
DELETED