Skip to content

Instantly share code, notes, and snippets.

@ipl31
Created November 20, 2010 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipl31/707980 to your computer and use it in GitHub Desktop.
Save ipl31/707980 to your computer and use it in GitHub Desktop.
Ruby Gmetric example that counts dir listings and sends them to a ganglia cluster
#Simple ganglia gmetric plugin using the gmetric gem.
#Counts entries in a dir and reports them to the ganglia cluster using
#the gmetric ruby gem
require 'rubygems'
require 'gmetric'
#Tmax indicates freshness, if TN(seconds since metric was updated) exceeds tmax then ganglia will expect a new value
#Dmax indicates how long an old metric should be retained
#decsripitions taken from http://monami.sourceforge.net/tutorial/ar01s06.html
tmax = 60
dmax = 300
#first argument is a host gmond host in the cluster
#second argument is the port
gmondhost = ARGV[0]
gmondport = ARGV[1]
dir = '/home/ken/'
graph_name = "Directory Listing Count in #{dir}"
units = "Files/Directories"
file_count = Dir.entries(dir).count
Ganglia::GMetric.send(gmondhost, gmondport, {
:name => graph_name,
:units => units,
:type => 'uint8',
:value => file_count,
:tmax => 60,
:dmax => 300
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment