lisa (owner)

Revisions

gist: 34817 Download_button fork
public
Public Clone URL: git://gist.github.com/34817.git
hddtemps-Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
## The Rakefile
require 'RRDtool'
require 'daemon_temperature'
task :default => :test_update_temps
desc "Test Update All Disk Temperatures"
task(:test_update_temps) do
  now = Time.now
  rrds = Hash.new(nil)
  terms = [ 'hour', 'day', 'week', 'month', 'year' ]
  RRD_ROOT = File.join(File.dirname(__FILE__),'rrds')
  IMAGE_OUTPUT_ROOT = File.join(File.dirname(__FILE__),'images','{disk}-{period}')
  temps = DaemonTemperature.new("localhost",7634)
  disks = temps.disks
  disks.each do |d|
    rrds[d] = RRDtool.new File.join(RRD_ROOT,d+'.rrd')
  end
 
  rrds.each do |name,rrd|
    next unless File.exists?("/dev/#{name}")
    unless File.exists?(rrd.rrdname)
      rrd.create(300, now.to_i - 1,[
          "DS:temp:GAUGE:600:0:100",
          "RRA:AVERAGE:0.5:1:24",
          "RRA:AVERAGE:0.5:1:576",
          "RRA:AVERAGE:0.5:6:672",
          "RRA:AVERAGE:0.5:24:732",
          "RRA:AVERAGE:0.5:144:1460"])
    end
    temperature = temps.temp(name)
    rrd.update("temp",[ "N:#{temperature}"])
    terms.each do |term|
      image = IMAGE_OUTPUT_ROOT.gsub('{disk}',name).gsub('{period}',term) + ".png"
      RRDtool.graph([image,
                "--lazy",
                "-A",
       "-s -1#{term}",
       "-t hdd temperature :: #{name} (/dev/#{name}; over 1 #{term})",
       "-h", "80", "-w", "600",
       "-a", "PNG",
       "-v degrees C",
       "DEF:temp=#{rrd.rrdname}:temp:AVERAGE",
       "LINE2:temp#0000FF:#{name} (/dev/#{name})",
       "GPRINT:temp:MIN: Min\\: %2.lf",
       "GPRINT:temp:MAX: Max\\: %2.lf",
       "GPRINT:temp:AVERAGE: Avg\\: %4.1lf",
       "GPRINT:temp:LAST: Current\\: %2.lf degrees C\\n"
      ])
    end
  end
  terms.each do |term|
    image = IMAGE_OUTPUT_ROOT.gsub('{disk}','all').gsub('{period}',term) + ".png"
    opts = [image,
            "--lazy",
            "-A",
            "-s -1#{term}",
            "-t hdd temperature :: all",
            "-h", "80", "-w", "600",
            "-a", "PNG",
            "-v degrees C"]
    rrds.each do |disk,rrd|
      opts << "DEF:#{disk}=#{rrd.rrdname}:temp:AVERAGE"
    end
    opts << [ "LINE2:hde#0000FF:hde (/dev/hde)",
              "LINE2:hdg#FF0000:hdg (/dev/hdg)",
              "LINE2:hdi#00FF00:hdi (/dev/hdi)",
              "LINE2:hdk#000000:hdk (/dev/hdk)",
              "LINE2:hdm#FF00FF:hdm (/dev/hdm)",
              "LINE2:hdo#00FFFF:hdo (/dev/hdo)",
              "LINE2:hdq#0FF00F:hdq (/dev/hdq)",
              "LINE2:hds#F0F0F0:hds (/dev/hds)"
    ]
    opts -= [ "LINE2:hdi#00FF00:hdi (/dev/hdi)" ]
    opts.flatten!
    RRDtool.graph(opts)
  end
end