hosted_graphite 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +1 -0
- data/README.md +4 -8
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/hosted_graphite.rb +11 -19
- data/lib/hosted_graphite/ext/sidekiq.rb +7 -7
- data/lib/hosted_graphite/{http.rb → protocols/http.rb} +1 -0
- data/lib/hosted_graphite/protocols/statsd.rb +24 -0
- data/lib/hosted_graphite/{tcp.rb → protocols/tcp.rb} +1 -0
- data/lib/hosted_graphite/{udp.rb → protocols/udp.rb} +2 -0
- data/lib/hosted_graphite/statsd.rb +1 -33
- data/lib/hosted_graphite/testing.rb +3 -0
- data/lib/hosted_graphite/version.rb +1 -1
- data/test/helper.rb +1 -0
- data/test/test_http_protocol.rb +1 -8
- data/test/test_stastd.rb +1 -7
- data/test/test_tcp_protocol.rb +1 -8
- data/test/test_udp_protocol.rb +1 -8
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a96d4721686e9b29cded57b6624a05bec73484c
|
4
|
+
data.tar.gz: e2350801a97eb3b09b97e2ea36e8c97241fd4463
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f6f7351e6d2be3135e9a6f88772e6e3c5d81d1fb71baffa8558f5b4404ea7d4a3592f380b38e93f505013272220f574d0e69ae33c5fecdb97fea05b67d2106d
|
7
|
+
data.tar.gz: 4c93fd58f0c53687a8165f337eb532c404c4c132b54c8862eae29dbabad6ca06b7ebdfb19f602281ccf09b6c4b23dffd263a01b221fad703513d708dfbfde91d
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1 : Add sidekiq extension
|
data/README.md
CHANGED
@@ -65,15 +65,10 @@ gem 'hosted_graphite'
|
|
65
65
|
gem 'statsd-ruby'
|
66
66
|
```
|
67
67
|
|
68
|
-
And then require
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
require 'hosted_graphite/statsd'
|
72
|
-
```
|
73
|
-
|
74
68
|
#### Basic usage
|
75
69
|
|
76
70
|
```ruby
|
71
|
+
HostedGraphite.protocol = :statsd
|
77
72
|
# Send some stats
|
78
73
|
HostedGraphite.increment 'page_views'
|
79
74
|
HostedGraphite.decrement 'likes_count'
|
@@ -91,9 +86,10 @@ HostedGraphite.time('newsletter.monthly') { @newsletter.deliver_now }
|
|
91
86
|
|
92
87
|
Sidekiq.configure_server do |config|
|
93
88
|
config.server_middleware do |chain|
|
94
|
-
#
|
89
|
+
# my_app is an optional namespace
|
90
|
+
# chain.prepend HostedGraphite::Ext::Sidekiq::StatsdMetrics, 'my_app'
|
95
91
|
# or
|
96
|
-
# chain.prepend
|
92
|
+
# chain.prepend HostedGraphite::Ext::Sidekiq::Metrics
|
97
93
|
end
|
98
94
|
end
|
99
95
|
```
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'hosted_graphite'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/hosted_graphite.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
require 'hosted_graphite/version'
|
3
3
|
require 'hosted_graphite/protocol'
|
4
|
-
|
5
|
-
require 'hosted_graphite/tcp'
|
6
|
-
require 'hosted_graphite/http'
|
4
|
+
|
7
5
|
|
8
6
|
module HostedGraphite
|
9
7
|
extend Forwardable
|
10
8
|
extend self
|
9
|
+
attr_reader :namespace, :protocol
|
10
|
+
attr_writer :namespace, :api_key
|
11
11
|
|
12
12
|
def_delegators :protocol, :send_metric
|
13
13
|
module_function :send_metric
|
14
|
-
@protocol = nil
|
15
14
|
|
16
15
|
class MissingAPIKey < StandardError
|
17
16
|
def initialize
|
@@ -23,21 +22,14 @@ module HostedGraphite
|
|
23
22
|
@api_key ||= ENV['HOSTEDGRAPHITE_APIKEY']
|
24
23
|
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def protocol=(protocol)
|
26
|
+
protocol = protocol.to_s.downcase
|
27
|
+
require "hosted_graphite/protocols/#{protocol}"
|
28
|
+
@protocol = @registred_protocols[protocol].new
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def protocol=(protocol)
|
35
|
-
case protocol
|
36
|
-
when Class
|
37
|
-
@protocol = protocol.new
|
38
|
-
when String, Symbol
|
39
|
-
protocol = protocol.to_s.upcase
|
40
|
-
@protocol = const_get(protocol).new
|
41
|
-
end
|
31
|
+
@registred_protocols = {}
|
32
|
+
private def register(name, klass)
|
33
|
+
@registred_protocols[name] = klass
|
42
34
|
end
|
43
35
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
gem 'sidekiq', '>= 4.1.
|
1
|
+
gem 'sidekiq', '>= 4.1.2'
|
2
2
|
require 'sidekiq'
|
3
3
|
|
4
4
|
module HostedGraphite
|
5
5
|
module Ext
|
6
6
|
module Sidekiq
|
7
7
|
class Metrics
|
8
|
-
def initialize(namespace
|
8
|
+
def initialize(namespace=nil)
|
9
9
|
@client = HostedGraphite
|
10
|
-
|
10
|
+
HostedGraphite.namespace = namespace
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(worker, msg, _, &block)
|
14
14
|
w = msg['wrapped'] || worker.class.to_s
|
15
|
-
w = [
|
15
|
+
w = ['jobs', w].compact.join('.')
|
16
16
|
begin
|
17
17
|
@client.increment("#{w}.performed")
|
18
18
|
@client.time("#{w}.time", &block)
|
@@ -25,10 +25,10 @@ module HostedGraphite
|
|
25
25
|
end
|
26
26
|
|
27
27
|
class StatsdMetrics < Metrics
|
28
|
-
def initialize(namespace
|
28
|
+
def initialize(namespace=nil)
|
29
29
|
super
|
30
|
-
require 'hosted_graphite/statsd'
|
31
|
-
@client =
|
30
|
+
require 'hosted_graphite/protocols/statsd'
|
31
|
+
@client = STATSD.new
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
gem 'statsd-ruby'
|
2
|
+
require 'hosted_graphite'
|
3
|
+
require 'statsd'
|
4
|
+
|
5
|
+
module HostedGraphite
|
6
|
+
def_delegators :statsd, :increment, :decrement, :count, :gauge, :set, :timing, :time
|
7
|
+
|
8
|
+
class STATSD < Statsd
|
9
|
+
HOST = 'statsd.hostedgraphite.com'.freeze
|
10
|
+
PORT = 8125.freeze
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
raise MissingAPIKey unless HostedGraphite.api_key
|
14
|
+
super(HOST, PORT)
|
15
|
+
self.namespace = [HostedGraphite.api_key,HostedGraphite.namespace].join('.')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def statsd
|
20
|
+
@statsd ||= STATSD.new
|
21
|
+
end
|
22
|
+
|
23
|
+
register('statsd', STATSD)
|
24
|
+
end
|
@@ -1,33 +1 @@
|
|
1
|
-
|
2
|
-
require 'hosted_graphite'
|
3
|
-
require 'statsd'
|
4
|
-
|
5
|
-
module HostedGraphite
|
6
|
-
def_delegators :statsd, :increment, :decrement, :count, :gauge, :set, :timing, :time
|
7
|
-
|
8
|
-
class StatsD < Statsd
|
9
|
-
HOST = 'statsd.hostedgraphite.com'.freeze
|
10
|
-
PORT = 8125.freeze
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
raise MissingAPIKey unless HostedGraphite.api_key
|
14
|
-
super(HOST, PORT)
|
15
|
-
@namespace = HostedGraphite.api_key
|
16
|
-
@prefix = "#{@namespace}."
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
def socket
|
21
|
-
Thread.current[:hostedstatsd_socket] ||= UDPSocket.new addr_family
|
22
|
-
end
|
23
|
-
|
24
|
-
def addr_family
|
25
|
-
Addrinfo.udp(@host, @port).afamily
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def statsd
|
30
|
-
@statsd ||= StatsD.new
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
1
|
+
HostedGraphite.protocol = :stastd
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'hosted_graphite'
|
2
2
|
require 'securerandom'
|
3
|
+
require 'hosted_graphite/protocols/http'
|
4
|
+
require 'hosted_graphite/protocols/tcp'
|
5
|
+
require 'hosted_graphite/protocols/udp'
|
3
6
|
module HostedGraphite
|
4
7
|
@api_key = SecureRandom.hex
|
5
8
|
[TCP, UDP, HTTP].each do |protocol|
|
data/test/helper.rb
CHANGED
data/test/test_http_protocol.rb
CHANGED
@@ -3,14 +3,7 @@ require_relative 'helper'
|
|
3
3
|
class HTTPProtocolTest < Minitest::Test
|
4
4
|
attr_reader :api_key
|
5
5
|
def setup
|
6
|
-
|
7
|
-
@api_key = SecureRandom.uuid
|
8
|
-
HostedGraphite.api_key = @api_key
|
9
|
-
HostedGraphite.protocol = HostedGraphite::HTTP
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
HostedGraphite.api_key = @previous_api_key
|
6
|
+
HostedGraphite.protocol = :http
|
14
7
|
end
|
15
8
|
|
16
9
|
def test_http_protocol
|
data/test/test_stastd.rb
CHANGED
@@ -2,13 +2,7 @@ require_relative 'helper'
|
|
2
2
|
|
3
3
|
class StatsDTest < Minitest::Test
|
4
4
|
def setup
|
5
|
-
|
6
|
-
HostedGraphite.api_key = SecureRandom.uuid
|
7
|
-
require 'hosted_graphite/statsd'
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
HostedGraphite.api_key = @previous_api_key
|
5
|
+
HostedGraphite.protocol = 'statsd'
|
12
6
|
end
|
13
7
|
|
14
8
|
def test_respond_to_time
|
data/test/test_tcp_protocol.rb
CHANGED
@@ -4,22 +4,15 @@ class TCPProtocolTest < Minitest::Test
|
|
4
4
|
attr_reader :api_key
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@previous_api_key = HostedGraphite.api_key
|
8
|
-
@api_key = SecureRandom.uuid
|
9
|
-
HostedGraphite.api_key = @api_key
|
10
7
|
HostedGraphite.protocol = 'tcp'
|
11
8
|
end
|
12
9
|
|
13
|
-
def teardown
|
14
|
-
HostedGraphite.api_key = @previous_api_key
|
15
|
-
end
|
16
|
-
|
17
10
|
def test_tcp_protocol
|
18
11
|
assert_instance_of HostedGraphite::TCP, HostedGraphite.protocol
|
19
12
|
end
|
20
13
|
|
21
14
|
def test_correct_query
|
22
15
|
query = HostedGraphite.send_metric('foo', 1.2, 1421792423)
|
23
|
-
assert_equal "#{api_key}.foo 1.2 1421792423\n", query
|
16
|
+
assert_equal "#{HostedGraphite.api_key}.foo 1.2 1421792423\n", query
|
24
17
|
end
|
25
18
|
end
|
data/test/test_udp_protocol.rb
CHANGED
@@ -3,22 +3,15 @@ require_relative 'helper'
|
|
3
3
|
class UDPProtocolTest < Minitest::Test
|
4
4
|
attr_reader :api_key
|
5
5
|
def setup
|
6
|
-
@previous_api_key = HostedGraphite.api_key
|
7
|
-
@api_key = SecureRandom.uuid
|
8
|
-
HostedGraphite.api_key = @api_key
|
9
6
|
HostedGraphite.protocol = :udp
|
10
7
|
end
|
11
8
|
|
12
|
-
def teardown
|
13
|
-
HostedGraphite.api_key = @previous_api_key
|
14
|
-
end
|
15
|
-
|
16
9
|
def test_udp_protocol
|
17
10
|
assert_instance_of HostedGraphite::UDP, HostedGraphite.protocol
|
18
11
|
end
|
19
12
|
|
20
13
|
def test_correct_query
|
21
14
|
query = HostedGraphite.send_metric('foo', 1.2, 1421792423)
|
22
|
-
assert_equal "#{api_key}.foo 1.2 1421792423\n", query
|
15
|
+
assert_equal "#{HostedGraphite.api_key}.foo 1.2 1421792423\n", query
|
23
16
|
end
|
24
17
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdelkader Boudih
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,19 +61,23 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".travis.yml"
|
64
|
+
- CHANGELOG.md
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
68
71
|
- hosted_graphite.gemspec
|
69
72
|
- lib/hosted_graphite.rb
|
70
73
|
- lib/hosted_graphite/ext/sidekiq.rb
|
71
|
-
- lib/hosted_graphite/http.rb
|
72
74
|
- lib/hosted_graphite/protocol.rb
|
75
|
+
- lib/hosted_graphite/protocols/http.rb
|
76
|
+
- lib/hosted_graphite/protocols/statsd.rb
|
77
|
+
- lib/hosted_graphite/protocols/tcp.rb
|
78
|
+
- lib/hosted_graphite/protocols/udp.rb
|
73
79
|
- lib/hosted_graphite/statsd.rb
|
74
|
-
- lib/hosted_graphite/tcp.rb
|
75
80
|
- lib/hosted_graphite/testing.rb
|
76
|
-
- lib/hosted_graphite/udp.rb
|
77
81
|
- lib/hosted_graphite/version.rb
|
78
82
|
- test/helper.rb
|
79
83
|
- test/test_http_protocol.rb
|