#!/usr/bin/env perl ############################################################## # Use my simple library for finding max & min values in arrays ############################################################## require "maxmin.lib"; ($density,$plottype,$date) = @ARGV; if ($plottype == 1) { @plottype = (lines,lines,lines,lines,lines); } elsif ($plottype == 2) { @plottype = (points,points,points,points,points); } else { print "You have specified an incorrect plot-type parameter.\n\n Valid values are 1 (line) or 2 (plot)\n"; exit;} ################################### # Use J. Cothran's graphing library ################################### require "graphMulti.lib"; ################################################################# # Open the directory, search for XXX files and # perform the following conversion routine on each matching file ################################################################# opendir(DIR, "."); #@files = grep { /stats.$date/} readdir(DIR); #@files = grep { /stats.032505/} readdir(DIR); @files = glob("*statlog.032505"); closedir(DIR); print "debug\n"; foreach $file (@files) { print $file."\n"; ################################################################### # Opens the input file for conversion, loads it into a scalar named # "lines", then closes it ################################################################### open (INFILE, "$file") or die "Can't open $file: $!"; @lines=; close INFILE; $count = 0; ######################################################################## # Iterate through the lines of the scalar until the last line is reached ######################################################################## foreach $lines (@lines) { if ($lines =~ /^procs/ || $lines =~ /\sr/) { } else { if ($count % $density == 0) { ($dummy,$procs_waiting,$procs_sleeping,$vm_swpd,$vm_free,$vm_buff,$vm_cache,$swapped_in,$swapped_out,$io_bi,$io_bo,$sys_in,$sys_cs,$cpu_usr,$cpu_sys,$cpu_idle,$cpu_wa) = split (/\s+/, $lines); push(@t_procs_waiting,$procs_waiting); push(@t_procs_sleeping,$procs_sleeping); push(@t_vm_swpd,$vm_swpd); push(@t_vm_free,$vm_free); push(@t_vm_buff,$vm_buff); push(@t_vm_cache,$vm_cache); push(@t_swapped_in,$swapped_in); push(@t_swapped_out,$swapped_out); push(@t_io_bi,$io_bi); push(@t_io_bo,$io_bo); push(@t_sys_in,$sys_in); push(@t_sys_cs,$sys_cs); push(@t_cpu_usr,$cpu_usr); push(@t_cpu_sys,$cpu_sys); push(@t_cpu_idle,$cpu_idle); push(@t_cpu_wa,$cpu_wa); $count++; } else { $count++; } } } # END foreach loop. } print "The total number of data values in your logfile is: $count\n"; print "The actual number of data values that will be plotted, based on the density you have specified is: ".$count/$density."\n"; print "These measurements will be displayed in ".5*$density." second intervals.\n"; ########################## # Graph Generation Section ########################## #@row0 = (); $time = 0; for ($j=0;$j<($count/$density)+1;$j++) { if ($j % (720/$density) == 0) { push(@row0,"$time"); $time++; } else { push(@row0,undef); } } $row[0] = 0; my @graph_data = (\@row0,\@t_procs_waiting,\@t_procs_sleeping); my @labels = ("Waiting for runtime","In uninterruptable sleep"); my_graph(\@graph_data,\@labels,\@plottype,"Process Statistics (in ".5*$density." second intervals)","Number of processes",findmin(@t_procs_waiting,@t_procs_sleeping),findmax(@t_procs_waiting,@t_procs_sleeping),"./vmstatgraphs/procs.png"); my @graph_data = (\@row0,\@t_vm_swpd,\@t_vm_free,\@t_vm_buff,\@t_vm_cache); my @labels = ("Used","Idle","Buffers","Cache"); $max = findmax(@t_vm_swpd,@t_vm_free,@t_vm_buff,@t_vm_cache); $min = findmin(@t_vm_swpd,@t_vm_free,@t_vm_buff,@t_vm_cache); print "The max value for vm is: ".$max."\n"; print "First two values are:".@t_vm_cache[0].",".@t_vm_cache[1]."\n"; #print "@t_vm_cache[0],@t_vm_cache[1]\n"; print "The min value for vm is: ".$min."\n"; my_area(\@graph_data,\@labels,\@plottype,"Virtual memory utilization (in ".5*$density." second intervals)","Kilobytes used",findmin(@t_vm_swpd,@t_vm_free,@t_vm_buff,@t_vm_cache),findmax(@t_vm_swpd,@t_vm_free,@t_vm_buff,@t_vm_cache),"./vmstatgraphs/vm.png"); my @graph_data = (\@row0,\@t_swapped_in,\@t_swapped_out); my @labels = ("From disk","To disk"); my_graph(\@graph_data,\@labels,\@plottype,"Swap Utilization","KB/Second Swapped",findmin(@t_swapped_in,@t_swapped_out),findmax(@t_swapped_in,@t_swapped_out),"./vmstatgraphs/swap.png"); my @graph_data = (\@row0,\@t_io_bi,\@t_io_bo); my @labels = ("Out","In"); my_graph(\@graph_data,\@labels,\@plottype,"I/O Statistics (in ".5*$density." second intervals)","Blocks/second",findmin(@t_io_bi,@t_io_bo),findmax(@t_io_bi,@t_io_bo),"./vmstatgraphs/io.png"); my @graph_data = (\@row0,\@t_sys_in,\@t_sys_cs); my @labels = ("Interrupts, including the clock","Context switches"); my_graph(\@graph_data,\@labels,\@plottype,"System Stats (in ".5*$density." second intervals)","Number of occurences/second",findmin(@t_sys_in,@t_sys_cs),findmax(@t_sys_in,@t_sys_cs),"./vmstatgraphs/sys.png"); my @graph_data = (\@row0,\@t_cpu_usr,\@t_cpu_sys,\@t_cpu_idle,\@t_cpu_wa); $max = findmax(@t_cpu_usr,@t_cpu_sys,@t_cpu_idle,@t_cpu_wa); $min = findmin(@t_cpu_usr,@t_cpu_sys,@t_cpu_idle,@t_cpu_wa); print "The max value for cpu is: ".$max."\n"; #print "First two values are:".@t_vm_cache[0].",".@t_vm_cache[1]."\n"; #print "@t_vm_cache[0],@t_vm_cache[1]\n"; print "The min value for vm is: ".$min."\n"; my @labels = ("User","System","Idle","CPU Waiting"); my_area(\@graph_data,\@labels,\@plottype,"Total CPU time (in ".5*$density." second intervals)","Percent of utilization",findmin(@t_cpu_usr,@t_cpu_sys,@t_cpu_idle,@t_cpu_wa),findmax(@t_cpu_usr,@t_cpu_sys,@t_cpu_idle,@t_cpu_wa),"./vmstatgraphs/cpu.png"); exit;