#! /usr/local/bin/perl # cisstat for cisco statistics # Scott Presnell, srp@zgi.com, Wed Feb 7 07:51:00 PST 2001 $cisco = "/usr/local/etc/cisco"; open(QP, "$cisco |") || die "cannot open pipe to DSL router ($!)\n"; while () { if (/uptime\s+is\s+((\d+)\s+days,\s+(\d+)\s+hours\s+and\s+(\d+)\s+minutes)/i) { $uptime = $1; $updays = $2; $found += 1; } if (/(\d+)\s+Kbps\s+down;\s+(\d+)\s+Kbps\s+up;/) { $speed[0] = $1; $speed[1] = $2; } elsif (/Line\s+Quality\s+(\d+)\s+dB/) { $signal = $1; } elsif (/TX\sPower\s+\+([\d\.]+)\s+dB\s+Remote\s+TX\s+Power\s+\+([\d\.]+)\s+dB/) { $power[0] = $2; $power[1] = $1; } if (/Good\s+Tx:\s+(\d+)\s+\#\s+of\s+Good\s+Rcv\'d:\s+(\d+)/) { print "eth0 packets in: $2\n" if ($opt_d); print "eth0 packets out: $1\n" if ($opt_d); $eth[0] = $2; $eth[1] = $1; } elsif (/uncorrected\s+RS\s+errors:\s+(\d+)\s+\#\s+of\s+corrected\s+RS\s+errors:\s+(\d+)/) { print "uncorrected RS errors: $1\n" if ($opt_d); print " corrected RS errors: $2\n" if ($opt_d); $werrs[0] = $1; $werrs[1] = $2; } elsif (/CRC\s+errors:\s+(\d+)/) { print "crc errors: $1\n" if ($opt_d); $werrs[2] = $1; } elsif (/rejected\s+Tx\s+packets:\s+(\d+)/) { print "Tx errors: $1\n" if ($opt_d); $werrs[3] = $1; } elsif (/packets\s+Rx:\s+(\d+)\s+Tx:\s+(\d+)/) { print "wan0-0 packets in: $1\n" if ($opt_d); print "wan0-0 packets out: $2\n" if ($opt_d); $wan[0] = $1; $wan[1] = $2; } elsif (/bytes\s+Rx:\s+(\d+)\s+Tx:\s+(\d+)/) { print "wan0-0 bytes in: $1\n" if ($opt_d); print "wan0-0 bytes out: $2\n" if ($opt_d); $wan[2] = $1; $wan[3] = $2; } } close(QP); print "Name Rate U/D Power U/D S/N (db)\n"; printf "%-6.6s %10s %9s %2d\n", "wan0", join("/", $speed[1], $speed[0]), join("/", $power[1], $power[0]), $signal; print "\n"; print "Name Ipkts CRCerrs RSerrs Opkts Oerrs\n"; printf "%-6.6s %7d %7d %15.15s %7d %5d\n", "eth0", $eth[0], 0, 0, $eth[1], 0; printf "%-6.6s %7d %7d %2d%% %15.15s %7d %5d %2d%%\n", "wan0-0", $wan[0], $werrs[2], int((100 * $werrs[2]/$wan[0]) + 0.5), join("/", $werrs[0], $werrs[1]), $wan[1], $werrs[3], int((100 * $werrs[3]/$wan[1]) + 0.5);
Scott Presnell
Last modified: Wednesday, February 7, 2001 07:51 PST