diff options
author | Peter Palfrader <peter@palfrader.org> | 2006-05-15 14:09:40 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2006-05-15 14:09:40 +0000 |
commit | ba00cb980bc5ab3e95f270ec830a96587c5ca0cb (patch) | |
tree | 48717264a72d9aebc40b495560ff8ba753bae84f /munin/ipmi_sensor_ | |
parent | 33f4d7374803578371bbfcd6e8ab554e98e7161f (diff) |
Cache ipmitool output
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@86 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'munin/ipmi_sensor_')
-rwxr-xr-x | munin/ipmi_sensor_ | 30 |
1 files changed, 30 insertions, 0 deletions
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 |