hosted_graphite 0.0.2 → 0.0.3
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/Gemfile +3 -1
- data/README.md +56 -20
- data/Rakefile +0 -1
- data/lib/hosted_graphite/http.rb +0 -1
- data/lib/hosted_graphite/protocol.rb +2 -4
- data/lib/hosted_graphite/statsd.rb +58 -0
- data/lib/hosted_graphite/tcp.rb +4 -2
- data/lib/hosted_graphite/udp.rb +4 -1
- data/lib/hosted_graphite/version.rb +1 -1
- data/lib/hosted_graphite.rb +2 -2
- data/test/helper.rb +2 -0
- data/test/test_stastd.rb +37 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf11312fbd83ce1b48007df57abe2e2c2521327b
|
4
|
+
data.tar.gz: e0fc96df3a589328f8bc9cb912944df5458cd584
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 995e3f7630a2c77f77811faf2462981e0380f62b42b8d1e221cbb2db928057ca2bfb92dc37d3a4d6bd9ea5eb3994222ca5bd017c5bc13bcb23b5442d18ef6fa6
|
7
|
+
data.tar.gz: d14de66879dc278375af325ceade1c2be7a192c6e57008729221e1eb735d1522692105618e04f60bbba2d7755dd8cded1eca2e17f092d3509a98c894b0a4fdf9
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -14,38 +14,74 @@ gem 'hosted_graphite'
|
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
17
|
-
|
17
|
+
```bash
|
18
|
+
$ bundle
|
19
|
+
```
|
18
20
|
|
19
21
|
Or install it yourself as:
|
20
22
|
|
21
|
-
|
23
|
+
```bash
|
24
|
+
$ gem install hosted_graphite
|
25
|
+
```
|
22
26
|
|
23
27
|
## Usage
|
24
28
|
|
25
|
-
Set ```ENV['HOSTEDGRAPHITE_APIKEY']``` to your
|
29
|
+
Set ```ENV['HOSTEDGRAPHITE_APIKEY']``` to your hosted graphite API key.
|
26
30
|
Your API key can be found on your [account home](https://www.hostedgraphite.com/accounts/profile/) page.
|
27
31
|
|
28
|
-
You can also set
|
32
|
+
You can also set the hosted graphite API key programatically with:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
HostedGraphite.api_key = 'YOUR API KEY'
|
36
|
+
```
|
37
|
+
|
38
|
+
#### Sending a metric via UDP
|
39
|
+
```ruby
|
40
|
+
HostedGraphite.protocol = HostedGraphite::UDP
|
41
|
+
HostedGraphite.send_metric('foo.udp', 1.2)
|
42
|
+
```
|
43
|
+
|
44
|
+
#### Sending a metric via TCP
|
45
|
+
```ruby
|
46
|
+
HostedGraphite.protocol = HostedGraphite::TCP
|
47
|
+
HostedGraphite.send_metric('foo.tcp', 1.2)
|
48
|
+
```
|
49
|
+
|
50
|
+
#### Sending a metric via HTTP
|
51
|
+
```ruby
|
52
|
+
HostedGraphite.protocol = HostedGraphite::HTTP
|
53
|
+
HostedGraphite.send_metric('foo.http', 1.2)
|
54
|
+
```
|
55
|
+
|
56
|
+
### HostedStatsD
|
57
|
+
|
58
|
+
Enable Statsd on your [account](https://www.hostedgraphite.com/app/data-sources)
|
59
|
+
|
60
|
+
Ensure these line are present in your application's Gemfile:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
gem 'hosted_graphite'
|
64
|
+
gem 'statsd-ruby'
|
65
|
+
```
|
29
66
|
|
30
|
-
|
67
|
+
And then require
|
31
68
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
HostedGraphite.send_metric('foo.udp', 1.2)
|
36
|
-
```
|
69
|
+
```ruby
|
70
|
+
require 'hosted_graphite/statsd'
|
71
|
+
```
|
37
72
|
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
HostedGraphite.protocol = HostedGraphite::TCP
|
41
|
-
HostedGraphite.send_metric('foo.tcp', 1.2)
|
42
|
-
```
|
73
|
+
#### Basic usage
|
43
74
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
75
|
+
```ruby
|
76
|
+
# Send some stats
|
77
|
+
HostedGraphite.increment 'page_views'
|
78
|
+
HostedGraphite.decrement 'likes_count'
|
79
|
+
HostedGraphite.timing 'foo', 320
|
80
|
+
HostedGraphite.gauge 'bar', 100
|
81
|
+
|
82
|
+
# Use {#time} to time the execution of a block
|
83
|
+
HostedGraphite.time('newsletter.monthly') { @newletter.deliver_now }
|
84
|
+
```
|
49
85
|
|
50
86
|
## Contributing
|
51
87
|
|
data/Rakefile
CHANGED
data/lib/hosted_graphite/http.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'net/http'
|
1
3
|
module HostedGraphite
|
2
4
|
class Protocol
|
3
5
|
HOST = 'carbon.hostedgraphite.com'.freeze
|
@@ -22,9 +24,5 @@ module HostedGraphite
|
|
22
24
|
def build_message(name, value)
|
23
25
|
[name, value].join(' ')
|
24
26
|
end
|
25
|
-
|
26
|
-
def addr_info
|
27
|
-
Addrinfo.tcp(HOST, PORT)
|
28
|
-
end
|
29
27
|
end
|
30
28
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
gem 'statsd-ruby'
|
2
|
+
require 'hosted_graphite'
|
3
|
+
require 'statsd'
|
4
|
+
|
5
|
+
module HostedGraphite
|
6
|
+
class StatsD < Statsd
|
7
|
+
HOST = 'statsd.hostedgraphite.com'.freeze
|
8
|
+
PORT = 8125.freeze
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
raise MissingAPIKey unless HostedGraphite.api_key
|
12
|
+
super(HOST, PORT)
|
13
|
+
@namespace = HostedGraphite.api_key
|
14
|
+
@prefix = "#{@namespace}."
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def socket
|
19
|
+
Thread.current[:hostedstatsd_socket] ||= UDPSocket.new addr_family
|
20
|
+
end
|
21
|
+
|
22
|
+
def addr_family
|
23
|
+
Addrinfo.udp(@host, @port).afamily
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
@@statsd = StatsD.new
|
28
|
+
|
29
|
+
class << self
|
30
|
+
def increment(stat, sample_rate=1)
|
31
|
+
@@statsd.count stat, 1, sample_rate
|
32
|
+
end
|
33
|
+
|
34
|
+
def decrement(stat, sample_rate=1)
|
35
|
+
@@statsd.count stat, -1, sample_rate
|
36
|
+
end
|
37
|
+
|
38
|
+
def count(stat, count, sample_rate=1)
|
39
|
+
@@statsd.send_stats stat, count, :c, sample_rate
|
40
|
+
end
|
41
|
+
|
42
|
+
def gauge(stat, value, sample_rate=1)
|
43
|
+
@@statsd.send_stats stat, value, :g, sample_rate
|
44
|
+
end
|
45
|
+
|
46
|
+
def set(stat, value, sample_rate=1)
|
47
|
+
@@statsd.send_stats stat, value, :s, sample_rate
|
48
|
+
end
|
49
|
+
|
50
|
+
def timing(stat, ms, sample_rate=1)
|
51
|
+
@@statsd.send_stats stat, ms, :ms, sample_rate
|
52
|
+
end
|
53
|
+
|
54
|
+
def time(stat, sample_rate=1)
|
55
|
+
@@statsd.time(stat, sample_rate)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/hosted_graphite/tcp.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
require 'socket'
|
2
1
|
module HostedGraphite
|
3
2
|
class TCP < Protocol
|
4
3
|
private
|
5
|
-
|
6
4
|
def build_message(name, value)
|
7
5
|
message = [name, value].join(' ') + "\n"
|
8
6
|
[@api_key, message].join('.')
|
@@ -17,5 +15,9 @@ module HostedGraphite
|
|
17
15
|
Thread.current[:hostedgraphite_tcpsocket] ||= TCPSocket.new addr_info.ip_address,
|
18
16
|
addr_info.ip_port
|
19
17
|
end
|
18
|
+
|
19
|
+
def addr_info
|
20
|
+
Addrinfo.tcp(HOST, PORT)
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
data/lib/hosted_graphite/udp.rb
CHANGED
data/lib/hosted_graphite.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/test_stastd.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class StatsDTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@previous_api_key = HostedGraphite.api_key
|
6
|
+
HostedGraphite.api_key = SecureRandom.uuid
|
7
|
+
require 'hosted_graphite/statsd'
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
HostedGraphite.api_key = @previous_api_key
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_respond_to_time
|
15
|
+
assert_respond_to HostedGraphite, :time
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_respond_to_timing
|
19
|
+
assert_respond_to HostedGraphite, :timing
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_respond_to_set
|
23
|
+
assert_respond_to HostedGraphite, :set
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_respond_to_gauge
|
27
|
+
assert_respond_to HostedGraphite, :gauge
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_respond_to_decrement
|
31
|
+
assert_respond_to HostedGraphite, :decrement
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_respond_to_increment
|
35
|
+
assert_respond_to HostedGraphite, :increment
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hosted_graphite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdelkader Boudih
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/hosted_graphite.rb
|
70
70
|
- lib/hosted_graphite/http.rb
|
71
71
|
- lib/hosted_graphite/protocol.rb
|
72
|
+
- lib/hosted_graphite/statsd.rb
|
72
73
|
- lib/hosted_graphite/tcp.rb
|
73
74
|
- lib/hosted_graphite/udp.rb
|
74
75
|
- lib/hosted_graphite/version.rb
|
@@ -76,6 +77,7 @@ files:
|
|
76
77
|
- test/helper.rb
|
77
78
|
- test/test_http_protocol.rb
|
78
79
|
- test/test_missing_apikey.rb
|
80
|
+
- test/test_stastd.rb
|
79
81
|
- test/test_tcp_protocol.rb
|
80
82
|
- test/test_udp_protocol.rb
|
81
83
|
homepage: https://github.com/seuros/hosted_graphite
|
@@ -107,6 +109,7 @@ test_files:
|
|
107
109
|
- test/helper.rb
|
108
110
|
- test/test_http_protocol.rb
|
109
111
|
- test/test_missing_apikey.rb
|
112
|
+
- test/test_stastd.rb
|
110
113
|
- test/test_tcp_protocol.rb
|
111
114
|
- test/test_udp_protocol.rb
|
112
115
|
has_rdoc:
|