#!/usr/bin/perl use FileHandle; use strict; use RRDs; my $rrddir = '/var/www/apps/diskstats/loke/'; my $fh = FileHandle -> new; open($fh, "LANG=C iostat -k -d 10 dm-0 dm-1 hda|"); unless(eof($fh)) { my $line; my $linenr = 0; while($line = <$fh>) { if($linenr > 6) { unless($line =~ "^\n") { unless($line =~ "Device") { my $device = (split /\ +/,$line)[0]; my $kbps_read = (split /\ +/,$line)[2]; my $kbps_write = (split /\ +/,$line)[3]; my $now = time; unless( -e "$rrddir/$device.rrd" ) { &create("$rrddir/$device.rrd"); } RRDs::update( "$rrddir/$device.rrd", "$now:$kbps_read:$kbps_write", ); } } } unless($linenr == 10) { $linenr++; } } } else { close($fh); } sub create { my $outfile = $_[0]; RRDs::create ( "$outfile", "-s 10", 'DS:read:GAUGE:20:U:U', 'DS:write:GAUGE:20:U:U', 'RRA:AVERAGE:0.5:1:360', 'RRA:AVERAGE:0.5:6:1440', 'RRA:AVERAGE:0.5:30:2014', 'RRA:AVERAGE:0.5:360:672', 'RRA:AVERAGE:0.5:8640:365', ); `chmod 640 "$outfile"`; `chown admin:www-data "$outfile"`; }