Hozzászólások
[quote:0fb9930ea0="macskas"]hello
ezt az elejere tedd be (my nelkul):
[code:1:0fb9930ea0]
$P_ifconfig = "/sbin/ifconfig";
$P_grep = "/bin/grep";
$P_cut = "/usr/bin/cut";
[/code:1:0fb9930ea0]
ezt a 2 sort:
my $in = `ifconfig $_[0] |grep bytes|cut -d":" -f2|cut -d" " -f1`;
my $out = `ifconfig $_[0] |grep bytes|cut -d":" -f3|cut -d" " -f1`;
meg csereld erre(ezis my nelkul):
[code:1:0fb9930ea0]
$in = `$P_ifconfig $_[0] |$P_grep bytes|$P_cut -d":" -f2|$P_cut -d" " -f1`;
$out = `$P_ifconfig $_[0] |$P_grep bytes|$P_cut -d":" -f3|$P_cut -d" " -f1`;
[/code:1:0fb9930ea0]
macskas
Köszi! Működik!
- A hozzászóláshoz be kell jelentkezni
A címben említett programot használnám a hálózati forgalmam monitorozására (is). A http://martybugs.net/linux/rrdtool/traffic.cgi oldalról leszedett rrd_traffic.pl script-tel nem boldogulok. Az eth0 eszközt akarom monitorozni. Az adatbázist megcsinálja a program, de nem olvassa be az adatokat. Vagyis egy üres táblázat a végeredmény. A http://martybugs.net/linux/hddtemp.cgi oldalon található script viszont működik, ezért úgy tippelem, hogy a rrd_traffic.pl-ben van valami elírva. Mivel a perlhez nem értek, bemásolom ide, hátha valaki meg tudja mondani mi a gond vele.
#!/usr/bin/perl
#
# copyright Martin Pot 2003
# http://martybugs.net/linux/rrdtool/traffic.cgi
#
# rrd_traffic.pl
use RRDs;
# define location of rrdtool databases
my $rrd = '/var/lib/rrd';
# define location of images
my $img = '/var/www/html/rrdtool';
# process data for each interface (add/delete as required)
&ProcessInterface("eth0", "local network");
#&ProcessInterface("eth1", "internet gateway");
#&ProcessInterface("eth2", "MartinMast wireless link");
#&ProcessInterface("eth3", "home wireless");
sub ProcessInterface
{
# process interface
# inputs: $_[0]: interface name (ie, eth0/eth1/eth2/ppp0)
# $_[1]: interface description
# get network interface info
my $in = `ifconfig $_[0] |grep bytes|cut -d":" -f2|cut -d" " -f1`;
my $out = `ifconfig $_[0] |grep bytes|cut -d":" -f3|cut -d" " -f1`;
# remove eol chars
chomp($in);
chomp($out);
print "$_[0] traffic in, out: $in, $out\n";
# if rrdtool database doesn't exist, create it
if (! -e "$rrd/$_[0].rrd")
{
print "creating rrd database for $_[0] interface...\n";
RRDs::create "$rrd/$_[0].rrd",
"-s 300",
"DS:in:DERIVE:600:0:12500000",
"DS:out:DERIVE:600:0:12500000",
"RRA:AVERAGE:0.5:1:576",
"RRA:AVERAGE:0.5:6:672",
"RRA:AVERAGE:0.5:24:732",
"RRA:AVERAGE:0.5:144:1460";
}
# insert values into rrd
RRDs::update "$rrd/$_[0].rrd",
"-t", "in:out",
"N:$in:$out";
# create traffic graphs
&CreateGraph($_[0], "day", $_[1]);
&CreateGraph($_[0], "week", $_[1]);
&CreateGraph($_[0], "month", $_[1]);
&CreateGraph($_[0], "year", $_[1]);
}
sub CreateGraph
{
# creates graph
# inputs: $_[0]: interface name (ie, eth0/eth1/eth2/ppp0)
# $_[1]: interval (ie, day, week, month, year)
# $_[2]: interface description
RRDs::graph "$img/$_[0]-$_[1].png",
"-s -1$_[1]",
"-t traffic on $_[0] :: $_[2]",
"--lazy",
"-h", "80", "-w", "600",
"-l 0",
"-a", "PNG",
"-v bytes/sec",
"DEF:in=$rrd/$_[0].rrd:in:AVERAGE",
"DEF:out=$rrd/$_[0].rrd:out:AVERAGE",
"CDEF:out_neg=out,-1,*",
"AREA:in#32CD32:Incoming",
"LINE1:in#336600",
"GPRINT:in:MAX: Max\\: %5.1lf %s",
"GPRINT:in:AVERAGE: Avg\\: %5.1lf %S",
"GPRINT:in:LAST: Current\\: %5.1lf %Sbytes/sec\\n",
"AREA:out_neg#4169E1:Outgoing",
"LINE1:out_neg#0033CC",
"GPRINT:out:MAX: Max\\: %5.1lf %S",
"GPRINT:out:AVERAGE: Avg\\: %5.1lf %S",
"GPRINT:out:LAST: Current\\: %5.1lf %Sbytes/sec",
"HRULE:0#000000";
if ($ERROR = RRDs::error) { print "$0: unable to generate $_[0] $_[1] traffic graph: $ERROR\n"; }
}
- A hozzászóláshoz be kell jelentkezni
Hali!
Kipróbáltam, működik szépen. A perl script vége fele a "--lazy" opció miatt a nem updateli állandóan a .png fileokat. Próbaképp töröld ki ezt a sort.
Amúgy egyszerűen ellenőrizheted, hogy tölti-e az rrd adatbázist, dumpold ki: rrdtool dump eth0.rrd
BYe
Roland
- A hozzászóláshoz be kell jelentkezni
hello
ezt az elejere tedd be (my nelkul):
[code:1:fbad290adb]
$P_ifconfig = "/sbin/ifconfig";
$P_grep = "/bin/grep";
$P_cut = "/usr/bin/cut";
[/code:1:fbad290adb]
ezt a 2 sort:
my $in = `ifconfig $_[0] |grep bytes|cut -d":" -f2|cut -d" " -f1`;
my $out = `ifconfig $_[0] |grep bytes|cut -d":" -f3|cut -d" " -f1`;
meg csereld erre(ezis my nelkul):
[code:1:fbad290adb]
$in = `$P_ifconfig $_[0] |$P_grep bytes|$P_cut -d":" -f2|$P_cut -d" " -f1`;
$out = `$P_ifconfig $_[0] |$P_grep bytes|$P_cut -d":" -f3|$P_cut -d" " -f1`;
[/code:1:fbad290adb]
macskas
- A hozzászóláshoz be kell jelentkezni