rt-watchman 0.9.0 → 0.10.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 +53 -2
- data/lib/watchman.rb +22 -25
- data/lib/watchman/metric_name.rb +36 -0
- data/lib/watchman/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ea317e3767bb88fc1f9ad45dd8f0e59d390e878
|
4
|
+
data.tar.gz: 38d7f082ccc4f9232e22a3be8491ad994df0d31c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 729390c5b43c85c590e32c52cb73690f891c2a1d80286d1c33faaa5dbf90cc1433607265394342aeb45d7ce24b0afc6fd8c1b9457a26e8086f8e36695f417fc9
|
7
|
+
data.tar.gz: 3485485924f7705cdd29156f2279a78b0410b1d04670d9c037c3b590c74fa18c41adfff4d1ef85db4b27c8a596f1a0a5506ddaec8cddc17df8e2a0a0a9adf25d
|
data/README.md
CHANGED
@@ -17,7 +17,18 @@ Watchman.host = "localhost"
|
|
17
17
|
Watchman.port = 22345
|
18
18
|
```
|
19
19
|
|
20
|
-
To submit a
|
20
|
+
To submit a value to statsd from your service use:
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
Watchman.submit(name, value, type)
|
24
|
+
```
|
25
|
+
|
26
|
+
Available types:
|
27
|
+
* :gauge `default`
|
28
|
+
* :timing
|
29
|
+
* :count
|
30
|
+
|
31
|
+
Submitting a simple gauge value from your service would look like:
|
21
32
|
|
22
33
|
``` ruby
|
23
34
|
Watchman.submit("number.of.kittens", 30)
|
@@ -33,12 +44,52 @@ Watchman.benchmark("time.to.wake.up") do
|
|
33
44
|
end
|
34
45
|
```
|
35
46
|
|
36
|
-
To submit a time value in
|
47
|
+
To submit a time value in milliseconds use:
|
37
48
|
|
38
49
|
``` ruby
|
39
50
|
Watchman.submit("number.of.kittens", 30, :timing)
|
40
51
|
```
|
41
52
|
|
53
|
+
To submit a count value use:
|
54
|
+
|
55
|
+
``` ruby
|
56
|
+
# To increse:
|
57
|
+
Watchman.increment("number.of.kittens")
|
58
|
+
|
59
|
+
# or decrese:
|
60
|
+
Watchman.decrement("number.of.kittens")
|
61
|
+
```
|
62
|
+
|
63
|
+
Alternatively you can use:
|
64
|
+
|
65
|
+
``` ruby
|
66
|
+
# To increse:
|
67
|
+
Watchman.submit("number.of.kittens", 1, :count)
|
68
|
+
|
69
|
+
# or decrese:
|
70
|
+
Watchman.submit("number.of.kittens", -1, :count)
|
71
|
+
```
|
72
|
+
|
73
|
+
to achieve the equivalent effect, with the added possibility of tweaking the
|
74
|
+
value.
|
75
|
+
|
76
|
+
## Tags
|
77
|
+
|
78
|
+
If you want to use a variable that changes often, don't use this:
|
79
|
+
|
80
|
+
``` ruby
|
81
|
+
Watchman.submit("user.#{id}", 30)
|
82
|
+
```
|
83
|
+
|
84
|
+
Use tags. A list of tags is an optional last parameter of `:submit`, `:benchmark`,
|
85
|
+
`:increment` and `:decrement` methods.
|
86
|
+
|
87
|
+
``` ruby
|
88
|
+
Watchman.submit("user", 30, tags: [id])
|
89
|
+
```
|
90
|
+
|
91
|
+
Tags list is limited to 3 values.
|
92
|
+
|
42
93
|
## Global metric prefix
|
43
94
|
|
44
95
|
If you want to prepend all the metric names with a prefix, do the following:
|
data/lib/watchman.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "watchman/version"
|
2
|
+
require "watchman/metric_name"
|
2
3
|
require "watchman/mock_statsd"
|
3
4
|
require "benchmark"
|
4
5
|
require "statsd"
|
@@ -12,35 +13,39 @@ class Watchman
|
|
12
13
|
attr_accessor :port
|
13
14
|
attr_accessor :test_mode
|
14
15
|
|
15
|
-
def
|
16
|
-
metric = metric_name_with_prefix(name)
|
17
|
-
|
18
|
-
case type
|
19
|
-
when :gauge then statsd_client.gauge(metric, value)
|
20
|
-
when :timing then statsd_client.timing(metric, value)
|
21
|
-
when :count then statsd_client.count(metric, value)
|
22
|
-
else raise SubmitTypeError.new("Submit type '#{type}' is not recognized")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def benchmark(name)
|
16
|
+
def benchmark(name, options = {})
|
27
17
|
result = nil
|
28
18
|
|
29
19
|
time = Benchmark.measure do
|
30
20
|
result = yield
|
31
21
|
end
|
32
22
|
|
33
|
-
|
23
|
+
timing(name, (time.real * 1000).floor, options)
|
34
24
|
|
35
25
|
result
|
36
26
|
end
|
37
27
|
|
38
|
-
def
|
39
|
-
submit(name,
|
28
|
+
def timing(name, value, options = {})
|
29
|
+
submit(name, value, :timing, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def increment(name, options = {})
|
33
|
+
submit(name, 1, :count, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def decrement(name, options = {})
|
37
|
+
submit(name, -1, :count, options)
|
40
38
|
end
|
41
39
|
|
42
|
-
def
|
43
|
-
|
40
|
+
def submit(name, value, type = :gauge, options = {})
|
41
|
+
metric = Watchman::MetricName.construct(name, prefix, options[:tags])
|
42
|
+
|
43
|
+
case type
|
44
|
+
when :gauge then statsd_client.gauge(metric, value)
|
45
|
+
when :timing then statsd_client.timing(metric, value)
|
46
|
+
when :count then statsd_client.count(metric, value)
|
47
|
+
else raise SubmitTypeError.new("Submit type '#{type}' is not recognized")
|
48
|
+
end
|
44
49
|
end
|
45
50
|
|
46
51
|
private
|
@@ -52,13 +57,5 @@ class Watchman
|
|
52
57
|
@client ||= Statsd.new(@host, @port)
|
53
58
|
end
|
54
59
|
end
|
55
|
-
|
56
|
-
def metric_name_with_prefix(name)
|
57
|
-
if @prefix
|
58
|
-
"#{@prefix}.#{name}"
|
59
|
-
else
|
60
|
-
name
|
61
|
-
end
|
62
|
-
end
|
63
60
|
end
|
64
61
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Watchman
|
2
|
+
class MetricName
|
3
|
+
def self.construct(base_name, prefix, tags)
|
4
|
+
new(base_name, prefix, tags).construct
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(base_name, prefix = nil, tags)
|
8
|
+
@base_name = base_name
|
9
|
+
@prefix = prefix
|
10
|
+
@tags = tags || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def construct
|
14
|
+
full_name = []
|
15
|
+
|
16
|
+
full_name << "tagged" if tagged?
|
17
|
+
full_name << @prefix if @prefix
|
18
|
+
full_name << formated_tags if tagged?
|
19
|
+
full_name << @base_name
|
20
|
+
|
21
|
+
full_name.join(".")
|
22
|
+
end
|
23
|
+
|
24
|
+
def formated_tags
|
25
|
+
@tags
|
26
|
+
.map(&:to_s)
|
27
|
+
.fill("no_tag", @tags.length, [3 - @tags.length, 0].max)
|
28
|
+
.first(3)
|
29
|
+
.join(".")
|
30
|
+
end
|
31
|
+
|
32
|
+
def tagged?
|
33
|
+
@tags.size > 0
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/watchman/version.rb
CHANGED
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.
|
4
|
+
version: 0.10.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:
|
11
|
+
date: 2017-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: statsd-ruby
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- bin/console
|
84
84
|
- bin/setup
|
85
85
|
- lib/watchman.rb
|
86
|
+
- lib/watchman/metric_name.rb
|
86
87
|
- lib/watchman/mock_statsd.rb
|
87
88
|
- lib/watchman/version.rb
|
88
89
|
- watchman.gemspec
|