statsd-opentsdb-client 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 +8 -8
- data/lib/statsd-opentsdb-client/statsd_taggable.rb +52 -0
- data/lib/statsd-opentsdb-client.rb +1 -4
- metadata +3 -3
- data/lib/statsd_taggable.rb +0 -48
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODgzNmI3OTgwNTIwMTMyNTdkNmFhZTQxNGZkYmRhZjJiNjlhOGFkMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDQ4OWY0ZTEyYmM3MTgxOWM0ZTFlYjA4OTY4NzY0ODFmMDY1M2JiNg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDlmMTE2MWU3YmM0ZmJlOGU5YmVlMGJkNmRhZWNkNmUzZDRkNTQ0MGM1NThk
|
10
|
+
N2IzMWI5MWFjNTQzOThhNDMzMGZlYTU4MzdhYWJhZTRmZDUwOTk5OGVmZTA0
|
11
|
+
NWJmODJiMWIyNzMwMjVlNGI4ZGEzNTk3MWRiMDUwNTFjOGE5NTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjgzODc4OGJkYzBiODE2ZDM1YTM4NmJlOTY5MGNhYjg5Yjg5MjEzN2E4NDU4
|
14
|
+
YjU2MzgwYzhlODUwNTU5NjhkZTg0ZTY5ZjAyNGRiOWRiNzAwY2VhMjllM2I0
|
15
|
+
MTg5OGNiNDg1MmUwODRhMjY0MGU1ZTIzNGY0M2E4NTY1OGVjYmM=
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'statsd-ruby'
|
2
|
+
|
3
|
+
module StatsdTaggable
|
4
|
+
class Client
|
5
|
+
def initialize(config)
|
6
|
+
@host = config[:host] || 'localhost'
|
7
|
+
@port = (config[:port] || 8125).to_i
|
8
|
+
@app_name = config[:app_name] || "my_app"
|
9
|
+
@tag_prefix = config[:tag_prefix] || '_t_'
|
10
|
+
@hostname = `hostname`.to_s.strip.split(".").first
|
11
|
+
@client = Statsd.new(@host,@port)
|
12
|
+
@default_tags = {
|
13
|
+
'host' => @hostname,
|
14
|
+
'app' => @app_name
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def gauge(metric, tags, value)
|
19
|
+
@client.gauge(encode_tags(metric, tags.merge(@default_tags)), value)
|
20
|
+
end
|
21
|
+
|
22
|
+
def encode_tags(metric, tags)
|
23
|
+
tags.inject([metric]) do |memo, (k,v)|
|
24
|
+
memo << "#{@tag_prefix}#{sanitize(k)}.#{sanitize(v)}"
|
25
|
+
end.join(".")
|
26
|
+
end
|
27
|
+
|
28
|
+
def sanitize v
|
29
|
+
v.to_s.gsub ".", "_"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class BasicMetrics
|
34
|
+
def initialize(c)
|
35
|
+
@client = c
|
36
|
+
end
|
37
|
+
|
38
|
+
def emit(tags = {})
|
39
|
+
|
40
|
+
# TODO: ensure shelling out doesn't happen too often, e.g.,
|
41
|
+
# preserve a timestamp of the last shell-out, and refuse to shell-out
|
42
|
+
# again unless the timestamp is old enough (e.g. 10 seconds)
|
43
|
+
|
44
|
+
rss, pcpu = `ps -o rss=,pcpu= -p #{Process.pid}`.split
|
45
|
+
rss = rss.to_i
|
46
|
+
pcpu = pcpu.to_f
|
47
|
+
|
48
|
+
@client.gauge "statsd.apps.rss", tags, rss
|
49
|
+
@client.gauge "statsd.apps.pcpu", tags, pcpu
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Nugmanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: statsd-ruby
|
@@ -59,8 +59,8 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- lib/statsd-opentsdb-client/statsd_taggable.rb
|
62
63
|
- lib/statsd-opentsdb-client.rb
|
63
|
-
- lib/statsd_taggable.rb
|
64
64
|
homepage: http://github.com/bnugmanov/statsd_opentsdb_client
|
65
65
|
licenses:
|
66
66
|
- MIT
|
data/lib/statsd_taggable.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'statsd-ruby'
|
2
|
-
|
3
|
-
module Statsd_Taggable
|
4
|
-
class Client
|
5
|
-
def initialize(config)
|
6
|
-
@host = config[:host] || 'localhost'
|
7
|
-
@port = (config[:port] || 8125).to_i
|
8
|
-
@app_name = config[:app_name] || "my_app"
|
9
|
-
@tag_prefix = config[:tag_prefix] || '_t_'
|
10
|
-
@client = Statsd.new(@host,@port)
|
11
|
-
end
|
12
|
-
|
13
|
-
def gauge(metric, tags, value)
|
14
|
-
@client.gauge(encode_tags(metric, tags), value)
|
15
|
-
end
|
16
|
-
|
17
|
-
def encode_tags(metric, tags)
|
18
|
-
terms = [metric]
|
19
|
-
tags.each do |k,v|
|
20
|
-
terms << "#{@tag_prefix}#{sanitize(k)}.#{sanitize(v)}"
|
21
|
-
end
|
22
|
-
terms.join(".")
|
23
|
-
end
|
24
|
-
|
25
|
-
def expand_tags tags
|
26
|
-
tags['host'] = `hostname`.strip
|
27
|
-
tags['app'] = @app_name
|
28
|
-
tags
|
29
|
-
end
|
30
|
-
|
31
|
-
def sanitize v
|
32
|
-
v.to_s.gsub ".", "_"
|
33
|
-
end
|
34
|
-
|
35
|
-
#TODO: consider extracting
|
36
|
-
def basic_metrics
|
37
|
-
rss, pcpu = `ps -o rss=,pcpu= -p #{Process.pid}`.split
|
38
|
-
rss = rss.to_i
|
39
|
-
pcpu = pcpu.to_f
|
40
|
-
|
41
|
-
tags = expand_tags({})
|
42
|
-
puts "Basic rss,pcpu: #{rss} #{pcpu}"
|
43
|
-
|
44
|
-
gauge "statsd.apps.rss", tags, rss
|
45
|
-
gauge "statsd.apps.pcpu", tags, pcpu
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|