mettric 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a14cc6806c5c54cfd62ada74fd3bf38325393318
4
- data.tar.gz: eafe9169e9c89e39f5ca0fa16f98361d0a320a0b
3
+ metadata.gz: 2af9edc95eb1c3558bb3423c92c17e7d7232c795
4
+ data.tar.gz: 4b6c218c4eb1622494cfa1c122b0880ea4e4097e
5
5
  SHA512:
6
- metadata.gz: f61ebb4d42c205458746c5be9e6e6bfd9f31ec86ddba3b8b7c4359915985451d24c592d0cb661798f40e8c391d443d4ce7bb28c1b75382f30ec3537eb569d34d
7
- data.tar.gz: 31e9e31719392d09a31e805b3cdfa8e5aeda920987e70e106adf467526db0d78be1443bb5ab3ae715cbed972699849647b4be7d4ba3d0991f52a42ba40dec893
6
+ metadata.gz: 4603b57739d6dcb6bd1d3b72e7caf8fe26efdc4f89fc80fce2553aeb9f6e8db4940066335bbd0f79572d11957c5d6dae36904a29433f80c07c9414d6b17dca83
7
+ data.tar.gz: ee41d7cfbcd0f875d7123ee605a41003f53cdb5d7c3be90a5eeba9d20a4984075e5ae590902f096780fe02bdd3c4af31d0a765e63cc3d21f43dd2260b3d14a46
@@ -45,7 +45,7 @@ class Mettric::Client
45
45
  def <<(payload)
46
46
  @riemann.tcp << standardize_payload(payload)
47
47
  rescue => e
48
- @riemann.tcp << { service: 'Mettric error', description: e.to_s }
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.symbolize_keys
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
@@ -1,4 +1,7 @@
1
- class Mettric::CouldNotStartWorkerThread < StandardError; end
2
- class Mettric::MissingAppName < StandardError; end
3
- class Mettric::MissingHostName < StandardError; end
4
- class Mettric::MissingService < StandardError; end
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
@@ -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
@@ -0,0 +1,11 @@
1
+ # SCNR
2
+ def 🌡(payload)
3
+ Mettric.track(payload)
4
+ end
5
+
6
+ def ⏱(payload, &block)
7
+ Mettric.time(payload) do
8
+ block.call
9
+ end
10
+ end
11
+
@@ -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
@@ -1,3 +1,3 @@
1
1
  class Mettric
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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: 'Mettric Worker start') rescue nil
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
@@ -6,5 +6,6 @@ require 'mettric/errors'
6
6
  require 'mettric/client'
7
7
  require 'mettric/worker'
8
8
  require 'mettric/mettric'
9
- require 'mettric/thermometer'
9
+ require 'mettric/sidekiq_middleware'
10
+ require 'mettric/scnr'
10
11
 
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
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-30 00:00:00.000000000 Z
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/thermometer.rb
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
@@ -1,4 +0,0 @@
1
- # SCNR
2
- def 🌡 (payload)
3
- Mettric.track(payload)
4
- end