statsd-opentsdb-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/statsd_taggable.rb +48 -0
  3. metadata +87 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTQ2OGZhOGFjN2YxZGQ1NDUxNmVhNzkwOGEyZTJjYjE5OGMyM2NiZQ==
5
+ data.tar.gz: !binary |-
6
+ ZTk4YTRkMTA1Y2ExNzRjNzhiMWU4MGRlOWJjZmVhYWVmOGIxYmFiZQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MDE3YzE0ODg0MmY1NTYzMjMxNDkxMzU3NDQzMTA3Mzg4NGU1ODZmMDZlNmY0
10
+ M2ZjMjUyMzg5MDk4OGU1Y2EyYzFkN2U0YmI1NGE0ODQ3OTc4Y2MxMGFmNWVh
11
+ MmM2NmFiYWFlOTIzZGFiODRmNzg1OWFkY2Y5ODRiNzJkNDAxNjk=
12
+ data.tar.gz: !binary |-
13
+ NTRhNWY5MDFlM2IxNTNmM2Q3N2NlNTllOGM4ZWExZmVmOWEwMmIwZWU5OTQ3
14
+ N2U2Y2NkOWNhNzg0MDZiYTc3ZTY1OGIyNmM1M2E3NGJiMjI0Y2ViNDkyZmI5
15
+ MDc5OTZlYjhjZmI3ZGUxYjRmMGEwZTcxZGExNTI0NzFmMDdjODU=
@@ -0,0 +1,48 @@
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
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statsd-opentsdb-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bob Nugmanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: statsd-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: statsd client for using with statsd_opentsdb_backend, with tag support
56
+ email:
57
+ - bob.nugmanov@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/statsd_taggable.rb
63
+ homepage: http://github.com/bnugmanov/statsd_opentsdb_client
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.0.7
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: statsd opentsdb client
87
+ test_files: []