statsy 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +26 -11
- data/lib/statsy.rb +40 -9
- data/test/statsy_test.rb +10 -11
- metadata +37 -54
data/README.md
CHANGED
@@ -1,28 +1,44 @@
|
|
1
1
|
# Statsy
|
2
2
|
|
3
|
-
[Cal made simple stat aggregation][cal]
|
3
|
+
[Cal made simple stat aggregation][cal] - And it was good.
|
4
4
|
|
5
|
-
[Etsy also made simple stat aggregation][etsy]
|
5
|
+
[Etsy also made simple stat aggregation][etsy] - And it was also good.
|
6
6
|
|
7
|
-
This is a simple client.
|
7
|
+
This is a simple client. It supports:
|
8
8
|
|
9
|
-
|
9
|
+
* counts
|
10
|
+
* time measurements
|
11
|
+
* recording gauges
|
12
|
+
* sampling
|
13
|
+
* batching
|
14
|
+
|
15
|
+
## Requirements
|
16
|
+
|
17
|
+
This client is compatible with a [Statsd][statsd] server version >= 0.1.0.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
gem install statsy
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Default to UDP to a host in the current search domain called 'stats' on port 8125.
|
10
26
|
|
11
27
|
client = Statsy::Client.new
|
12
28
|
|
13
|
-
|
29
|
+
Use a custom transport or change the host/port pair for UDP.
|
14
30
|
|
15
31
|
client = Statsy::Client.new(Statsy::Transport::UDP.new("graphite.acme.com", 8125))
|
16
32
|
client = Statsy::Client.new(Acme::Transport::Statsd) # <- you made that
|
17
33
|
client = Statsy::Client.new(Statsy::Transport::Queue.new) # <- if you want to test stuff
|
18
34
|
|
19
|
-
|
35
|
+
Increment by 1, arbitrary integer, or arbitrary integer at a uniform random distribution
|
20
36
|
|
21
37
|
client.increment("coffee.single-espresso")
|
22
38
|
client.increment("coffee.single-espresso", 1)
|
23
39
|
client.increment("coffee.single-espresso", 1, 0.5) # 50% of the time
|
24
40
|
|
25
|
-
|
41
|
+
Measure a timing stat that will calculate the mean, min, max, upper\_90 and count
|
26
42
|
|
27
43
|
client.measure("acme.backend-runtime", response.headers["X-Runtime"].to_i)
|
28
44
|
|
@@ -33,7 +49,7 @@ Bonus points: Batch up many things into a fewer packets like in a shell script
|
|
33
49
|
client.batch do |batch|
|
34
50
|
$stdin.each do |log_line|
|
35
51
|
metric, timing = parse(log_line) # <- you made that
|
36
|
-
|
52
|
+
batch.measure metric, timing
|
37
53
|
break if (batch_lines -= 1) <= 0
|
38
54
|
end
|
39
55
|
end
|
@@ -45,9 +61,8 @@ These stats end up in your graphite interface under the top level keys. Look for
|
|
45
61
|
stats/timings
|
46
62
|
stats
|
47
63
|
|
48
|
-
Fork it out of love.
|
64
|
+
Fork it out of love. Enjoy.
|
49
65
|
|
50
66
|
[cal]:http://code.flickr.com/blog/2008/10/27/counting-timing/
|
51
67
|
[etsy]:http://codeascraft.etsy.com/2011/02/15/measure-anything-measure-everything/
|
52
|
-
|
53
|
-
|
68
|
+
[statsd]:https://github.com/etsy/statsd
|
data/lib/statsy.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Client to access statsd service authored by etsy. Yay etsy!
|
2
2
|
# https://github.com/etsy/statsd
|
3
3
|
module Statsy
|
4
|
-
VERSION=
|
4
|
+
VERSION='0.2.0'
|
5
5
|
|
6
6
|
module Transport
|
7
7
|
require 'socket'
|
@@ -49,7 +49,8 @@ module Statsy
|
|
49
49
|
@transport = transport
|
50
50
|
end
|
51
51
|
|
52
|
-
# Increment a count optionally at a random sample rate
|
52
|
+
# Increment a count optionally at a random sample rate. These keys will
|
53
|
+
# live under the stats and stats_counts keys.
|
53
54
|
#
|
54
55
|
# Usage:
|
55
56
|
# client.increment("coffee.single-espresso")
|
@@ -57,17 +58,49 @@ module Statsy
|
|
57
58
|
# client.increment("coffee.single-espresso", 1, 0.5) # 50% of the time
|
58
59
|
#
|
59
60
|
def increment(stat, count=1, sampling=1)
|
60
|
-
|
61
|
+
if sampling < 1
|
62
|
+
if Kernel.rand < sampling
|
63
|
+
write(stat, count, 'c', sampling)
|
64
|
+
end
|
65
|
+
else
|
66
|
+
write(stat, count, 'c', 1)
|
67
|
+
end
|
61
68
|
self
|
62
69
|
end
|
63
70
|
|
64
|
-
# Sample a timing
|
71
|
+
# Sample a timing. The units of the timing are up to you and your
|
72
|
+
# consumers, milliseconds is common.
|
73
|
+
#
|
74
|
+
# Including the units in the key name will help communicate the units to
|
75
|
+
# consumers of these measurements.
|
76
|
+
#
|
77
|
+
# The statistics will be aggregated over the sampling period configured in
|
78
|
+
# your statsd. By default this is every 10 seconds.
|
79
|
+
#
|
80
|
+
# In graphite, these reports will end up under the stats.timings key.
|
65
81
|
#
|
66
82
|
# Usage:
|
67
83
|
# client.measure("foo.backendtime", response.headers["X-Runtime"].to_i)
|
68
84
|
#
|
69
|
-
|
70
|
-
|
85
|
+
# Produces the statistics found per sampling interval.
|
86
|
+
# stats.timings.foo.backendtime.count
|
87
|
+
# stats.timings.foo.backendtime.lower
|
88
|
+
# stats.timings.foo.backendtime.mean_90
|
89
|
+
# stats.timings.foo.backendtime.upper
|
90
|
+
# stats.timings.foo.backendtime.upper_90
|
91
|
+
#
|
92
|
+
def measure(stat, time)
|
93
|
+
write(stat, time, 'ms', 1)
|
94
|
+
self
|
95
|
+
end
|
96
|
+
|
97
|
+
# Record an arbitrary value
|
98
|
+
#
|
99
|
+
# Usage:
|
100
|
+
# client.record("foo.arbitrary", 42)
|
101
|
+
#
|
102
|
+
def record(stat, gauge)
|
103
|
+
write(stat, gauge, 'g', 1)
|
71
104
|
self
|
72
105
|
end
|
73
106
|
|
@@ -105,9 +138,7 @@ module Statsy
|
|
105
138
|
protected
|
106
139
|
def write(stat, value, modifier, sampling)
|
107
140
|
if sampling < 1
|
108
|
-
|
109
|
-
@transport.write("%s:%d|%s@%f" % [ stat, value, modifier, sampling ])
|
110
|
-
end
|
141
|
+
@transport.write("%s:%d|%s|@%f" % [ stat, value, modifier, sampling ])
|
111
142
|
else
|
112
143
|
@transport.write("%s:%d|%s" % [ stat, value, modifier ])
|
113
144
|
end
|
data/test/statsy_test.rb
CHANGED
@@ -49,7 +49,7 @@ class Unit < Test::Unit::TestCase
|
|
49
49
|
|
50
50
|
def test_increment_should_sample
|
51
51
|
@client.increment("foo.stat", 1, 0.999999)
|
52
|
-
assert_equal "foo.stat:1|c
|
52
|
+
assert_equal "foo.stat:1|c|@0.999999", @transport.shift
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_measure_should_return_self
|
@@ -61,16 +61,6 @@ class Unit < Test::Unit::TestCase
|
|
61
61
|
assert_equal "foo.timing:1000|ms", @transport.shift
|
62
62
|
end
|
63
63
|
|
64
|
-
def test_measure_should_sample
|
65
|
-
@client.measure("foo.sampled.timing", 100, 0.0000001)
|
66
|
-
assert_equal nil, @transport.shift
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_measure_should_include_sample_rate
|
70
|
-
@client.measure("foo.sampled.timing", 100, 0.999999)
|
71
|
-
assert_equal "foo.sampled.timing:100|ms@0.999999", @transport.shift
|
72
|
-
end
|
73
|
-
|
74
64
|
def test_increment_twice_should_write_twice
|
75
65
|
@client.increment("foo.inc", 1)
|
76
66
|
@client.increment("foo.inc", 2)
|
@@ -152,4 +142,13 @@ class Unit < Test::Unit::TestCase
|
|
152
142
|
assert_equal "bar.inc:700|ms:900|ms:3|c", @transport.shift
|
153
143
|
assert_equal "foo.inc:2|c:9|c:500|ms", @transport.shift
|
154
144
|
end
|
145
|
+
|
146
|
+
def test_record_should_return_self
|
147
|
+
assert_equal @client, @client.record("foo.bar", 100)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_record_should_form_gauge
|
151
|
+
@client.record("foo.bar", 333)
|
152
|
+
assert_equal "foo.bar:333|g", @transport.shift
|
153
|
+
end
|
155
154
|
end
|
metadata
CHANGED
@@ -1,84 +1,67 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 3
|
10
|
-
version: 0.1.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Sean Treadway
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-06-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: test-unit
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Simple way to increment counts and measure variance in timings of everything
|
31
|
+
from requests per second to single espressos
|
32
|
+
email:
|
37
33
|
- treadway@gmail.com
|
38
34
|
executables: []
|
39
|
-
|
40
35
|
extensions: []
|
41
|
-
|
42
36
|
extra_rdoc_files: []
|
43
|
-
|
44
|
-
files:
|
37
|
+
files:
|
45
38
|
- lib/statsy.rb
|
46
39
|
- LICENSE
|
47
40
|
- README.md
|
48
41
|
- test/statsy_test.rb
|
49
|
-
has_rdoc: true
|
50
42
|
homepage: http://github.com/streadway/statsy
|
51
43
|
licenses: []
|
52
|
-
|
53
44
|
post_install_message:
|
54
45
|
rdoc_options: []
|
55
|
-
|
56
|
-
require_paths:
|
46
|
+
require_paths:
|
57
47
|
- lib
|
58
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
49
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
|
64
|
-
|
65
|
-
- 0
|
66
|
-
version: "0"
|
67
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
55
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
segments:
|
74
|
-
- 0
|
75
|
-
version: "0"
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
76
60
|
requirements: []
|
77
|
-
|
78
61
|
rubyforge_project: statsy
|
79
|
-
rubygems_version: 1.
|
62
|
+
rubygems_version: 1.8.23
|
80
63
|
signing_key:
|
81
64
|
specification_version: 3
|
82
65
|
summary: Client network library to Statsd
|
83
|
-
test_files:
|
66
|
+
test_files:
|
84
67
|
- test/statsy_test.rb
|