#!/usr/bin/env ruby @dummyvar = <<-'=cut' =head2 Description puppet_runtime - Munin plugin that reports the duration of puppet runs. =head2 Compatibility This Plugin is tested with the following configurations: Debian: { version => 11 { Puppet: { version => 5.5.22, version => 7.14.0, } } } Redhat: { version => 8 { Puppet: { version => 6.4.0, version => 6.19.1, version => 7.9.2, } } } Fedora: { version => 35 { Puppet: { version => 7.12.1, version => 7.14.0, } } } =head2 Configuration The following configuration is mandatory. It must be ensured that the plugin is executed by the root user. $ cat /etc/munin/plugin-conf.d/puppet.conf [puppet_runtime] user root Further configurations are not necessary. If it does not work, then run "puppet config print lastrunreport" and make sure that the specified file is readable. $ puppet config print lastrunreport /opt/puppetlabs/puppet/cache/state/last_run_report.yaml To check the function, perform the following: $ munin-run puppet_runtime An example Output: $ munin-run puppet_runtime total.value 6.952583373 fact_generation.value 4.8415459030075 catalog_application.value 1.060418801032938 plugin_sync.value 0.6275155210169032 The duration of the Puppet run is determined from the Puppet report. This information can be found in the file last_run_report.yaml. The location of the file is determined via the Puppet client, for example: $ puppet config print lastrunreport /opt/puppetlabs/puppet/cache/state/last_run_report.yaml =head2 Tips & Tricks Since you want to integrate the runtime of a puppet run into Munin, you will most likely use puppet as well. Here you can find an example for your puppet configuration: file {'/etc/munin/plugin-conf.d/puppet.conf': source => 'puppet:///modules/munin/puppet.conf', notify => Service['munin-node'], } file {'/etc/munin/plugins/puppet_runtime': ensure => 'link', target => '/usr/share/munin/plugins/puppet_runtime', } =head3 Known issues The only known issue that can occur is that puppet cannot be found. This is because it is not known to the environment used. This issue can occur when using the packages from the puppetlabs repo. In this case, a simple link is enough to fix this issue: file {'/usr/bin/puppet': ensure => 'link', target => '/opt/puppetlabs/bin/puppet', } =cut require 'yaml' report = YAML.load(File.read(`puppet config print lastrunfile`.strip)) time_report = report["time"] if time_report.is_a?(Hash) total, fact_generation, catalog_application, plugin_sync = time_report.values_at( "total", "fact_generation", "catalog_application", "plugin_sync" ) puts "total.value #{total}" if total puts "fact_generation.value #{fact_generation}" if fact_generation puts "catalog_application.value #{catalog_application}" if catalog_application puts "plugin_sync.value #{plugin_sync}" if plugin_sync end case ARGV[0] when 'config' puts 'graph_category system' puts 'graph_args --base 1000 -l 0' puts 'graph_scale no' puts 'graph_title Puppet agent run time' puts 'graph_vlabel Seconds' puts 'total.label Puppet agent runtime' puts 'fact_generation.label Fact generation runtime' puts 'catalog_application.label Catalog application runtime' puts 'plugin_sync.label Plugin sync runtime' exit 0 when 'autoconf' puts 'yes' exit 0 else total fact_generation catalog_application plugin_sync end