X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=htmlandlogs.c;h=70377848b7c501bd89f458541495d637d9ecf941;hb=bf59a20b46290db34e1761926a39ee68164d636b;hp=e11af1abac500b99e2b38d3489a4769a57e1455e;hpb=0b9c3c198771800cc6c5fbacfc0272549626bcfd;p=svn%2FPrometheus-QoS%2F.git diff --git a/htmlandlogs.c b/htmlandlogs.c index e11af1a..7037784 100644 --- a/htmlandlogs.c +++ b/htmlandlogs.c @@ -1,3 +1,5 @@ +/* Modified by: xChaos, 20131119 */ + #include "cll1-0.6.2.h" #include "ipstruct.h" #define STRLEN 512 @@ -20,6 +22,7 @@ extern char *log_url; extern int found_lmsid; extern char *lms_url; extern char *log_dir; +extern char *ip6prefix; const char *tr_odd_even(void); /* implemented in prometheus.c, shared with parselogs.c */ @@ -30,14 +33,18 @@ void append_log(struct IP *self) /*using global variables*/ FILE *f; date(d); /* this is typical cll1.h macro - prints current date */ - string(str,STRLEN); - sprintf(str,"%s/%s.log", log_dir, self->name); - f=fopen(str,"a"); + string(str, STRLEN); + sprintf(str, "%s/%s.log", log_dir, self->name); + + /*-----------------------------------------------------------------*/ + printf("Writing traffic log %s ...\n", str); + /*-----------------------------------------------------------------*/ + f = fopen(str, "a"); if(f > 0) { - fprintf(f,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s", - time(NULL), self->name, self->traffic, self->direct, self->proxy, - self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/ + fprintf(f, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s", + time(NULL), self->name, self->traffic, self->direct, self->proxy, + self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/ fclose(f); } else @@ -85,8 +92,8 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) for_each(keyword, keywords) if(keyword->ip_count) { - fprintf(f,"%d MB", - keyword->html_color, group->min*keyword->data_limit); + fprintf(f, "%d MB", + keyword->html_color, group->min*keyword->data_limit); } i += group->desired; total += group->count; @@ -118,30 +125,51 @@ 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; + unsigned long long total_pktup = 0, total_pktdown = 0; + int active_classes = 0; +// int colspan = 14; + struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums = NULL; + int agreg_count = 0, 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; + int mpkts; + double perc6; + +/* if(qos_proxy) { colspan++; } - +*/ + if(use_jquery_popups) + { + fprintf(f,""); + } + fprintf(f,"

\n\n", d); fputs("\n\n",f); - fputs("\n\ + fputs("\n\ \n\ \n\ -\n",f); +\n",f); +/* if(qos_proxy) { fputs("\n",f); } - fputs("\n\ +*/ + fputs("\n\ \n\ \n\ \n\ @@ -154,11 +182,13 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) \n\ \n\ \n\ +\n\ \n\ +\n\ \n\ \n\ \n\ -\n\ +\n\ \n",f); row_odd_even = 0; @@ -167,16 +197,22 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) char *f1="", *f2=""; i++; - if(ip->max < ip->desired) - { - f1 = ""; + if(ip->aggregated > 1) + { + f1 = ""; + f2 = ""; + agreg_count++; + } + else if(ip->max < ip->desired) + { + f1 = ""; f2 = ""; limit_count++; - } - else if(ip->prio > highest_priority+1) - { - f1 = ""; - f2 = ""; + } + else if(ip->prio > highest_priority+1) + { + f1 = ""; + f2 = ""; prio_count++; } @@ -184,28 +220,36 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); #endif /* hostnames -------------------------------------- */ - fprintf(f,"%s\ +\n",f); @@ -216,66 +260,134 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) fputs("\n",f); } fprintf(f,"\n", ip->credit); fprintf(f,"", ip->keyword->html_color, ip->realquota); - fprintf(f,"", f1, ip->traffic, f2); - /* download --------------------------------------- */ - fprintf(f,"\n",f); - /* ----------------------------------------------- */ + /* pkts up ----------------------------------- */ + mpkts = ip->pktsup>>20; + total_pktup += mpkts; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"\n",f); + +/* if(qos_proxy) { fprintf(f,"\n", ip->proxy); } - /* upload ---------------------------------------- */ - fprintf(f,"\n",f); + + /* pkts down ---------------------------------------- */ + mpkts = ip->pktsdown>>20; + total_pktdown += mpkts; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"\n",f); /* ----------------------------------------------- */ - fprintf(f,"\n\ + fprintf(f, "\n\ \n\ \n\ \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; @@ -300,15 +412,51 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) } } } - fprintf(f,"\n\ -", colspan-7, i); - fprintf(f,"\n", total_traffic, total_direct); + fprintf(f, "\n\ +", i); + fprintf(f, "\ +\n", + total_traffic, total_upload, total_pktup/i); +/* if(qos_proxy) { - fprintf(f,"\n", total_proxy); + fprintf(f," \n", total_proxy); + } +*/ + fprintf(f, "", + total_direct, total_pktdown/i); + fprintf(f, "\n
%s",title); fprintf(f," (%s)
 creditcred.FUPtotaldownuploadproxyupdownloadminmaxlimitMBMBMBpktMBpktkb/skb/skb/sprio!
