Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow true/false for host spoofing

  • Loading branch information...
commit 6e67d929fea3f3dde635360c56495da9a9ddf2e0 1 parent fc9767b
@igrigorik authored
Showing with 42 additions and 25 deletions.
  1. +27 −25 README.rdoc
  2. +4 −0 lib/gmetric.rb
  3. +11 −0 spec/gmetric_spec.rb
View
52 README.rdoc
@@ -2,36 +2,38 @@
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.
+- http://www.igvita.com/2010/01/28/cluster-monitoring-with-ganglia-ruby/
+
== Example: Sending a gmetric to a gmond over UDP
- Ganglia::GMetric.send("127.0.0.1", 8670, {
- :name => 'pageviews',
- :units => 'req/min',
- :type => 'uint8',
- :value => 7000,
- :tmax => 60,
- :dmax => 300
- })
+ Ganglia::GMetric.send("127.0.0.1", 8670, {
+ :name => 'pageviews',
+ :units => 'req/min',
+ :type => 'uint8',
+ :value => 7000,
+ :tmax => 60,
+ :dmax => 300
+ })
== Example: Generating the Meta and Metric packets
- g = Ganglia::GMetric.pack(
- :slope => 'positive',
- :name => 'ruby',
- :value => rand(100),
- :tmax => 60,
- :units => '',
- :dmax => 60,
- :type => 'uint8'
- )
-
- # g[0] = meta packet
- # g[1] = gmetric packet
-
- s = UDPSocket.new
- s.connect("127.0.0.1", 8670)
- s.send g[0], 0
- s.send g[1], 0
+ g = Ganglia::GMetric.pack(
+ :slope => 'positive',
+ :name => 'ruby',
+ :value => rand(100),
+ :tmax => 60,
+ :units => '',
+ :dmax => 60,
+ :type => 'uint8'
+ )
+
+ # g[0] = meta packet
+ # g[1] = gmetric packet
+
+ s = UDPSocket.new
+ s.connect("127.0.0.1", 8670)
+ s.send g[0], 0
+ s.send g[1], 0
== License
View
4 lib/gmetric.rb
@@ -31,6 +31,10 @@ def self.pack(metric)
:dmax => 0
}.merge(metric)
+ # convert bools to ints
+ metric[:spoof] = 1 if metric[:spoof].is_a? TrueClass
+ metric[:spoof] = 0 if metric[:spoof].is_a? FalseClass
+
raise "Missing key, value, type" if not metric.key? :name or not metric.key? :value or not metric.key? :type
raise "Invalid metric type" if not %w(string int8 uint8 int16 uint16 int32 uint32 float double).include? metric[:type]
View
11 spec/gmetric_spec.rb
@@ -64,4 +64,15 @@ def hex(data)
Ganglia::GMetric.pack(data)
}.should raise_error
end
+
+ it "should allow host spoofing" do
+ lambda {
+ data = {:name => 'a', :type => 'uint8', :value => 'c', :spoof => 1, :host => 'host'}
+ Ganglia::GMetric.pack(data)
+
+ data = {:name => 'a', :type => 'uint8', :value => 'c', :spoof => true, :host => 'host'}
+ Ganglia::GMetric.pack(data)
+ }.should_not raise_error
+
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.