mettric 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +106 -12
- data/lib/mettric/mettric.rb +11 -0
- data/lib/mettric/scnr.rb +1 -1
- data/lib/mettric/sidekiq_middleware.rb +25 -25
- data/lib/mettric/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a54c6667cd180fa2a4f52f5159f9973f56b50c43
|
4
|
+
data.tar.gz: 1dee7f23fb2987d2bd4e74081816deaff2f1f2f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d860f9b44f28156054d3969f7ad388b903579a98580d3d3aea9db081d36afa6aa447d87308d23174ee96fd03cbc394d8280ca4557fa3844cd71cc9e0f9b477bf
|
7
|
+
data.tar.gz: 6ca35061b4b86a7c68f0fd5b1838a153e5f18aed7d3a12e7e0ed79f01000af8550e348c92ef0a8e0679e96b7dd8a96177e5010f78abd158fc4a758fe1240bd26
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,39 +1,133 @@
|
|
1
1
|
# Mettric
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
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
|
-
|
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: '
|
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
|
-
|
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
|
-
|
65
|
+
### Time things
|
32
66
|
|
33
67
|
```ruby
|
34
|
-
|
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
|
data/lib/mettric/mettric.rb
CHANGED
@@ -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
@@ -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
|
-
|
9
|
-
opts = worker.class.sidekiq_options['mettric']
|
20
|
+
opts = worker.class.sidekiq_options['mettric']
|
10
21
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
27
|
+
# Tracking under this name
|
28
|
+
service = "sidekiq.#{queue.to_s.underscore}.#{worker.class.name.underscore}"
|
18
29
|
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
|
data/lib/mettric/version.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.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-
|
11
|
+
date: 2016-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|