gmetric 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +2 -0
  2. data/VERSION +1 -1
  3. data/lib/gmetric.rb +27 -16
  4. data/spec/gmetric_spec.rb +21 -1
  5. metadata +12 -5
@@ -2,6 +2,8 @@
2
2
 
3
3
  A pure Ruby client for generating Ganglia 3.1.x+ gmetric meta and metric packets and talking to your gmond / gmetad nodes over UDP protocol. Supports host spoofing, and all the same parameters as the gmetric command line executable.
4
4
 
5
+ - http://www.igvita.com/2010/01/28/cluster-monitoring-with-ganglia-ruby/
6
+
5
7
  == Example: Sending a gmetric to a gmond over UDP
6
8
 
7
9
  Ganglia::GMetric.send("127.0.0.1", 8670, {
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -16,47 +16,58 @@ module Ganglia
16
16
  conn = UDPSocket.new
17
17
  conn.connect(host, port)
18
18
  gmetric = self.pack(metric)
19
-
19
+
20
20
  conn.send gmetric[0], 0
21
21
  conn.send gmetric[1], 0
22
22
  end
23
23
 
24
24
  def self.pack(metric)
25
25
  metric = {
26
- :hostname => '',
26
+ :hostname => '',
27
+ :group => '',
27
28
  :spoof => 0,
28
29
  :units => '',
29
30
  :slope => 'both',
30
31
  :tmax => 60,
31
32
  :dmax => 0
32
33
  }.merge(metric)
33
-
34
+
35
+ # convert bools to ints
36
+ metric[:spoof] = 1 if metric[:spoof].is_a? TrueClass
37
+ metric[:spoof] = 0 if metric[:spoof].is_a? FalseClass
38
+
34
39
  raise "Missing key, value, type" if not metric.key? :name or not metric.key? :value or not metric.key? :type
35
40
  raise "Invalid metric type" if not %w(string int8 uint8 int16 uint16 int32 uint32 float double).include? metric[:type]
36
-
41
+
37
42
  meta = XDRPacket.new
38
43
  data = XDRPacket.new
39
-
44
+
40
45
  # METADATA payload
41
46
  meta.pack_int(128) # gmetadata_full
42
47
  meta.pack_string(metric[:hostname]) # hostname
43
48
  meta.pack_string(metric[:name].to_s) # name of the metric
44
49
  meta.pack_int(metric[:spoof].to_i) # spoof hostname flag
45
-
50
+
46
51
  meta.pack_string(metric[:type].to_s) # one of: string, int8, uint8, int16, uint16, int32, uint32, float, double
47
- meta.pack_string(metric[:name].to_s) # name of the metric
52
+ meta.pack_string(metric[:name].to_s) # name of the metric
48
53
  meta.pack_string(metric[:units].to_s) # units for the value, e.g. 'kb/sec'
49
54
  meta.pack_int(SLOPE[metric[:slope]]) # sign of the derivative of the value over time, one of zero, positive, negative, both, default both
50
55
  meta.pack_uint(metric[:tmax].to_i) # maximum time in seconds between gmetric calls, default 60
51
56
  meta.pack_uint(metric[:dmax].to_i) # lifetime in seconds of this metric, default=0, meaning unlimited
52
- meta.pack_int(0)
53
-
54
- # DATA payload
55
- data.pack_int(128+5) # string message
56
- data.pack_string(metric[:hostname].to_s) # hostname
57
- data.pack_string(metric[:name].to_s) # name of the metric
58
- data.pack_int(metric[:spoof].to_i) # spoof hostname flag
59
- data.pack_string("%s") #
57
+
58
+ ## MAGIC NUMBER: equals the elements of extra data, here it's 1 because I added Group.
59
+ meta.pack_int(1)
60
+
61
+ ## METADATA EXTRA DATA: functionally key/value
62
+ meta.pack_string("GROUP")
63
+ meta.pack_string(metric[:group].to_s)
64
+
65
+ # DATA payload
66
+ data.pack_int(128+5) # string message
67
+ data.pack_string(metric[:hostname].to_s) # hostname
68
+ data.pack_string(metric[:name].to_s) # name of the metric
69
+ data.pack_int(metric[:spoof].to_i) # spoof hostname flag
70
+ data.pack_string("%s") #
60
71
  data.pack_string(metric[:value].to_s) # value of the metric
61
72
 
62
73
  [meta.data, data.data]
@@ -88,4 +99,4 @@ module Ganglia
88
99
  @data.string
89
100
  end
90
101
  end
91
- end
102
+ end
@@ -37,7 +37,7 @@ describe Ganglia::GMetric do
37
37
 
38
38
  g = Ganglia::GMetric.pack(data)
39
39
  g.size.should == 2
40
- g[0].should == "\000\000\000\200\000\000\000\000\000\000\000\003foo\000\000\000\000\000\000\000\000\006string\000\000\000\000\000\003foo\000\000\000\000\000\000\000\000\003\000\000\000<\000\000\000\000\000\000\000\000"
40
+ g[0].should == "\000\000\000\200\000\000\000\000\000\000\000\003foo\000\000\000\000\000\000\000\000\006string\000\000\000\000\000\003foo\000\000\000\000\000\000\000\000\003\000\000\000<\000\000\000\000\000\000\000\001\000\000\000\005GROUP\000\000\000\000\000\000\000"
41
41
  g[1].should == "\000\000\000\205\000\000\000\000\000\000\000\003foo\000\000\000\000\000\000\000\000\002%s\000\000\000\000\000\003bar\000"
42
42
  end
43
43
 
@@ -64,4 +64,24 @@ describe Ganglia::GMetric do
64
64
  Ganglia::GMetric.pack(data)
65
65
  }.should raise_error
66
66
  end
67
+
68
+ it "should allow host spoofing" do
69
+ lambda {
70
+ data = {:name => 'a', :type => 'uint8', :value => 'c', :spoof => 1, :host => 'host'}
71
+ Ganglia::GMetric.pack(data)
72
+
73
+ data = {:name => 'a', :type => 'uint8', :value => 'c', :spoof => true, :host => 'host'}
74
+ Ganglia::GMetric.pack(data)
75
+ }.should_not raise_error
76
+
77
+ end
78
+
79
+ it "should allow group meta data" do
80
+ lambda {
81
+ data = {:name => 'a', :type => 'uint8', :value => 'c', :spoof => 1, :host => 'host', :group => 'test'}
82
+ g = Ganglia::GMetric.pack(data)
83
+ g[0].should == "\000\000\000\200\000\000\000\000\000\000\000\001a\000\000\000\000\000\000\001\000\000\000\005uint8\000\000\000\000\000\000\001a\000\000\000\000\000\000\000\000\000\000\003\000\000\000<\000\000\000\000\000\000\000\001\000\000\000\005GROUP\000\000\000\000\000\000\004test"
84
+
85
+ }.should_not raise_error
86
+ end
67
87
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmetric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Ilya Grigorik
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-28 00:00:00 -05:00
17
+ date: 2010-06-13 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -41,18 +46,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
41
46
  requirements:
42
47
  - - ">="
43
48
  - !ruby/object:Gem::Version
49
+ segments:
50
+ - 0
44
51
  version: "0"
45
- version:
46
52
  required_rubygems_version: !ruby/object:Gem::Requirement
47
53
  requirements:
48
54
  - - ">="
49
55
  - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
50
58
  version: "0"
51
- version:
52
59
  requirements: []
53
60
 
54
61
  rubyforge_project: gmetric
55
- rubygems_version: 1.3.5
62
+ rubygems_version: 1.3.6
56
63
  signing_key:
57
64
  specification_version: 3
58
65
  summary: Pure Ruby interface for generating Ganglia gmetric packets