I writing new version of nginx_webmin plugin and want to add bandwidth counting feature.
In API I find function feature_bandwidth, but can't find the working example how it must works.
Can you give me working example?
At now I write:
sub feature_bandwidth
{
my ($d, $start, %bwhash) = @_;
$file=$d->{'home'}.'logs/nginx_access.log';
open(LOG,$file);
$i2=0;
while($line=) {
@line_spl = split(/ /,$line);
$line =~ m/\[([^\]]+)\]/;
$date = $1;
$time=str2time($date);
$bwtime = int($time/86400);
$line =~ m/(\d+) "[\d\.\-]+"/;
$in = $1;
$out = $line_spl[10];
$bwhash{$bwtime} += ($in+$out);
return $bwhash;
}
Is it correct? How I can debug this function?
Will be good to create dummy example module, that have all api functions with comments and examples.
The way the function is supposed to work is like this - it takes in three parameters :
The return value must be the unix time of the last log entry that was scanned.
Actual accounting is done by updating the hash in the 3rd parameter. It is a map from keys like
web_15085
to a number of bytes used. The part of the key afterweb_
is a day number, which is the number of days since 1st Jan 1970.You function should get called from the
/etc/webmin/virtual-server/bw.pl
cron job. One way to debug it is to put someprint STDERR ...
statements in your function, then SSH into the system and runbw.pl
as root manually from the shell.''
Thank's for info, I try debug via STDERR. I need name keys like web_9999 or other name, nginx_9999? Value of the key must be integer with total traffic in bytes?
I can't find the feature_bandwidth function that parse proftpd or apache logs, where it is located? Or maybe you can post perl source of some working function or write a simple example?
You need to use keys starting with
web_
.For an example of the version of this function for Apache logs, see
virtual-server/feature-web.pl
under the Webmin root, in thebandwidth_web
function.''
Thank's, with
web_
all works, but I see my traffic in "Website traffic" section. Can I separate my nginx traffic from apache and show it with different color and column? Because nginx working as proxy for dynamic files, and now traffic for php scripts counts double time.You can't define custom bandwidth types unfortunately - all you can do is use one of the built-in types, which are
web
,mail
,ftp
,unix
,backup
andrestore
.''
I update my function, now it saves bandwidth normally to file:
root@rise:/etc/webmin/virtual-server/bandwidth# cat ./13028756286394
last_nginx-webmin=1303385042
last_web=1303385042
last_mail=1303413843
last_ftp=
web_15079=417724
last_unix=1302877657
ftp_15079=37333063
web_15082=501093
web_15085=47925
nginx_15083=1493123
nginx_15084=1495121
nginx_15085=1493271
But i didn't see my part of bandwidth in graphs: http://img849.imageshack.us/img849/9523/snapshot4.png
Maybe I must additionally describe my bandwidth type in any function?
JamieCameron, thank's for the help! I do the new working release of nginx module for virtualmin and webmin, you can look on it here: https://github.com/MurzNN/virtualmin-nginx
Cool, looks good ... are you supporting serving content using nginx, or just proxying?
''
By default nginx serve static content by youself, dynamic and 404 errors proxies to apache. But you can set custom config in settings.