Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
linux_stats.pl
Package: mrtg-2.13.2.zip [view]
Upload User: shbosideng
Upload Date: 2013-05-04
Package Size: 1555k
Code Size: 2k
Category:
SNMP
Development Platform:
C/C++
- #!/usr/bin/perl -Tw
- ####################################################################
- # linux_stats.pl 1.0 Mike Machado #
- # mike@innercite.com #
- # 2000-07-19 #
- # #
- # Script to read traffic stats off linux 2.2 and greater systems #
- # #
- ####################################################################
- use strict;
- #### Options ####
- my $uptimeprog = '/usr/bin/uptime'; # Set to program to give system uptime
- my $hostnameprog = '/bin/hostname'; # Set to program to give system hostname
- my $defaultinterface = 'eth0'; # Set to default interface
- my $defaultstatfile = '/proc/net/dev'; # Set to traffic stats file location
- ##### Nothing below here should have to be changed #####
- if (@ARGV && $ARGV[0] eq '-h') {
- print "Usage: linux_stats.pl [interface] [stats file]n";
- print "tIf left blank 'eth0' and '/proc/net/dev' are usedn";
- print "tInterface of 'ALL' will total all interface traffic, excluding lon";
- exit;
- }
- my $interface = shift || $defaultinterface;
- my $statfile = shift || $defaultstatfile;
- # Clear path and get uptime
- delete $ENV{PATH};
- delete $ENV{BASH_ENV};
- my $uptime = `$uptimeprog`;
- chomp($uptime);
- my $hostname = `$hostnameprog`;
- chomp($hostname);
- my ($in, $out, $found);
- open(STATS, $statfile) || die "Cannot open $statfile: $!n";
- while (<STATS>) {
- my $line = $_;
- chomp($line);
- if (uc($interface) eq 'ALL') {
- if ($line =~ /^s+(.*):s*(d+)s+d+s+d+s+d+s+d+s+d+s+d+s+d+s+(d+)s+d+s+d+s+d+s+d+s+d+s+d+s+d+$/) {
- next if $1 eq 'lo';
- $in += $2;
- $out += $3;
- $found++;
- }
- } else {
- if ($line =~ /^s+$interface:s*(d+)s+d+s+d+s+d+s+d+s+d+s+d+s+d+s+(d+)s+d+s+d+s+d+s+d+s+d+s+d+s+d+$/) {
- $in = $1;
- $out = $2;
- $found = 1;
- last;
- }
- }
- }
- close(STATS);
- if (!$found) {
- print "0n0n$uptimen$hostname: Unknown Interface: $interfacen";
- } else {
- print "$inn$outn$uptimen$hostname: Interface: $interface";
- if (uc($interface) eq 'ALL') {
- print " (counted $found interface";
- if ($found > 1) {
- print "s";
- }
- print ")";
- }
- print "n";
- }