%d%s\n", + fprintf(f,"%s%d%s\n", tr_odd_even(), ip->name, i, log_url, ip->name, ip->name); if(use_jquery_popups) { - fprintf(f,"",i); + fprintf(f, "",i); popup_button=0; + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */ { - fprintf(f,"
%s\n", log_url, sharedip->name, sharedip->name); + fprintf(f, "
%s\n", + log_url, sharedip->name, sharedip->name); popup_button++; } + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */ { - fprintf(f,"
%s/64\n", log_url, sharedip->addr, sharedip->addr); + fprintf(f, "
%s/%d\n", + log_url, sharedip->addr, sharedip->addr, sharedip->mask); popup_button++; } + fputs("
\n",f); if(popup_button) { - fprintf(f,"[+%d]", - i, i, i, popup_button); + fprintf(f, "[+%d]", + i, popup_button); } } fputs("
",f); if(ip->lmsid > 0) { - fprintf(f,"%04d\n", lms_url, ip->lmsid, ip->lmsid); + fprintf(f, "%04d\n", + lms_url, ip->lmsid, ip->lmsid); } else if(ip->lmsid == 0) { - fputs("-------",f); + fputs("------",f); } fputs("%Lu%Lu%s%Lu%s", f1, ip->traffic, f2); + fprintf(f,"%s%Lu%s%Lu", ip->direct); + /* upload --------------------------------------- */ + fprintf(f,"%Lu", ip->upload); if(use_jquery_popups) { - fprintf(f,"",i); + fprintf(f,"", i); for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */ { - fprintf(f,"
%Lu", sharedip->direct); + fprintf(f,"
%Lu", sharedip->upload); } for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */ { - fprintf(f,"
%Lu", sharedip->direct); + fprintf(f,"
%Lu", sharedip->upload); } fputs("
\n",f); } fputs("
%d", ip->upload/mpkts); + if(use_jquery_popups) + { + fprintf(f,"", i); + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */ + { + mpkts = sharedip->pktsup>>20; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"
%d", sharedip->upload/mpkts); + } + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */ + { + mpkts = sharedip->pktsup>>20; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"
%d", sharedip->upload/mpkts); + } + fputs("
\n",f); + } + fputs("
%Lu%Lu", ip->upload); +*/ + /* download ---------------------------------------- */ + fprintf(f,"%Lu", ip->direct); if(use_jquery_popups) { - fprintf(f,"",i); + fprintf(f,"", i); for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */ { - fprintf(f,"
%Lu", sharedip->upload); + fprintf(f,"
%Lu", sharedip->direct); } for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */ { - fprintf(f,"
%Lu", sharedip->upload); + fprintf(f,"
%Lu", sharedip->direct); + } + fputs("
\n",f); + } + fputs("
%d", ip->direct/mpkts); + if(use_jquery_popups) + { + fprintf(f,"", i); + for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */ + { + mpkts = sharedip->pktsdown>>20; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"
%d", sharedip->direct/mpkts); + } + for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */ + { + mpkts = sharedip->pktsdown>>20; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"
%d", sharedip->direct/mpkts); } fputs("
\n",f); } fputs("
%d%d%d%s%d%s%s%d%s
%d CLASSES%Lu%Lu
%d CLASSES%Lu%Lu%d%Lu%Lu%Lu%d\ +AGR %dx \ +FUP %dx \ +PRIO %dx
\n", + agreg_count, limit_count, prio_count); + + if(ip6prefix) + { + for_each(ip, ips) + { + if(ip->v6) + { + bytes6 += ip->upload + ip->direct; + pkts6 += ip->pktsdown + ip->pktsup; + count6++; + } + else + { + bytes4 += ip->upload + ip->direct; + pkts4 += ip->pktsdown + ip->pktsup; + count4++; + } + } + + perc6=(double)(bytes6)/(bytes4+bytes6)*100; + fputs("

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

\n", f); } - fprintf(f,"%Lu", total_upload); - fprintf(f,"LIMIT %dx LOW-PRIO %dx\n\n",limit_count,prio_count); row_odd_even = 0; if(active_classes>10) @@ -324,7 +472,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\ @@ -334,7 +482,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\ @@ -344,7 +492,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\ @@ -354,7 +502,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\ @@ -364,7 +512,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; @@ -378,7 +526,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\ @@ -398,7 +546,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\ @@ -413,7 +561,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) @@ -423,9 +571,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 M\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