#!/usr/bin/perl # # loadavg.pl - Very silly script to measure the size of my email # "inbox", then plot that size over time to display my "load average" # Intended to run periodically (maybe once per hour) from cron. Needs # 'date', 'grep', 'gnuplot', probably some other things. # # To do: I get a huge amount of junk (mailing lists, mail generated by # automated processes, etc.) that gets immediately deleted when I read # it. This graph would be much smoother and more meaningful if it only # plotted each day's minimum value or something like that. # # Copyright (C) 2002 Michael A. Dickerson. Copying, modification, or # redistribution are permitted under the terms of the Artistic License # as published by the Open Source Initiative. This is OSI Certified # Open Source Software; see http://www.opensource.org. # # Created 20 Aug 2002 by M. Dickerson # 3 Sep 02 MAD: changed y range from [0,100] to [0,50] use strict; my $date="/usr/bin/date"; my $grep="/usr/bin/grep"; my $home="/home/mikey"; my $inbox="$home/.mail"; my $data_file="$home/.inbox_size"; my $week_plot="$home/www/week.png"; my $month_plot="$home/www/month.png"; my @month = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; my $size=`$grep -c "^From " $inbox`; chomp $size; # some fancy date arithmetic my $now=time(); (my $sec, my $min, my $hour, my $day, my $mon, my $year) = localtime($now - (86400 * 7)); my $lastweek = sprintf("%d %s %d %d:%02d:%02d", $day, $month[$mon], $year + 1900, $hour, $min, $sec); ($sec, $min, $hour, $day, $mon, $year) = localtime($now - (86400 * 30)); my $lastmonth = sprintf("%d %s %d %d:%02d:%02d", $day, $month[$mon], $year + 1900, $hour, $min, $sec); ($sec, $min, $hour, $day, $mon, $year) = localtime($now); $now = sprintf("%d %s %d %02d:%02d:%02d", $day, $month[$mon], $year + 1900, $hour, $min, $sec); if (0) { # for if you need to debug the date arithmetic.. print "now: $now\n"; print "lastweek: $lastweek\n"; print "lastmonth: $lastmonth\n"; exit 0; } open DAT, ">>$data_file" or die("can't open $data_file: $!"); print DAT "$now $size\n"; close DAT or die("can't close $data_file: $!"); open PLOT, "|/usr/local/bin/gnuplot" or die("can't run gnuplot: $!"); print PLOT <