initial
This commit is contained in:
72
files/ganglia/puppetmaster.rb
Normal file
72
files/ganglia/puppetmaster.rb
Normal file
@@ -0,0 +1,72 @@
|
||||
#! /bin/env ruby
|
||||
|
||||
# returns the mem usage of a given process
|
||||
$gmetric = %x{which gmetric}.chomp
|
||||
exit 0 unless $gmetric != ""
|
||||
|
||||
def plist(psname)
|
||||
whats = ["rss","size","vsize","cpu"]
|
||||
%x{ps h -o rss,size,vsize,pcpu,command -C ruby1.8 |grep #{psname}|cut -f 1-4 -d ' '}.each do |ps|
|
||||
#rss,size,vsize,cpu,command = ps.split
|
||||
counter = 0
|
||||
ps.split.each { |value|
|
||||
what = whats[counter]
|
||||
counter += 1
|
||||
units = counter == 4 ? "time" : "kbyte"
|
||||
# puts "#{psname}_#{counter}_#{what} V=#{value} U=#{units}"
|
||||
gmetric("#{psname}_#{counter}_#{what}",value,units)
|
||||
}
|
||||
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
def gmetric(name,value,units)
|
||||
%x{#{$gmetric} --type=float --units=#{units} --name=#{name} --value=#{value} --slope=positive --tmax=300 --dmax=300000}
|
||||
end
|
||||
|
||||
# reports how many clients compiled in the last 5 minutes
|
||||
# repotrs how many unique clients compiled since the begining of the day
|
||||
# report the average compilation time for all clients in the last 5 minutes.
|
||||
def phaselog
|
||||
logfile = ENV['puppet_logfile'] || '/var/log/daemon.log'
|
||||
count,avg,day_count_unique,day_count = 0 ,0 ,0, 0
|
||||
t = Time.now
|
||||
today = t.strftime("^%b %d")
|
||||
hour = t.strftime("%H:")
|
||||
m = t.min.to_i
|
||||
last5m = ""
|
||||
6.times do |i|
|
||||
last5m += hour
|
||||
last5m += "0" if (m-i) < 10
|
||||
last5m += (m-i).to_s
|
||||
last5m += "|" unless i==5
|
||||
end
|
||||
hosts = Array.new
|
||||
regexp = ".* for (.*) in (.*) seconds"
|
||||
File.open(logfile).grep(/#{today}/).grep(/Compiled configuration|Compiled catalog/).each do |line|
|
||||
case line
|
||||
when /#{last5m}/ then
|
||||
if line =~ /#{regexp}/
|
||||
avg += $2.to_f
|
||||
count += 1
|
||||
unless hosts.include?($1)
|
||||
hosts << $1
|
||||
end
|
||||
end
|
||||
when /#{regexp}/ then
|
||||
day_count += 1
|
||||
unless hosts.include?($1)
|
||||
hosts << $1
|
||||
day_count_unique += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
gmetric("puppetmasterd avg_compile",(avg / count).to_s[0..3],"seconds") unless count == 0
|
||||
gmetric("puppetmasterd last5m_count",count,"clients")
|
||||
gmetric("puppetmasterd last24h_unique_count", day_count_unique, "clients")
|
||||
end
|
||||
|
||||
plist("puppetmasterd")
|
||||
gmetric("puppetmasterd known_clients",Dir.entries('/var/lib/puppet/yaml/facts/').size-2,"clients")
|
||||
phaselog
|
||||
Reference in New Issue
Block a user