Linuxtrent: MRTG

  • From: "Gelpi Andrea - Liste" <liste@xxxxxxxx>
  • To: "Linuxtrent" <linuxtrent@xxxxxxxxxxxxxxxxx>
  • Date: Tue, 5 Mar 2002 23:25:25 +0100

Salve,
        qualche tempo fa Guido mi aveva passato uno script per catturare i byte
dalle interfacce del PC.

Copiando da un'altro script l'ho sistemato ed ora funziona come sorgente di
dati x mrtg.

Lo allego qui sotto, grazie a tutti.

-----------------------------------------------------------------------
#!/usr/bin/perl
use strict;
  my (%interface_acc, $interface, $upTime, $host);
  $host=`/bin/hostname --fqdn`;  # local hostname (for information only)
  ($interface) = @ARGV;
  $interface = "eth0" if !defined $interface;

  open DEV, "</proc/net/dev";
  <DEV>;<DEV>;  #skip header
  while(<DEV>){
    chop;
    my($name, $str_bytes) = split /:/, $_, 2;
    $name =~ s/\s+//;
    $str_bytes =~ s/\s+//;
    my @bytes = split /\s+/, $str_bytes, 16;
    $interface_acc{$name} = \@bytes;
  }
  close DEV;

# uptime of the machine
open(UPTIME, "uptime |cut -b 14-27|");
$upTime=<UPTIME>;
close(UPTIME);
chop $upTime;

# 4 lines of output only.

print "$interface_acc{$interface}->[0]\n",
      "$interface_acc{$interface}->[8]\n",
      "$upTime\n",
      "$host";
-----------------------------------------------------------------------

--
Gelpi ing. Andrea
--------------------------------------------------------------
It took the computing power of three C-64s to fly to the Moon.
It takes a 486 to run Windows 95. Something is wrong here.
--------------------------------------------------------------

-- 
Per iscriversi  (o disiscriversi), basta spedire un  messaggio con SOGGETTO
"subscribe" (o "unsubscribe") a mailto:linuxtrent-request@xxxxxxxxxxxxxxxxx


Other related posts:

  • » Linuxtrent: MRTG