root / plugins / puppet / puppetmaster @ 9f85e0ae
Historique | Voir | Annoter | Télécharger (3,46 ko)
| 1 | d2491a19 | Antoine Beaupré | #!/usr/bin/ruby |
|---|---|---|---|
| 2 | 573d1225 | ohadlevy@gmail.com | |
| 3 | 93a7c793 | Antoine Beaupré | # this plugin reports various performance statistics from a puppetmaster |
| 4 | # server and client |
||
| 5 | # |
||
| 6 | # linked as puppet_mem, it will display memory usage of the puppet |
||
| 7 | # client and puppet master on the local server. |
||
| 8 | # |
||
| 9 | # linked as puppet_clients, it will report the average compile time, the |
||
| 10 | # number of clients that checked in in the last 5 minutes and 24h and |
||
| 11 | # the number of known clients. |
||
| 12 | # |
||
| 13 | # it requires read access to the puppet logfile. |
||
| 14 | # |
||
| 15 | # CONFIGURATION |
||
| 16 | # |
||
| 17 | # [puppet*] |
||
| 18 | # env.puppet_logfile /var/log/message |
||
| 19 | # env.puppet_logformat "^%b %d" |
||
| 20 | # |
||
| 21 | # the logfile is where the puppetmaster is expected to log its |
||
| 22 | # compilation statistics. the format is the format of the date syslog |
||
| 23 | # writes to the file, which may vary according to locale and |
||
| 24 | # configuration. |
||
| 25 | |||
| 26 | 573d1225 | ohadlevy@gmail.com | # returns the mem usage of a given process |
| 27 | def plist(psname) |
||
| 28 | counter = 0 |
||
| 29 | %x{ps h -o rss,size,vsize,pcpu -C #{psname}}.each do |ps|
|
||
| 30 | rss,size,vsize,cpu = ps.split |
||
| 31 | counter += 1 |
||
| 32 | puts "#{psname}_#{counter}.value #{rss}"
|
||
| 33 | |||
| 34 | end |
||
| 35 | return |
||
| 36 | end |
||
| 37 | |||
| 38 | # reports how many clients compiled in the last 5 minutes |
||
| 39 | # repotrs how many unique clients compiled since the begining of the day |
||
| 40 | # report the average compilation time for all clients in the last 5 minutes. |
||
| 41 | def phaselog |
||
| 42 | logfile = ENV['puppet_logfile'] || '/var/log/messages' |
||
| 43 | count,avg,day_count_unique,day_count = 0 ,0 ,0, 0 |
||
| 44 | t = Time.now |
||
| 45 | ee0f13f3 | Antoine Beaupré | dateformat = ENV['puppet_logformat'] || "^%b %d" |
| 46 | today = t.strftime(dateformat) |
||
| 47 | hour = t.strftime(dateformat + " %H:") |
||
| 48 | 573d1225 | ohadlevy@gmail.com | m = t.min.to_i |
| 49 | last5m = "" |
||
| 50 | 6.times do |i| |
||
| 51 | last5m += hour |
||
| 52 | last5m += "0" if (m-i) < 10 |
||
| 53 | last5m += (m-i).to_s |
||
| 54 | last5m += "|" unless i==5 |
||
| 55 | end |
||
| 56 | hosts = Array.new |
||
| 57 | regexp = ".* for (.*) in (.*) seconds" |
||
| 58 | |||
| 59 | File.open(logfile).grep(/#{today}/).grep(/Compiled configuration|Compiled catalog/).each do |line|
|
||
| 60 | case line |
||
| 61 | when /#{last5m}/ then
|
||
| 62 | if line =~ /#{regexp}/
|
||
| 63 | avg += $2.to_f |
||
| 64 | count += 1 |
||
| 65 | unless hosts.include?($1) |
||
| 66 | hosts << $1 |
||
| 67 | end |
||
| 68 | end |
||
| 69 | when /#{regexp}/ then
|
||
| 70 | day_count += 1 |
||
| 71 | unless hosts.include?($1) |
||
| 72 | hosts << $1 |
||
| 73 | day_count_unique += 1 |
||
| 74 | end |
||
| 75 | end |
||
| 76 | end |
||
| 77 | puts "avg_compile.value #{(avg / count).to_s[0..3]}" unless count == 0
|
||
| 78 | puts "last5m_count.value #{count}"
|
||
| 79 | puts "last24h_unique_count.value #{day_count_unique}"
|
||
| 80 | end |
||
| 81 | |||
| 82 | |||
| 83 | case ARGV[0] |
||
| 84 | when 'config' |
||
| 85 | case $0 |
||
| 86 | when /puppet_mem/ |
||
| 87 | puts "graph_title puppet memory usage" |
||
| 88 | puts "graph_vlabel memory" |
||
| 89 | puts "puppetd_1.label puppetd" |
||
| 90 | # find out how many mongrel process we have - if any |
||
| 91 | File.open('/etc/sysconfig/puppetmaster') do |line|
|
||
| 92 | @pm_process = line.grep(/PUPPETMASTER_INSTANCES/).to_s.split('=')[1].to_i
|
||
| 93 | end |
||
| 94 | if @pm_process > 0 |
||
| 95 | @pm_process.times do |i| |
||
| 96 | puts "puppetmasterd_#{i+1}.label puppetmasterd #{i+1}"
|
||
| 97 | end |
||
| 98 | else |
||
| 99 | puts "puppetmaster.label puppetmasterd" |
||
| 100 | end |
||
| 101 | when /puppet_clients/ |
||
| 102 | puts "graph_title puppet clients usage" |
||
| 103 | puts "graph_vlabel clients" |
||
| 104 | puts "known_clients.label Known Clients" |
||
| 105 | e5be4561 | Antoine Beaupré | puts "avg_compile.label Average configuration compile, in seconds" |
| 106 | 573d1225 | ohadlevy@gmail.com | puts "last5m_count.label Clients in the last 5 minutes" |
| 107 | puts "last24h_unique_count.label unique clients in the last 24 hours" |
||
| 108 | end |
||
| 109 | puts "graph_category puppet" |
||
| 110 | exit 0 |
||
| 111 | when 'autoconf' |
||
| 112 | case $0 |
||
| 113 | when /puppet_mem/,/puppet_clients/ |
||
| 114 | puts "yes" |
||
| 115 | else |
||
| 116 | puts "no" |
||
| 117 | exit 0 |
||
| 118 | end |
||
| 119 | else |
||
| 120 | plist("puppetmasterd") if $0 =~ /puppet_mem$/
|
||
| 121 | plist("puppetd") if $0 =~ /puppet_mem$/
|
||
| 122 | if $0 =~ /puppet_clients$/ |
||
| 123 | puts "known_clients.value #{Dir.entries('/var/lib/puppet/yaml/facts/').size-2}"
|
||
| 124 | phaselog |
||
| 125 | end |
||
| 126 | end |
