From ba00cb980bc5ab3e95f270ec830a96587c5ca0cb Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 15 May 2006 14:09:40 +0000 Subject: Cache ipmitool output git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@86 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- munin/ipmi_sensor_ | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'munin') diff --git a/munin/ipmi_sensor_ b/munin/ipmi_sensor_ index 11a66fd..148f1d3 100755 --- a/munin/ipmi_sensor_ +++ b/munin/ipmi_sensor_ @@ -19,6 +19,10 @@ require 'yaml'; VALID_UNITS = %w{volts degrees_c rpm} +CACHEDIR = "/var/lib/munin/plugin-state" +CACHEFILE = "plugin-ipmi_sensor.cache" +CACHE_AGE = 290 + def bail_out(m) STDERR.puts "#{$0}: #{m}" exit 1 @@ -32,7 +36,32 @@ end def normalize_unit(s) s.downcase.tr('^a-z0-9', '_') end +def fetch_cache + fn = CACHEDIR+"/"+CACHEFILE + return nil unless FileTest.exists? fn + cache = YAML::load( File.open(fn) ) + return nil unless cache + return nil unless cache[:version] == 1 + return nil if Time.now - cache[:timestamp] > CACHE_AGE + return cache[:data] +end +def write_cache(data) + fn = CACHEDIR+"/"+CACHEFILE + return unless FileTest.directory? CACHEDIR + return unless FileTest.writable? CACHEDIR or FileTest.writable? fn + File.open(fn, "w", 0600) { |f| + cache = { + :version => 1, + :timestamp => Time.now, + :data => data + } + f.puts cache.to_yaml + } +end def get_sensor_data + data = fetch_cache + return data if data + data = [] names = {} IO.popen("ipmitool -I open sensor") do |f| @@ -65,6 +94,7 @@ def get_sensor_data } end end + write_cache data data end -- cgit v1.2.3