statsd-opentsdb-client 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
|
|
1
|
+
module StatsdTaggable
|
2
|
+
|
3
|
+
class ActiveSupportSubscriber
|
4
|
+
|
5
|
+
def self.subscribe(statsd_client)
|
6
|
+
@client = statsd_client
|
7
|
+
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args|
|
8
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
9
|
+
controller = event.payload[:controller]
|
10
|
+
action = event.payload[:action]
|
11
|
+
format = event.payload[:format] || "all"
|
12
|
+
format = "all" if format == "*/*"
|
13
|
+
status = event.payload[:status]
|
14
|
+
path = event.payload[:path]
|
15
|
+
id = event.payload[:params]['id'] || 'null'
|
16
|
+
ActiveSupport::Notifications.instrument :performance, :action => :timing, :measurement => "total_duration",
|
17
|
+
:controller => controller, :controller_action => action,
|
18
|
+
:format => format, :path => path, :id => id, :value => event.duration
|
19
|
+
ActiveSupport::Notifications.instrument :performance, :action => :timing, :measurement => "db_time",
|
20
|
+
:controller => controller, :controller_action => action,
|
21
|
+
:format => format, :path => path, :id => id, :value => event.payload[:db_runtime]
|
22
|
+
ActiveSupport::Notifications.instrument :performance, :action => :timing, :measurement => "view_time",
|
23
|
+
:controller => controller, :controller_action => action,
|
24
|
+
:format => format, :path => path, :id => id, :value => event.payload[:view_runtime]
|
25
|
+
ActiveSupport::Notifications.instrument :performance, :measurement => "status", :controller => controller,
|
26
|
+
:controller_action => action, :format => format, :path => path, :id => id,
|
27
|
+
:status => status
|
28
|
+
end
|
29
|
+
ActiveSupport::Notifications.subscribe "performance" do |name, start, finish, id, payload|
|
30
|
+
self.send_event_to_statsd(@client, name, payload)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.mock_client(client)
|
35
|
+
@client = client
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def self.send_event_to_statsd(statsd_client, name, payload)
|
40
|
+
measurement = payload[:measurement]
|
41
|
+
value = payload[:value]
|
42
|
+
action = payload[:action] || :count
|
43
|
+
|
44
|
+
tags = Hash.new
|
45
|
+
tags[:controller] = payload[:controller].gsub(/::/, '-')
|
46
|
+
tags[:action] = payload[:controller_action]
|
47
|
+
tags[:format] = payload[:format]
|
48
|
+
# path often includes data and can be too long and varied -- not useful and hogs statsd memory
|
49
|
+
#tags[:path] = payload[:path][0..41]
|
50
|
+
tags[:id] = "#{payload[:id]}"[0..29]
|
51
|
+
tags[:status] = payload[:status] if payload.include? :status
|
52
|
+
|
53
|
+
statsd_client.send "#{action.to_s}_with_tags", "#{name.to_s}.#{measurement}", (value || 1), tags
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -2,25 +2,62 @@ require 'statsd-ruby'
|
|
2
2
|
|
3
3
|
module StatsdTaggable
|
4
4
|
class Client
|
5
|
+
extend Forwardable
|
6
|
+
def_delegators :@client, :gauge, :increment, :decrement, :count, :set, :timing, :time
|
7
|
+
|
5
8
|
def initialize(config)
|
6
9
|
@host = config[:host] || 'localhost'
|
7
10
|
@port = (config[:port] || 8125).to_i
|
8
11
|
@app_name = config[:app_name] || "my_app"
|
9
12
|
@tag_prefix = config[:tag_prefix] || '_t_'
|
10
|
-
@hostname = `hostname`.
|
11
|
-
@client = Statsd.new(@host
|
13
|
+
@hostname = `hostname`.split(".").first
|
14
|
+
@client = Statsd.new(@host, @port)
|
15
|
+
if config.include? :logger
|
16
|
+
Statsd.logger = config[:logger]
|
17
|
+
end
|
12
18
|
@default_tags = {
|
13
|
-
|
14
|
-
|
19
|
+
'host' => @hostname,
|
20
|
+
'app' => @app_name
|
15
21
|
}
|
16
22
|
end
|
17
23
|
|
18
|
-
|
19
|
-
|
24
|
+
|
25
|
+
def gauge_with_tags (metric, value, tags, sample_rate = 1)
|
26
|
+
with_tagged_name(metric, tags) { |new_metric_name| @client.gauge(new_metric_name, *[value, sample_rate]) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def increment_with_tags (metric, tags, sample_rate = 1)
|
30
|
+
with_tagged_name(metric, tags) { |new_metric_name| @client.increment(new_metric_name, sample_rate) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def decrement_with_tags (metric, tags, sample_rate = 1)
|
34
|
+
with_tagged_name(metric, tags) { |new_metric_name| @client.decrement(new_metric_name, sample_rate) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def count_with_tags (metric, count, tags, sample_rate = 1)
|
38
|
+
with_tagged_name(metric, tags) { |new_metric_name| @client.count(new_metric_name, count, sample_rate) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_with_tags (metric, value, tags, sample_rate = 1)
|
42
|
+
with_tagged_name(metric, tags) { |new_metric_name| @client.set(new_metric_name, value, sample_rate) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def timing_with_tags (metric, tim, tags, sample_rate = 1)
|
46
|
+
with_tagged_name(metric, tags) { |new_metric_name| @client.timing(new_metric_name, tim, sample_rate) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def time_with_tags (metric, tags, sample_rate = 1, &block)
|
50
|
+
with_tagged_name(metric, tags) { |new_metric_name| @client.time(new_metric_name, sample_rate, &block) }
|
51
|
+
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
|
55
|
+
def with_tagged_name (metric, tags)
|
56
|
+
yield encode_tags(metric, tags.merge(@default_tags))
|
20
57
|
end
|
21
58
|
|
22
59
|
def encode_tags(metric, tags)
|
23
|
-
tags.inject([metric]) do |memo, (k,v)|
|
60
|
+
tags.inject([metric]) do |memo, (k, v)|
|
24
61
|
memo << "#{@tag_prefix}#{sanitize(k)}.#{sanitize(v)}"
|
25
62
|
end.join(".")
|
26
63
|
end
|
@@ -45,8 +82,8 @@ module StatsdTaggable
|
|
45
82
|
rss = rss.to_i
|
46
83
|
pcpu = pcpu.to_f
|
47
84
|
|
48
|
-
@client.
|
49
|
-
@client.
|
85
|
+
@client.gauge_with_tags "statsd.apps.rss", rss, tags
|
86
|
+
@client.gauge_with_tags "statsd.apps.pcpu", pcpu, tags
|
50
87
|
end
|
51
88
|
end
|
52
89
|
end
|
metadata
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsd-opentsdb-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Bob Nugmanov
|
9
|
+
- Emmet Murphy
|
10
|
+
- Matt Camuto
|
8
11
|
autorequire:
|
9
12
|
bindir: bin
|
10
13
|
cert_chain: []
|
11
|
-
date:
|
14
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
12
15
|
dependencies:
|
13
16
|
- !ruby/object:Gem::Dependency
|
14
17
|
name: statsd-ruby
|
15
18
|
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
16
20
|
requirements:
|
17
21
|
- - ! '>='
|
18
22
|
- !ruby/object:Gem::Version
|
@@ -20,6 +24,7 @@ dependencies:
|
|
20
24
|
type: :runtime
|
21
25
|
prerelease: false
|
22
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
23
28
|
requirements:
|
24
29
|
- - ! '>='
|
25
30
|
- !ruby/object:Gem::Version
|
@@ -27,6 +32,7 @@ dependencies:
|
|
27
32
|
- !ruby/object:Gem::Dependency
|
28
33
|
name: rspec
|
29
34
|
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
30
36
|
requirements:
|
31
37
|
- - ! '>='
|
32
38
|
- !ruby/object:Gem::Version
|
@@ -34,6 +40,7 @@ dependencies:
|
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
37
44
|
requirements:
|
38
45
|
- - ! '>='
|
39
46
|
- !ruby/object:Gem::Version
|
@@ -41,6 +48,7 @@ dependencies:
|
|
41
48
|
- !ruby/object:Gem::Dependency
|
42
49
|
name: guard-rspec
|
43
50
|
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
44
52
|
requirements:
|
45
53
|
- - ! '>='
|
46
54
|
- !ruby/object:Gem::Version
|
@@ -48,6 +56,7 @@ dependencies:
|
|
48
56
|
type: :development
|
49
57
|
prerelease: false
|
50
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
51
60
|
requirements:
|
52
61
|
- - ! '>='
|
53
62
|
- !ruby/object:Gem::Version
|
@@ -59,30 +68,32 @@ executables: []
|
|
59
68
|
extensions: []
|
60
69
|
extra_rdoc_files: []
|
61
70
|
files:
|
71
|
+
- lib/statsd-opentsdb-client/active_support_subscriber.rb
|
62
72
|
- lib/statsd-opentsdb-client/statsd_taggable.rb
|
63
73
|
- lib/statsd-opentsdb-client.rb
|
64
|
-
homepage: http://github.com/
|
74
|
+
homepage: http://github.com/okl/statsd_opentsdb_client
|
65
75
|
licenses:
|
66
76
|
- MIT
|
67
|
-
metadata: {}
|
68
77
|
post_install_message:
|
69
78
|
rdoc_options: []
|
70
79
|
require_paths:
|
71
80
|
- lib
|
72
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
73
83
|
requirements:
|
74
84
|
- - ! '>='
|
75
85
|
- !ruby/object:Gem::Version
|
76
86
|
version: '0'
|
77
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
78
89
|
requirements:
|
79
90
|
- - ! '>='
|
80
91
|
- !ruby/object:Gem::Version
|
81
92
|
version: '0'
|
82
93
|
requirements: []
|
83
94
|
rubyforge_project:
|
84
|
-
rubygems_version:
|
95
|
+
rubygems_version: 1.8.25
|
85
96
|
signing_key:
|
86
|
-
specification_version:
|
97
|
+
specification_version: 3
|
87
98
|
summary: statsd opentsdb client
|
88
99
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
NDg1ZGQ4OTJjMDJhMWI1ZjU1OWM3MDg3Yzg1Y2Y2MWQ1OWE0NWQ4NQ==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MGRkM2I3MjMyMzkwZjFjNDc3NzNjMWMxNzk0Zjg4NTg2ZjJkNTgzYQ==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MGMzNmVjODMzZTRiNWFmYjYxYmM4MzA2MGVjZTU5MGU4YjMyN2ZmYjkyOGNj
|
10
|
-
NWEwNmE0MzdjNjM2Nzg0Njk2ZWZmM2IzYjlkNzBkZmRiMzI3NTg4NjdmMDY3
|
11
|
-
NTAxMjRlOTc4MGIyOTI0OTNmZTFlZGQ5MjBkYjY3Y2Y0NTY3ZmE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MzJiMTM3YTAyYjk3ZTRkNTAwZTgwMzczNTMzZWQ2ZTZmZWVlN2RiYTZmMTk5
|
14
|
-
OWM0YmU4N2VjMzc2MTcyMmFlMzY5NTEyOGY3YTljM2RiZjg5NmZjNzcxMjVm
|
15
|
-
OGI5N2U0NGVlM2M4MTM4OWFiZTZjZThhMWY4NTg0YzdhMGMzMWM=
|