hosted_graphite 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -5
- data/CHANGELOG.md +5 -1
- data/README.md +23 -11
- data/hosted_graphite.gemspec +1 -1
- data/lib/hosted_graphite.rb +17 -7
- data/lib/hosted_graphite/protocols/statsd.rb +5 -1
- data/lib/hosted_graphite/statsd.rb +1 -1
- data/lib/hosted_graphite/version.rb +1 -1
- data/test/test_enabling.rb +35 -0
- data/test/test_stastd.rb +18 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4272720da2d9eb6e32be3a43dd1b7188fc363550
|
4
|
+
data.tar.gz: e12ca2cb51e10288ccf138740f3541f7fbad908d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d6779726beaaeac6d344c0f26846d087a1d3cefc59884a01d5dc41a3ac427a921f6e08349c69c70c7b303a4106153f545180a879df6bb17a5b47882eebb7c17
|
7
|
+
data.tar.gz: '048f1ff89f556e12537c6b421d8cce685b31d5adfdf914de1dfd7d54605309dcd77f54de56f9c5d048ec7b0053c8308f8e42dfd07d87d08b23ea0acc2b8c72e2'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -32,10 +32,16 @@ Your API key can be found on your [account home](https://www.hostedgraphite.com/
|
|
32
32
|
|
33
33
|
You can also set the hosted graphite API key programatically with:
|
34
34
|
|
35
|
-
```
|
35
|
+
```ruby
|
36
36
|
HostedGraphite.api_key = 'YOUR API KEY'
|
37
37
|
```
|
38
38
|
|
39
|
+
You may also specify a namespace for your metrics, which will be applied if you are using the StatsD backend:
|
40
|
+
|
41
|
+
```bash
|
42
|
+
HostedGraphite.namespace = 'our_app'
|
43
|
+
```
|
44
|
+
|
39
45
|
#### Sending a metric via UDP
|
40
46
|
```ruby
|
41
47
|
HostedGraphite.protocol = :udp
|
@@ -81,17 +87,23 @@ HostedGraphite.time('newsletter.monthly') { @newsletter.deliver_now }
|
|
81
87
|
|
82
88
|
### Extensions
|
83
89
|
#### Sidekiq
|
84
|
-
```ruby
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
90
|
+
```ruby
|
91
|
+
require 'hosted_graphite/ext/sidekiq'
|
92
|
+
|
93
|
+
Sidekiq.configure_server do |config|
|
94
|
+
config.server_middleware do |chain|
|
95
|
+
# my_app is an optional namespace
|
96
|
+
# chain.prepend HostedGraphite::Ext::Sidekiq::StatsdMetrics, 'my_app'
|
97
|
+
# or
|
98
|
+
# chain.prepend HostedGraphite::Ext::Sidekiq::Metrics
|
94
99
|
end
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
### Disable sends for local/test environments
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
HostedGraphite.enabled = false unless Rails.env.production?
|
95
107
|
```
|
96
108
|
|
97
109
|
## Contributing
|
data/hosted_graphite.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.summary = 'A Ruby client for HostedGraphite'
|
11
11
|
spec.homepage = 'https://github.com/seuros/hosted_graphite'
|
12
12
|
spec.license = 'Apache 2.0'
|
13
|
-
spec.required_ruby_version = '>=
|
13
|
+
spec.required_ruby_version = '>= 2.0.0'
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
data/lib/hosted_graphite.rb
CHANGED
@@ -6,11 +6,10 @@ require 'hosted_graphite/protocol'
|
|
6
6
|
module HostedGraphite
|
7
7
|
extend Forwardable
|
8
8
|
extend self
|
9
|
-
attr_reader :namespace, :protocol
|
10
|
-
attr_writer :namespace, :api_key
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
attr_accessor :namespace, :enabled
|
11
|
+
attr_reader :protocol
|
12
|
+
attr_writer :api_key
|
14
13
|
|
15
14
|
class MissingAPIKey < StandardError
|
16
15
|
def initialize
|
@@ -22,14 +21,25 @@ module HostedGraphite
|
|
22
21
|
@api_key ||= ENV['HOSTEDGRAPHITE_APIKEY']
|
23
22
|
end
|
24
23
|
|
25
|
-
|
24
|
+
def enabled?
|
25
|
+
@enabled.nil? ? true : @enabled
|
26
|
+
end
|
27
|
+
|
28
|
+
def send_metric(*args)
|
29
|
+
protocol.send_metric(*args) if enabled?
|
30
|
+
end
|
31
|
+
module_function :send_metric
|
32
|
+
|
33
|
+
def protocol=(protocol)
|
26
34
|
protocol = protocol.to_s.downcase
|
27
35
|
require "hosted_graphite/protocols/#{protocol}"
|
28
36
|
@protocol = @registred_protocols[protocol].new
|
29
|
-
|
37
|
+
end
|
30
38
|
|
31
39
|
@registred_protocols = {}
|
32
|
-
private
|
40
|
+
private
|
41
|
+
|
42
|
+
def register(name, klass)
|
33
43
|
@registred_protocols[name] = klass
|
34
44
|
end
|
35
45
|
end
|
@@ -12,7 +12,11 @@ module HostedGraphite
|
|
12
12
|
def initialize
|
13
13
|
raise MissingAPIKey unless HostedGraphite.api_key
|
14
14
|
super(HOST, PORT)
|
15
|
-
|
15
|
+
if HostedGraphite.namespace
|
16
|
+
self.namespace = [HostedGraphite.api_key,HostedGraphite.namespace].join('.')
|
17
|
+
else
|
18
|
+
self.namespace = HostedGraphite.api_key
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
@@ -1 +1 @@
|
|
1
|
-
HostedGraphite.protocol = :
|
1
|
+
HostedGraphite.protocol = :statsd
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class DefaultBehaviourTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
HostedGraphite.protocol = :http
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_enabled_by_default
|
9
|
+
assert_equal true, HostedGraphite.enabled?
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_send_by_default
|
13
|
+
assert_send [HostedGraphite.protocol, :send_metric, *['foo', 1.2]]
|
14
|
+
HostedGraphite.send_metric 'foo', 1.2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
class DisabledTest < Minitest::Test
|
20
|
+
def setup
|
21
|
+
@previous_api_key = HostedGraphite.api_key
|
22
|
+
HostedGraphite.api_key = nil
|
23
|
+
HostedGraphite.enabled = false
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
HostedGraphite.enabled = nil
|
28
|
+
HostedGraphite.api_key = @previous_api_key
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_metric_send
|
32
|
+
# Will raise HostedGraphite::MissingAPIKey if incorrect
|
33
|
+
HostedGraphite.send_metric 'foo', 1.2
|
34
|
+
end
|
35
|
+
end
|
data/test/test_stastd.rb
CHANGED
@@ -28,4 +28,22 @@ class StatsDTest < Minitest::Test
|
|
28
28
|
def test_respond_to_increment
|
29
29
|
assert_respond_to HostedGraphite, :increment
|
30
30
|
end
|
31
|
+
|
32
|
+
def test_initialize_without_namespace
|
33
|
+
old_namespace = HostedGraphite.namespace
|
34
|
+
HostedGraphite.namespace = nil
|
35
|
+
|
36
|
+
assert_equal HostedGraphite.api_key, HostedGraphite::STATSD.new.namespace
|
37
|
+
|
38
|
+
HostedGraphite.namespace = old_namespace
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_initialize_with
|
42
|
+
old_namespace = HostedGraphite.namespace
|
43
|
+
HostedGraphite.namespace = "foo"
|
44
|
+
|
45
|
+
assert_equal "#{HostedGraphite.api_key}.foo", HostedGraphite::STATSD.new.namespace
|
46
|
+
|
47
|
+
HostedGraphite.namespace = old_namespace
|
48
|
+
end
|
31
49
|
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2016-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/hosted_graphite/testing.rb
|
81
81
|
- lib/hosted_graphite/version.rb
|
82
82
|
- test/helper.rb
|
83
|
+
- test/test_enabling.rb
|
83
84
|
- test/test_http_protocol.rb
|
84
85
|
- test/test_missing_apikey.rb
|
85
86
|
- test/test_stastd.rb
|
@@ -97,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
98
|
requirements:
|
98
99
|
- - ">="
|
99
100
|
- !ruby/object:Gem::Version
|
100
|
-
version:
|
101
|
+
version: 2.0.0
|
101
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
103
|
requirements:
|
103
104
|
- - ">="
|
@@ -105,12 +106,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
106
|
version: '0'
|
106
107
|
requirements: []
|
107
108
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.5.
|
109
|
+
rubygems_version: 2.5.2
|
109
110
|
signing_key:
|
110
111
|
specification_version: 4
|
111
112
|
summary: A Ruby client for HostedGraphite
|
112
113
|
test_files:
|
113
114
|
- test/helper.rb
|
115
|
+
- test/test_enabling.rb
|
114
116
|
- test/test_http_protocol.rb
|
115
117
|
- test/test_missing_apikey.rb
|
116
118
|
- test/test_stastd.rb
|