mettric 0.2.2 → 0.2.4

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: 41c233719f5671881896f6de5b3eb238cc0a5b0b
4
- data.tar.gz: 47db5d7f82128a21c00e2d3db2dcfbac75edb42f
3
+ metadata.gz: a54c6667cd180fa2a4f52f5159f9973f56b50c43
4
+ data.tar.gz: 1dee7f23fb2987d2bd4e74081816deaff2f1f2f3
5
5
  SHA512:
6
- metadata.gz: de15a514621130bfe913d651637caefb698338021b3515569df7620f0f96320ebe60cda9da5d85c77418a48f273778e0697bc61d79c42096f8783cd5a16b4859
7
- data.tar.gz: b91d7c2f89420d45ad30754c5ca2a0d96b4ef453c79cd1de49b0ac1e542f90d2b1c0f08d1e5784df03d32a08f27592e11a8af071abc0c8d655a05a92a1c60275
6
+ metadata.gz: d860f9b44f28156054d3969f7ad388b903579a98580d3d3aea9db081d36afa6aa447d87308d23174ee96fd03cbc394d8280ca4557fa3844cd71cc9e0f9b477bf
7
+ data.tar.gz: 6ca35061b4b86a7c68f0fd5b1838a153e5f18aed7d3a12e7e0ed79f01000af8550e348c92ef0a8e0679e96b7dd8a96177e5010f78abd158fc4a758fe1240bd26
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Jannis Hermanns
3
+ Copyright (c) 2016 Moviepilot, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,39 +1,133 @@
1
1
  # Mettric
2
2
 
