seismograph 0.2.1 → 0.3.0
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 +4 -4
- data/README.md +41 -7
- data/lib/seismograph/gateway.rb +1 -1
- data/lib/seismograph/sensor.rb +18 -9
- data/lib/seismograph/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: 56e91905b4b222e1e0c31c603a79f30d74abe237
|
4
|
+
data.tar.gz: dd10317f3aeb103d6d1816f0321cfe52d5ef0480
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a692a017eff498426e72e92d616c27b8631fa30e89133f29c2476c8219874faccc7dc5536e354c353d6772a1ce4638daf872a7039920876eb190709cf6f9a91b
|
7
|
+
data.tar.gz: 471321f5a40efa733ccf3b3175bffa77ea65819cef7ba84107d407034cde76f76b7ef6ef1cb2d317ed0ff547d1f1e81d455c5cd436e5ae410e6905de3c92f2ff
|
data/README.md
CHANGED
@@ -10,15 +10,20 @@ Add this line to your application's Gemfile:
|
|
10
10
|
gem 'seismograph'
|
11
11
|
```
|
12
12
|
|
13
|
+
If not using bundler, be sure to require the gem:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'seismograph'
|
17
|
+
```
|
18
|
+
|
13
19
|
## Usage
|
14
20
|
|
15
21
|
Configure your statsd server:
|
16
22
|
|
17
23
|
```ruby
|
18
|
-
require 'seismograph'
|
19
|
-
|
20
24
|
Seismograph.config do |config|
|
21
|
-
config.app_name = 'cabbagepult'
|
25
|
+
config.app_name = 'cabbagepult' # optional
|
26
|
+
config.env = 'staging' # optional, defaults to `RAILS_ENV` or `RACK_ENV`
|
22
27
|
config.statsd_host = ENV.fetch('STATSD_HOST')
|
23
28
|
config.statsd_port = ENV.fetch('STATSD_PORT')
|
24
29
|
end
|
@@ -43,7 +48,25 @@ def create
|
|
43
48
|
end
|
44
49
|
```
|
45
50
|
|
46
|
-
|
51
|
+
### Counting:
|
52
|
+
|
53
|
+
Counting is useful for tracking simple quantities or events. It accepts a numeric value (default
|
54
|
+
is 1) and an optional block. In addition to counting, this method will also track success or
|
55
|
+
failure (via incrementing) depending on whether an error is raised.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
sensor.count('signup', 2)
|
59
|
+
|
60
|
+
sensor.count('signup') do
|
61
|
+
User.create!(attributes)
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
### Benchmarking:
|
66
|
+
|
67
|
+
Benchmarking is useful for tracking how long an operation takes. In addition to tracking the
|
68
|
+
timing, this method will also track success or failure (via incrementing) depending on whether an
|
69
|
+
error is raised.
|
47
70
|
|
48
71
|
```ruby
|
49
72
|
def create
|
@@ -54,7 +77,20 @@ def create
|
|
54
77
|
end
|
55
78
|
```
|
56
79
|
|
57
|
-
|
80
|
+
### Incrementing/Decrementing:
|
81
|
+
|
82
|
+
Simple incrementing and decrementing can be performed on a stat. Both methods accept a numeric
|
83
|
+
value (default is 1).
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
sensor.increment('memberships')
|
87
|
+
sensor.decrement('memberships', 2)
|
88
|
+
```
|
89
|
+
|
90
|
+
### Logging events:
|
91
|
+
|
92
|
+
Logging can be used for tracking critical events. Valid log methods are `info`, `warning`,
|
93
|
+
`error`, and `success`.
|
58
94
|
|
59
95
|
```ruby
|
60
96
|
task :deploy do
|
@@ -67,8 +103,6 @@ task :deploy do
|
|
67
103
|
|
68
104
|
# "warning" and "success" are the remaining type alert type possibilities
|
69
105
|
end
|
70
|
-
|
71
|
-
|
72
106
|
```
|
73
107
|
|
74
108
|
## Contributing
|
data/lib/seismograph/gateway.rb
CHANGED
@@ -3,7 +3,7 @@ require 'statsd'
|
|
3
3
|
module Seismograph
|
4
4
|
module Gateway
|
5
5
|
class << self
|
6
|
-
[:histogram, :increment, :time, :event].each do |method|
|
6
|
+
[:histogram, :increment, :decrement, :time, :event].each do |method|
|
7
7
|
define_method(method) do |*args, &block|
|
8
8
|
client.send(method, *args, &block)
|
9
9
|
end
|
data/lib/seismograph/sensor.rb
CHANGED
@@ -19,24 +19,33 @@ module Seismograph
|
|
19
19
|
Gateway.increment(stat(description), gateway_params(params))
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
Gateway.
|
24
|
-
|
22
|
+
def decrement(description, params = {})
|
23
|
+
Gateway.decrement(stat(description), gateway_params(params))
|
24
|
+
end
|
25
|
+
|
26
|
+
def benchmark(description, params = {}, &block)
|
27
|
+
with_success_and_failure(description, params) do
|
28
|
+
Gateway.time(stat(description), gateway_params(params), &block)
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
32
|
private
|
29
33
|
|
30
|
-
def track(description, amount, params = {}
|
31
|
-
|
32
|
-
|
34
|
+
def track(description, amount, params = {})
|
35
|
+
with_success_and_failure(description, params) do
|
36
|
+
yield if block_given?
|
33
37
|
Gateway.histogram(stat(description), amount, gateway_params(params))
|
34
|
-
rescue StandardError => e
|
35
|
-
increment("#{description}.failure", gateway_params(params))
|
36
|
-
raise e
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
41
|
+
def with_success_and_failure(description, params)
|
42
|
+
yield
|
43
|
+
increment("#{description}.success", gateway_params(params))
|
44
|
+
rescue StandardError => e
|
45
|
+
increment("#{description}.failure", gateway_params(params))
|
46
|
+
raise e
|
47
|
+
end
|
48
|
+
|
40
49
|
def stat(description)
|
41
50
|
"#{namespace}.#{description}"
|
42
51
|
end
|
data/lib/seismograph/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seismograph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Croft
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dogstatsd-ruby
|