Pantau Temperatur Harddisk

Posted: 30 Januari 2008 in Uncategorized

Kalo abis install server kan kudu diawasi tu. bahasa kerennya tu di monitoring. nah sekarang aku pengen tulis gimana caranya mengetahui suhu harddisk secara otomatis.

jadi kita bisa siap2 kalo harddisk keliatan mau jebol gara-gara suhunya kepanasan. script ini udah dicoba dan jalan sampe sekarang di debian etch.

seharusnya sama untuk semua distro linux. untuk itu yang kudu disiapin adalah

perl(buat scriptnya), hddterm(untuk ngukur suhu harddisk), rrdtool (buat ngehasilin file gambar grafik), librrdtool-perl (biar si perl bisa pake library rrdtool)

trus apache(buat jadi webserver) dan php (buat nampilin gambarnya, sebenernya pake html biasa juga bisa sih.. yaaa perlu ga perlu lah).

then check this out!

#!/usr/bin/perl
#
# copyright Martin Pot 2003
# http://martybugs.net/linux/hddtemp.cgi
# di edit sama okho – 30 januari 2008
# rrd_hddtemp.pl

use RRDs;

# define location of rrdtool databases
my $rrd = ‘/var/lib/rrd’;
# define location of images
my $img = ‘/var/www/rrdtool’;

# process data for each specified HDD (add/delete as required)
&ProcessHDD(“sda”, “primary master”);
&ProcessHDD(“sdb”, “primary slave”);
#&ProcessHDD(“hdc”, “40GB Seagate”);
#&ProcessHDD(“hdd”, “secondary slave”);

sub ProcessHDD
{
# process HDD
# inputs: $_[0]: hdd (ie, hda, etc)
# $_[1]: hdd description

# get hdd temp for master drive on secondary IDE channel
my $temp=`/usr/sbin/hddtemp -n /dev/$_[0]`;
# remove eol chars and white space
$temp =~ s/[\n ]//g;

print “$_[1] (/dev/$_[0]) temp: $temp degrees C\n”;

# if rrdtool database doesn’t exist, create it
if (! -e “$rrd/$_[0].rrd”)
{
print “creating rrd database for /dev/$_[0]…\n”;
RRDs::create “$rrd/$_[0].rrd”,
“-s 300”,
“DS:temp:GAUGE:600:0:100”,
“RRA:AVERAGE:0.5:1:576”,
“RRA:AVERAGE:0.5:6:672”,
“RRA:AVERAGE:0.5:24:732”,
“RRA:AVERAGE:0.5:144:1460”;
}

# insert value into rrd
RRDs::update “$rrd/$_[0].rrd”,
“-t”, “temp”,
“N:$temp”;
# create graphs
&CreateGraph($_[0], “day”, $_[1]);
&CreateGraph($_[0], “week”, $_[1]);
&CreateGraph($_[0], “month”, $_[1]);
&CreateGraph($_[0], “year”, $_[1]);
}

sub CreateGraph
{
# creates graph
# inputs: $_[0]: hdd name (ie, hda, etc)
# $_[1]: interval (ie, day, week, month, year)
# $_[2]: hdd description

RRDs::graph “$img/$_[0]-$_[1].png”,
“–lazy”,
“-s -1$_[1]”,
“-t hdd temperature :: $_[2] (/dev/$_[0])”,
“-h”, “80”, “-w”, “600”,
“-a”, “PNG”,
“-v degrees C”,
“DEF:temp=$rrd/$_[0].rrd:temp:AVERAGE”,
“LINE2:temp#0000FF:$_[2] (/dev/$_[0])”,
“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”;
if ($ERROR = RRDs::error) { print “$0: unable to generate $_[0] graph: $ERROR\n”; }
}

bikin cronjob biar update otomatis

vim /etc/crontab

tambahin baris ini

# get hdd temperatures
*/5 * * * * root /root/rrd_hddtemp.pl > /dev/null

dengan asumsi file rrd_hddtemp.pl ada di /root

nah buat munculin gambarnya. kita buat index.php

<html>
<head>
<TITLE><?php echo $_SERVER[“HTTP_HOST”]?> – Temperatur Hardisk</TITLE>

<META HTTP-EQUIV=”Refresh” CONTENT=”300″>
<META HTTP-EQUIV=”Cache-Control” content=”no-cache”>
<META HTTP-EQUIV=”Pragma” CONTENT=”no-cache”>
<style>
body { font-family: Verdana,Tahoma,Arial,Helvetica; font-size:9pt}
.header { font-size: 16pt; font-weight: 900; }
</style>
<body bgcolor=”#ffffff” topMargin=’5′>

<span class=’header’><?php echo $_SERVER[“HTTP_HOST”]?> – Temperatur Hardisk</span>
<br><br>
Daily Graphs (5 minute averages)
<br>
<img src=’http://&lt;?php echo $_SERVER[“HTTP_HOST”]?>/rrdtool/sda-day.png’>
<img src=’http://&lt;?php echo $_SERVER[“HTTP_HOST”]?>/rrdtool/sdb-day.png’>

<br>
Weekly Graph (30 minute averages)
<br>
<img src=’http://&lt;?php echo $_SERVER[“HTTP_HOST”]?>/rrdtool/sda-week.png’>
<img src=’http://&lt;?php echo $_SERVER[“HTTP_HOST”]?>/rrdtool/sdb-week.png’>
<br>
Monthly Graph (2 hour averages)
<br>
<img src=’http://&lt;?php echo $_SERVER[“HTTP_HOST”]?>/rrdtool/sda-month.png’>
<img src=’http://&lt;?php echo $_SERVER[“HTTP_HOST”]?>/rrdtool/sdb-month.png’>
<br>
Yearly Graph (12 hour averages)
<br>
<img src=’http://&lt;?php echo $_SERVER[“HTTP_HOST”]?>/rrdtool/sda-year.png’>
<img src=’http://&lt;?php echo $_SERVER[“HTTP_HOST”]?>/rrdtool/sdb-year.png’>

<br><br>
</body>
</html>

nah liat deh hasilnya.. bingung ga? kalo bingung nanya dooonggg…. hehehe

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s