root / plugins / puppet / puppet_runtime @ c6f88968
Historique | Voir | Annoter | Télécharger (1,21 ko)
| 1 | 7a37bfb1 | Lars Kruse | #!/usr/bin/env ruby |
|---|---|---|---|
| 2 | f6d7cf59 | Jasper Lievisse Adriaanse | |
| 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 | 809639ab | Lars Kruse | logfile = ENV['puppet_logfile'] || '/var/log/messages' |
| 19 | f6d7cf59 | Jasper Lievisse Adriaanse | t = Time.now |
| 20 | 809639ab | Lars Kruse | dateformat = ENV['puppet_logformat'] || '^%b %d' |
| 21 | f6d7cf59 | Jasper Lievisse Adriaanse | 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 | 809639ab | Lars Kruse | puts "runtime.value #{Regexp.last_match(1)}"
|
| 25 | f6d7cf59 | Jasper Lievisse Adriaanse | exit 0 |
| 26 | end |
||
| 27 | end |
||
| 28 | end |
||
| 29 | |||
| 30 | case ARGV[0] |
||
| 31 | 809639ab | Lars Kruse | 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 | 6052c56d | Kenyon Ralph | exit 0 |
| 39 | 809639ab | Lars Kruse | when 'autoconf' |
| 40 | puts 'yes' |
||
| 41 | 6052c56d | Kenyon Ralph | exit 0 |
| 42 | else |
||
| 43 | get_runtime |
||
| 44 | f6d7cf59 | Jasper Lievisse Adriaanse | end |
