From: xchaos Date: Thu, 24 Jan 2013 15:19:47 +0000 (+0000) Subject: improved logging X-Git-Url: https://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=commitdiff_plain;h=b1a5c8838af8aab2c376bec78cc8a736a9f9c101 improved logging git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@218 251d49ef-1d17-4917-a970-b30cf55b089b --- diff --git a/htmlandlogs.c b/htmlandlogs.c index f16580a..0443c7b 100644 --- a/htmlandlogs.c +++ b/htmlandlogs.c @@ -123,12 +123,16 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) i=0; if(f > 0) { - unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum=0; - int active_classes=0; - int colspan=12; - struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums=NULL; - int limit_count=0, prio_count=0; - int popup_button=0; + unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum = 0; + int active_classes = 0; + int colspan = 12; + struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums = NULL; + int limit_count = 0, prio_count = 0; + int popup_button = 0; + /* IPv6 vs. IPv4 stats */ + unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0; + int count4 = 0, count6 = 0; + double perc6; if(qos_proxy) { @@ -279,13 +283,13 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) fputs("\n",f); /* ----------------------------------------------- */ - fprintf(f,"%d\n\ + fprintf(f, "%d\n\ %d\n\ %s%d%s\n\ %s%d%s\n", - ip->min, ip->desired, - f1, ip->max, f2, - f1, ip->prio, f2); + ip->min, ip->desired, + f1, ip->max, f2, + f1, ip->prio, f2); total_traffic+=ip->traffic; total_direct+=ip->direct; @@ -312,37 +316,42 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) } fprintf(f,"\n\ %d CLASSES", colspan-7, i); - fprintf(f,"%Lu%Lu\n", total_traffic, total_direct); + fprintf(f, "%Lu%Lu\n", + total_traffic, total_direct); if(qos_proxy) { - fprintf(f,"%Lu\n", total_proxy); + fprintf(f," %Lu\n", total_proxy); } - fprintf(f,"%Lu", total_upload); - fprintf(f,"LIMIT %dx LOW-PRIO %dx\n\n",limit_count,prio_count); + fprintf(f, "%Lu", total_upload); + fprintf(f, "LIMIT %dx LOW-PRIO %dx\n\n", + limit_count, prio_count); if(ip6prefix) { - unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0; + for_each(ip, ips) { if(ip->v6) { bytes6 += ip->traffic; pkts6 += ip->pktsdown+ip->pktsup; + count6++; } else { bytes4 += ip->traffic; pkts4 += ip->pktsdown+ip->pktsup; + count4++; } } + perc6=(double)(100*bytes6)/(bytes4+bytes6); fputs("

\n",f); - fprintf(f, "%s\n", - tr_odd_even(), bytes4, (float)(100*bytes4)/(bytes4+bytes6), pkts4, (float)(100*pkts4)/(pkts4+pkts6)); - fprintf(f, "%s\n", - tr_odd_even(), bytes6, (float)(100*bytes6)/(bytes4+bytes6), pkts6, (float)(100*pkts6)/(pkts4+pkts6)); - fputs("
IP protocols usage
Total IPv4%Lu MB (%.2f %%)%Lu packets (%d %%)
Total IPv6%Lu MB (%.2f %%)%Lu packets (%d %%)
\n", f); + fprintf(f, "%sTotal %d IPv4 (addreses)%Lu MB (%.2f %%)%Lu packets (%.2f %%)\n", + tr_odd_even(), count4, bytes4, (double)(100*bytes4)/(bytes4+bytes6), pkts4, (float)(100*pkts4)/(pkts4+pkts6)); + fprintf(f, "%sTotal %d IPv6 (/64 ranges)%Lu MB (%.2f %%)%Lu packets (%.2f %%)\n", + tr_odd_even(), count6, bytes6, perc6, pkts6, (float)(100*pkts6)/(pkts4+pkts6)); + fputs("

