#!/usr/bin/perl -w # Hugh Brown # Aug 15, 2006 # Version 1.0 # # graphit: A Small but Useful(tm) utility to write histograms from the command line. # Meant mainly for visualizing activity from logfiles. # Copyright (C) 1970 Hugh Brown # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # # $Id: graphit 278 2006-08-16 20:07:23Z aardvark $ use strict; use Getopt::Std; sub usage { print < 0) { #print "FIXME: \$minute == $minute\t\$modulo == $modulo\t$zoom == $zoom\n"; $minute -= $modulo; } $minute = sprintf ("%02d", $minute); $datestamp =~ s/:\d{2}$/:$minute/; return $datestamp; } my ($datestamp, $last); my $count = 0; my $scaling = 10; my $zoom = 1; my %option; getopts('hs:z:', \%option); if ($option{h}) { &usage; } if (defined $option{s}) { ($option{s} =~ /\d+$/) or &usage; $scaling = $option{s}; } if (defined $option{z}) { ($option{z} =~ /\d+$/) or &usage; $zoom = $option{z}; } format STDOUT = @<<<<<<<<<<< @>>>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@| $last, $count, "*" x ($count/$scaling), "+" . while () { # Month day hh:mm:ss $datestamp = join " ", (split " ", $_)[0,1,2]; # Take off the seconds $datestamp =~ s/:\d{2}$//; $datestamp = &zoom($datestamp, $zoom) if ($zoom > 1); if (! defined $last) { $last = $datestamp; } if ($datestamp eq $last) { $count++; next; } else { write; $last = $datestamp; $count = 1; } } #print "$datestamp $count " . "*" x ($count/$scaling) . "\n" unless ($last eq ""); write unless ($last eq "");