summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmunin/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