\n", f); } row_odd_even = 0; @@ -359,7 +368,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) Data transfers\n\ \n",f); - if_exists(sum,sums,sum->l>=total_traffic/4) + if_exists(sum,sums,sum->l >= total_traffic/4) { fprintf(f,"%sTop 25%% of traffic\n", tr_odd_even()); fprintf(f,"%d\n\ @@ -369,7 +378,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) sum->i, (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->i==10) + if_exists(sum,sums,sum->i == 10) { fprintf(f,"%sTop 10 downloaders\n", tr_odd_even()); fprintf(f,"10\n\ @@ -379,7 +388,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->l>=total_traffic/2) + if_exists(sum,sums,sum->l >= total_traffic/2) { fprintf(f,"%sTop 50%% of traffic\n", tr_odd_even()); fprintf(f,"%d\n\ @@ -389,7 +398,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->l>=4*total_traffic/5) + if_exists(sum,sums,sum->l >= 4*total_traffic/5) { fprintf(f,"%sTop 80%% of traffic\n", tr_odd_even()); fprintf(f,"%d\n\ @@ -399,7 +408,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->i>=(active_classes+1)/5) + if_exists(sum,sums,sum->i >= (active_classes+1)/5) { fprintf(f,"%sTop 20%% downloaders\n", tr_odd_even()); top20_count=sum->i; @@ -413,7 +422,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) top20_count,top20_perc1,top20_sum,top20_perc2); } - if_exists(sum,sums,sum->i>=(active_classes+1)/4) + if_exists(sum,sums,sum->i >= (active_classes+1)/4) { fprintf(f,"%sTop 25%% downloaders\n", tr_odd_even()); fprintf(f,"%d\n\ @@ -433,7 +442,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->i>=4*(active_classes+1)/5) + if_exists(sum,sums,sum->i >= 4*(active_classes+1)/5) { fprintf(f,"%sTop 80%% downloaders\n", tr_odd_even()); fprintf(f,"%d\n\ @@ -448,7 +457,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) 100 %%\n\ %Lu MB\n\ 100 %%\n",active_classes,total_traffic); - fputs("\n", f); + fputs("

\n", f); /* write basic ERP data to log directory */ if(!just_preview) @@ -458,9 +467,10 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) iplog=fopen(str,"a"); if(iplog) { - fprintf(iplog,"%ld\t%d\t%d %%\t%Lu M\t%Ld %%\tACTIVE %d\tTRAFFIC %Lu M\tCLASSES %d\tFUP-LIMIT %d\tLOW-PRIO %d\t%s", - time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, - active_classes, total_traffic, i, limit_count, prio_count, d); /* d = date*/ + fprintf(iplog, "%ld\t%d\t%d %%\t%Lu M\t%Ld %%\tACTIVE %d\tTRAFFIC %Lu M\tCLASSES %d\tFUP-LIMIT %d\tLOW-PRIO %d\tIPv6 %Lu\t%.2f %%\t%s", + time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, + active_classes, total_traffic, i, limit_count, prio_count, + bytes6, perc6, d); /* d = date*/ fclose(iplog); } else diff --git a/parsehosts.c b/parsehosts.c index 92ee23a..1e8dbe6 100644 --- a/parsehosts.c +++ b/parsehosts.c @@ -51,7 +51,7 @@ parse_ip(char *str) { char *ptr, *ipaddr, *ip6range = NULL, *ipname = NULL, *lmsid = NULL; - if(ip6prefix) /* Try this only if IPv6 subsystem is active...*/ + if(ip6prefix) /* Try this only if IPv6 subsystem is active... */ { ptr = strstr(str, "::"); if(ptr && ptr-str > 4) @@ -160,6 +160,7 @@ void parse_hosts(char *hosts) if(lastIP6) { lastIP6->sharing = substring; + lastIP6 = NULL; } while(*substring and *substring != '\n') { @@ -174,6 +175,11 @@ void parse_hosts(char *hosts) if_exists(keyword,keywords,(substring=strstr(str,keyword->key))) { parse_ip(str); + if(lastIP6) + { + lastIP6->sharing = ip->name; + lastIP6 = NULL; + } ip->keyword = keyword; keyword->ip_count++; ip->prio = keyword->default_prio; diff --git a/prometheus.c b/prometheus.c index 20a7603..503bbac 100644 --- a/prometheus.c +++ b/prometheus.c @@ -1,5 +1,6 @@ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Prometheus QoS - you can "steal fire" from your ISP *//* "fair-per-IP" quality of service (QoS) utility */ +/* Prometheus QoS - you can "steal fire" from your ISP */ +/* "fair-per-IP" quality of service (QoS) utility */ /* requires Linux 2.4.x or 2.6.x with HTB support */ /* Copyright(C) 2005-2013 Michael Polak, Arachne Aerospace */ /* iptables-restore support Copyright(C) 2007-2008 ludva */ @@ -563,12 +564,12 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); /*-----------------------------------------------------------------*/ for_each(ip,ips) if(ip->sharing) { - for_each(sharedip,ips) if(eq(sharedip->name,ip->sharing)) + for_each(sharedip,ips) if(eq(sharedip->name, ip->sharing)) { - sharedip->traffic+=ip->traffic; - ip->traffic=0; - ip->mark=sharedip->mark; - ip->lmsid=sharedip->lmsid; + sharedip->traffic += ip->traffic; + ip->traffic = 0; + ip->mark = sharedip->mark; + ip->lmsid = sharedip->lmsid; break; } if(not sharedip)