Created
April 24, 2014 03:09
-
-
Save yaasita/11240158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use File::Temp; | |
use strict; | |
use warnings; | |
# grep | |
my $temp_grep_log=File::Temp->new(DIR=>"/tmp",SUFFIX=>".tmp"); | |
my $temp_grep_log_name=$temp_grep_log->filename; | |
system "cat /var/log/syslog | grep '°' > $temp_grep_log_name "; | |
# make gnuplot data | |
chdir "/tmp" or die $!; | |
my $temp_gnuplot_data=File::Temp->new(DIR=>"/tmp",SUFFIX=>".tmp"); | |
my $temp_gnuplot_data_name=$temp_gnuplot_data->filename; | |
while (<$temp_grep_log>){ | |
# ex) May 15 01:19:02 | |
if (/^(...\s+\d{1,2}\s\d\d:\d\d:\d\d).*\s(\d+)°/){) | |
print $temp_gnuplot_data "$1,$2\n"; | |
} | |
else { | |
die "format error!"; | |
} | |
} | |
# make gnuplot config | |
my $temp_gnuplot_conf=File::Temp->new(DIR=>"/tmp",SUFFIX=>".tmp"); | |
my $temp_gnuplot_conf_name=$temp_gnuplot_conf->filename; | |
while (<DATA>){ | |
s/DATAFILE/$temp_gnuplot_data_name/; | |
print $temp_gnuplot_conf $_; | |
} | |
# run gnuplot | |
system "gnuplot $temp_gnuplot_conf_name" and die $!; | |
__DATA__ | |
set terminal png size 3000,1000 | |
set output "hddtemp.png" | |
set datafile separator "," | |
set grid xtics ytics mxtics | |
set xdata time | |
set timefmt "%b %d %H:%M:%S" | |
set format x "%m/%d\n%H:%m" | |
set xlabel "Day" | |
set xtics 28800 | |
set ylabel "C" | |
set ytics 1 | |
plot 'DATAFILE' using 1:2 w lp lt 2 lw 3 pt 7 title 'HDD Temperature' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment