rt-watchman 0.7.0 → 0.8.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: 4357d1bedf41f88aaa7eb347953ca9dfbd4fd76d
4
- data.tar.gz: c7fbe92bd341a5a2a5b001f32c28ecfeb2b2125e
3
+ metadata.gz: c6268d12059b4dcce2e1884056fb5e3f9a58ccc8
4
+ data.tar.gz: fc3e6c4d5fedf0a396779871a93dcbbbbc875ead
5
5
  SHA512:
6
- metadata.gz: 8386887ab93b52f9ec3cfdbd14d6b5a4c207284cd39c7340aa4793ca7458d93b4bdb9c1e4fcbadf952607eac25bf40525d438fab0cf2609091ba7017899d9072
7
- data.tar.gz: 210d9fb9a0a4396ab88ba366c3e9c2d4e80bc56320ee6f19377588441878f1da5c6c0d3c282be282b01fb06e2e1bca0eec3abcc50698973c8915bb6e697a983e
6
+ metadata.gz: 681b25d34ff7c9d87f667c772f998f7484cdef2b6480865440773163e60ae4e7151de217433f58479856781d3558f2fb21ccc8e165f6d032575a7f865f483271
7
+ data.tar.gz: c1647d66696b54332c9d7ebed2a1a86041120a88ceeb8c4e1aee40bbe1d824c5fae6a206473700a2e0430a16ca7874e01d0bb9ceb62742c8bf48c811170613b7
data/README.md CHANGED
@@ -36,9 +36,26 @@ end
36
36
  To submit a time value in miliseconds:
37
37
 
38
38
  ``` ruby
39
- Watchman.submit("number.of.kittens", 30, :timing)
39
+ Watchman.submit("number.of.kittens", 30, type: :timing)
40
40
  ```
41
41
 
42
+ ## Tags
43
+
44
+ If you want to use a variable that changes often, don't use this:
45
+
46
+ ``` ruby
47
+ Watchman.submit("user.#{id}", 30)
48
+ ```
49
+
50
+ Use tags. A list of tags is an optional last parameter of `:submit`, `:benchmark`,
51
+ `:increment` and `:decrement` methods.
52
+
53
+ ``` ruby
54
+ Watchman.submit("user", 30, tags: ["#{id}"])
55
+ ```
56
+
57
+ Tags list is limited to 3 values.
58
+
42
59
  ## Global metric prefix
43
60
 
44
61
  If you want to prepend all the metric names with a prefix, do the following:
@@ -1,3 +1,3 @@
1
1
  class Watchman
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
data/lib/watchman.rb CHANGED
@@ -12,8 +12,11 @@ class Watchman
12
12
  attr_accessor :port
13
13
  attr_accessor :test_mode
14
14
 
15
- def submit(name, value, type = :gauge)
16
- metric = metric_name_with_prefix(name)
15
+ def submit(name, value, args = {})
16
+ type = args[:type] || :gauge
17
+ tags = args[:tags] || []
18
+
19
+ metric = metric_name_with_prefix(name, tags)
17
20
 
18
21
  case type
19
22
  when :gauge then statsd_client.gauge(metric, value)
@@ -23,24 +26,30 @@ class Watchman
23
26
  end
24
27
  end
25
28
 
26
- def benchmark(name)
29
+ def benchmark(name, args = {})
30
+ tags = args[:tags] || []
31
+
27
32
  result = nil
28
33
 
29
34
  time = Benchmark.measure do
30
35
  result = yield
31
36
  end
32
37
 
33
- submit(name, (time.real * 1000).floor, :timing)
38
+ submit(name, (time.real * 1000).floor, type: :timing, tags: tags)
34
39
 
35
40
  result
36
41
  end
37
42
 
38
- def increment(name)
39
- submit(name, 1, :count)
43
+ def increment(name, args = {})
44
+ tags = args[:tags] || []
45
+
46
+ submit(name, 1, type: :count, tags: tags)
40
47
  end
41
48
 
42
- def decrement(name)
43
- submit(name, -1, :count)
49
+ def decrement(name, args = {})
50
+ tags = args[:tags] || []
51
+
52
+ submit(name, -1, type: :count, tags: tags)
44
53
  end
45
54
 
46
55
  private
@@ -53,12 +62,20 @@ class Watchman
53
62
  end
54
63
  end
55
64
 
56
- def metric_name_with_prefix(name)
57
- if @prefix
58
- "#{@prefix}.#{name}"
59
- else
60
- name
61
- end
65
+ def metric_name_with_prefix(name, tags)
66
+ full_name = []
67
+ full_name << "tagged"
68
+ full_name << @prefix if @prefix
69
+ full_name << tags_string(tags)
70
+ full_name << name
71
+ full_name.join(".")
72
+ end
73
+
74
+ def tags_string(tags)
75
+ tags
76
+ .fill("no_tag", tags.length, [3 - tags.length, 0].max)
77
+ .first(3)
78
+ .join(".")
62
79
  end
63
80
  end
64
81
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rt-watchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rendered Text
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: statsd-ruby