root / plugins / puppet / puppet_runtime @ a7139bca
Historique | Voir | Annoter | Télécharger (1,21 ko)
| 1 |
#!/usr/bin/env ruby |
|---|---|
| 2 |
|
| 3 |
# This plugin reports the duration of the most recent puppet agent run. |
| 4 |
# It requires read access to the puppet logfile (defaults to /var/log/messages). |
| 5 |
# |
| 6 |
# CONFIGURATION |
| 7 |
# |
| 8 |
# [puppet*] |
| 9 |
# env.puppet_logfile /var/log/message |
| 10 |
# env.puppet_logformat "^%b %d" |
| 11 |
# |
| 12 |
# The logfile is where the puppet agent is expected to log its run time statistics. |
| 13 |
# The format is the format of the date syslog writes to the file, which may vary |
| 14 |
# according to locale and configuration. |
| 15 |
|
| 16 |
# reports how long the puppet agent took to apply the catalog |
| 17 |
def get_runtime |
| 18 |
logfile = ENV['puppet_logfile'] || '/var/log/messages' |
| 19 |
t = Time.now |
| 20 |
dateformat = ENV['puppet_logformat'] || '^%b %d' |
| 21 |
today = t.strftime(dateformat) |
| 22 |
File.open(logfile).grep(/#{today}/).grep(/Finished catalog run in/).reverse_each do |line|
|
| 23 |
if line =~ /in (.*) seconds/ |
| 24 |
puts "runtime.value #{Regexp.last_match(1)}"
|
| 25 |
exit 0 |
| 26 |
end |
| 27 |
end |
| 28 |
end |
| 29 |
|
| 30 |
case ARGV[0] |
| 31 |
when 'config' |
| 32 |
puts 'graph_category other' |
| 33 |
puts 'graph_args --base 1000 -l 0' |
| 34 |
puts 'graph_scale no' |
| 35 |
puts 'graph_title puppet catalog run time' |
| 36 |
puts 'graph_vlabel Seconds' |
| 37 |
puts 'runtime.label Catalog application time' |
| 38 |
exit 0 |
| 39 |
when 'autoconf' |
| 40 |
puts 'yes' |
| 41 |
exit 0 |
| 42 |
else |
| 43 |
get_runtime |
| 44 |
end |
