#!/usr/bin/perl # disk-solaris.pl ################################################### # # MRTG Performance Enhancements v1.0.2 # # This script grabs Solaris Performance Monitoring (PM) data for MRTG # on the partition utilization of the system. # # Statistics args accepted: # kbytes, used, avail, capacity # # Usage: disk-solaris.pl hostname mount stat1 stat2 # Example: ./disk-solaris.pl / avail capacity # # By: # Mark Miller Crave Technology markm@cravetechnology.com # Bill Lynch Crave Technology billl@cravetechnology.com ##################################################################### ##### Subroutines ##### # Grab the PM data locally sub localh { $disk = `df -k`; $uptime = `uptime`; } # Grab the PM data remotely sub remoteh { $disk = `/usr/local/bin/ssh $host df -k`; $uptime = `/usr/local/bin/ssh $host uptime`; } sub Usage() { #display correct usage info print "Usage: disk-solaris.pl host mount stat1 stat2\n"; print " ex: ./disk-solaris.pl myhost / avail capacity\n"; } sub Validate() { #validate command line args if ((scalar(@ARGV) > 4) || ($ARGV[0] eq '')) { print "ERR: Must specify at least one stat to be monitored.\n"; Usage; exit; } } sub parseuptime() { # This sub returns only the number of days of uptime # A box with less than 1 day of uptime will show 0 days of uptime $uptime=~s/,//g; @utime = split /\s/, $uptime; for ($i = 1; $i < 8; $i++) { if ($utime[$i] eq "days" || $utime[$i] eq "day(s)" || $utime[$i] eq "day ") { $upout = $utime[$i-1]." day(s)"; } } if ($upout eq "") { $upout = "0 day(s)"; } } ##### Main Program Begins Here ###### Validate(); # Get the hostnames $localhost = `/bin/hostname`; chop($localhost); $host = $ARGV[0]; # Determine the short hostname @local = split(/\./,$localhost); $shorthost = $local[0]; # assign command line args to variables $mount = $ARGV[1]; $stat1 = $ARGV[2]; $stat2 = $ARGV[3]; # set vars ########################################################## $count = 0; $linenum = 0; # Determine if the host is local or remote if ($host eq $localhost) { localh(); } elsif ($host eq $shorthost) { localh(); } else { remoteh(); } # parse df -k data @lines=split /^/m, $disk; foreach $line (@lines) { $count++; $line =~ /^\S+\s+\d+\s+\d+\s+\d+\s+\S+\s+(\S+)/; if ($1 eq $mount) { $linenum = $count-1; } } if ($linenum < 1) { print"ERR: Unknown mount point\n"; Usage(); exit; } $line = @lines[$linenum]; $line =~ /^\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/; $kbytes = $1; $used = $2; $avail = $3; $capacity = $4; # output df -k data in MRTG format if ($stat1 eq "kbytes") { print "$kbytes\n"; } if ($stat1 eq "used") { print "$used\n"; } if ($stat1 eq "avail") { print "$avail\n"; } if ($stat1 eq "capacity") { print "$capacity\n"; } if ($stat2 eq "kbytes") { print "$kbytes\n"; } if ($stat2 eq "used") { print "$used\n"; } if ($stat2 eq "avail") { print "$avail\n"; } if ($stat2 eq "capacity") { print "$capacity\n"; } # Parse uptime data parseuptime(); # Print uptime data in MRTG format print $upout."\n";