seismograph 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcdd15888db5f139a1cfd3e35140216b00d4748e
4
- data.tar.gz: 561e7a7f023d1c47e9bf9859616f1212421a6d22
3
+ metadata.gz: 56e91905b4b222e1e0c31c603a79f30d74abe237
4
+ data.tar.gz: dd10317f3aeb103d6d1816f0321cfe52d5ef0480
5
5
  SHA512:
6
- metadata.gz: cdbb33b6d578858b6328f890330c14c8c4ebb922ab54a395b0c22cc6ec5677a35ebef25c820cb3549be73d5c9326253783d2bae677a662c52fc769763683c0d8
7
- data.tar.gz: b323d6c2382053fadb042856312ab3ece32f2de1722f892bf6f679e5475386d8771ee0e6b16a8a237441e5e9546f08fc482341f96c7b71dce0ad5f4b3b7aca84
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
- #### Benchmarking:
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
- #### Logging events:
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
@@ -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
@@ -19,24 +19,33 @@ module Seismograph
19
19
  Gateway.increment(stat(description), gateway_params(params))
20
20
  end
21
21
 
22
- def benchmark(description, params = {})
23
- Gateway.time(stat(description), gateway_params(params)) do
24
- yield
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 = {}, &block)
31
- begin
32
- block.call if block_given?
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
@@ -1,3 +1,3 @@
1
1
  module Seismograph
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.1
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-09-25 00:00:00.000000000 Z
12
+ date: 2015-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dogstatsd-ruby