3
- Track to riemann.
3
+ Tracks events, meter readings and timings to [riemann.io](http://riemann.io) in a background thread using [riemann-ruby-client](https://github.com/riemann/riemann-ruby-client). Fire and forget.
4
4
 
5
- ## Configuration
5
+ Mettric will also prepend your app's name to the services you track with riemann and set the reporting host and tags automatically.
6
+
7
+
8
+ ## Getting started
9
+
10
+ ```ruby
11
+ gem install mettric
12
+ ```
13
+
14
+
15
+ ### Configuration
16
+
17
+ You can configure Mettric like this:
6
18
 
7
19
  ```ruby
8
20
  Mettric.config = {
9
21
  host: 'my-riemann-server',
10
22
  port: 5555,
11
23
 
12
- reporting_host: 'override' # Defaults to system hostname
13
- app: 'my_app' # Defaults to rails app (if in rails)
14
- poll_intervall: 100 # Defaults to 50ms
24
+ reporting_host: 'override', # Defaults to system hostname
25
+ app: 'my_app', # Defaults to rails app (if in rails)
26
+ poll_intervall: 100, # Defaults to 50 (ms)
27
+ sidekiq_middleware: false # Defaults to true
15
28
  }
16
29
  ```
17
30
 
18
- ## Track events
31
+ Upon configuration, Mettric will install a [sidekiq](http://sidekiq.org/) middleware that automatically tracks the success and error rates of your workers as well as their duration (see below for details)
32
+
33
+
34
+ ### Track events
19
35
 
20
36
  ```ruby
21
37
  # Tracks payload with metric=1 and tags it 'event'
22
- 🛎 service: 'User created'
38
+ 🛎 service: 'users.created'
39
+
40
+ # Will send the following payload via riemann-ruby-client:
41
+ #
42
+ # {
43
+ # host: 'override',
44
+ # service: 'my_app.users.created',
45
+ # metric: 1,
46
+ # tags: ['event']
47
+ # }
23
48
  ```
24
49
 
25
- ## Track meter readings
50
+ ### Track meter readings
26
51
 
27
52
  ```ruby
28
53
  🌡 service: 'Rails req/s', metric: 400, state: 'normal'
54
+
55
+ # Will send the following payload via riemann-ruby-client:
56
+ #
57
+ # {
58
+ # host: 'override',
59
+ # service: 'my_app.Rails req/s',
60
+ # metric: 400,
61
+ # state: 'normal'
62
+ # }
29
63
  ```
30
64
 
31
- ## Time things
65
+ ### Time things
32
66
 
33
67
  ```ruby
34
- # This will track the duration in milliseconds as the `metric` value
35
- # as "Sleep duration ms" (note the added ' ms') and tag it 'timing'
36
- ⏱ (service: 'Sleep duration') do
68
+ (service: 'test.slept', tags: [:tired]) do
37
69
  sleep 1
38
70
  end
71
+
72
+ # Will send the following payload via riemann-ruby-client:
73
+ #
74
+ # {
75
+ # host: 'override',
76
+ # service: 'my_app.test.slept',
77
+ # metric: 1000,
78
+ # description: '(ms)',
79
+ # tags: ['timing', 'tired']
80
+ # }
39
81
  ```
82
+
83
+ ### For grown ups
84
+
85
+ Just in case you don't want to use the silly methods names, please know that the emoji variants of above methods just call `Mettric.event(payload)`, `Mettric.meter(payload` and `Mettric.time(paylod) { ... }` respectively. Be aware, though, that the emoji methods ignore a misconfigured or unavailable riemann server by rescuing `Mettric::CouldNotStartWorkerThread` exceptions. The non-emoji methods will throw that exception. Just have a look at [lib/mettric/scnr.rb](lib/mettric/scnr.rb) and you'll see what I mean.
86
+
87
+
88
+ ## Sidekiq
89
+
90
+ Let's assume you have sidekiq worker class called `MyWorker` that uses the `my_queue` queue. Each time it runs, Mettric will automatically track how long the worker took by sending the following payload to Riemann (assuming the worker took 80ms):
91
+
92
+ ```ruby
93
+ {
94
+ host: 'override',
95
+ service: 'my_app.sidekiq.my_queue.my_worker.duration',
96
+ metric: 80,
97
+ tags: ['sidekiq']
98
+ }
99
+ ```
100
+
101
+ Also, it will track the success
102
+
103
+ ```ruby
104
+ {
105
+ host: 'override',
106
+ service: 'my_app.sidekiq.my_queue.my_worker.success',
107
+ metric: 1,
108
+ tags: ['event']
109
+ }
110
+ ```
111
+
112
+ or error
113
+
114
+ ```ruby
115
+ {
116
+ host: 'override',
117
+ service: 'my_app.sidekiq.my_queue.my_worker.error',
118
+ metric: 1,
119
+ tags: ['event']
120
+ }
121
+ ```
122
+
123
+ of the worker's execution. If you want a worker not to be tracked by mettric, you would write:
124
+
125
+ ```ruby
126
+ class MyWorker
127
+ include Sidekiq::Worker
128
+ sidekiq_options mettric: false
129
+
130
+ def perform
131
+
132
+ end
133
+ end
@@ -7,9 +7,20 @@ class Mettric
7
7
  end
8
8
 
9
9
  def self.config=(config)
10
+ # See if the config is valid
10
11
  config_test = Client.new(config)
11
12
  config_test.close
13
+
14
+ # Set the config
12
15
  @config = config
16
+
17
+ # Attempt to install sidekiq middleware unless
18
+ # we're told not to
19
+ if config.delete(:sidekiq_middleware) != false
20
+ Mettric::SidekiqMiddleware.install
21
+ end
22
+
23
+ @config
13
24
  end
14
25
 
15
26
  def self.track(payload)
data/lib/mettric/scnr.rb CHANGED
@@ -6,7 +6,7 @@ rescue Mettric::CouldNotStartWorkerThread
6
6
  puts "***WARNING*** Mettric::CouldNotStartWorkerThread raised"
7
7
  end
8
8
 
9
- # A meter
9
+ # A meter reading
10
10
  def 🌡 (payload)
11
11
  Mettric.meter(payload)
12
12
  rescue Mettric::CouldNotStartWorkerThread
@@ -1,42 +1,42 @@
1
1
  require 'active_support/inflector'
2
2
 
3
3
  class Mettric::SidekiqMiddleware
4
+
5
+ def self.install
6
+ return if @installed
7
+ return unless Kernel.const_defined?(:Sidekiq)
8
+ @installed = true
9
+ Sidekiq.configure_server do |config|
10
+ config.server_middleware do |chain|
11
+ chain.add Mettric::SidekiqMiddleware
12
+ end
13
+ end
14
+ end
15
+
4
16
  def initialize(_options = {})
5
17
  end
6
18
 
7
19
  def call(worker, msg, queue)
8
- begin
9
- opts = worker.class.sidekiq_options['mettric']
20
+ opts = worker.class.sidekiq_options['mettric']
10
21
 
11
- # Don't do anything if we're told to skip this class
12
- if opts != true and opts != nil
13
- return yield
14
- end
22
+ # Don't do anything if we're told to skip this class
23
+ if opts != true and opts != nil
24
+ return yield
25
+ end
15
26
 
16
- # Tracking under this name
17
- service = "sidekiq.queue:#{queue.to_s.underscore}.worker:#{worker.class.name.underscore}"
27
+ # Tracking under this name
28
+ service = "sidekiq.#{queue.to_s.underscore}.#{worker.class.name.underscore}"
18
29
 
19
- # Yield & time
20
- Mettric.time(service: "#{service}.duration", tags: ['sidekiq']) do
21
- yield
22
- end
23
- rescue
24
- Mettric.event(service: "#{service}.error", tags: ['sidekiq'])
25
- raise
30
+ # Yield & time
31
+ Mettric.time(service: "#{service}.duration", tags: ['sidekiq']) do
32
+ yield
26
33
  end
27
34
 
28
35
  # Track success
29
36
  Mettric.event(service: "#{service}.success", tags: ['sidekiq'])
30
- end
31
- rescue => e
32
- raise unless e.is_a?(Mettric::Error)
33
- end
34
-
35
- if Kernel.const_defined?(:Sidekiq)
36
- Sidekiq.configure_server do |config|
37
- config.server_middleware do |chain|
38
- chain.add Mettric::SidekiqMiddleware
39
- end
37
+ rescue => e
38
+ Mettric.event(service: "#{service}.failure", tags: ['sidekiq', 'error'], description: e.to_s)
39
+ raise unless e.is_a?(Mettric::Error)
40
40
  end
41
41
  end
42
42
 
@@ -1,3 +1,3 @@
1
1
  class Mettric
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.4"
3
3
  end
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.2.2
4
+ version: 0.2.4
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-06-09 00:00:00.000000000 Z
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport