X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=htmlandlogs.c;h=c6d16120dd6da25646555ddcdd2f7e0a1eb295a4;hb=62b118c2d21d2ee89872ec6d3e253039728abd5d;hp=73a3d0f3f682270e99c28213202c77bcfbfd2a2b;hpb=e48d46c959233c89ccd6ccd411b31704610abb71;p=svn%2FPrometheus-QoS%2F.git
diff --git a/htmlandlogs.c b/htmlandlogs.c
index 73a3d0f..c6d1612 100644
--- a/htmlandlogs.c
+++ b/htmlandlogs.c
@@ -20,6 +20,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 +31,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
@@ -50,7 +55,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
{
int i;
char *str;
- FILE *f=fopen(html,"w");
+ FILE *f=fopen(html, "w");
string(str,STRLEN);
if(f > 0)
@@ -58,10 +63,6 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
int count=1;
i=0;
- /*-----------------------------------------------------------------*/
- printf("Writing statistics summary into HTML page %s ...\n", html);
- /*-----------------------------------------------------------------*/
-
if(use_jquery_popups)
{
fprintf(f,"\n", jquery_url);
@@ -89,8 +90,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;
@@ -122,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)
{
@@ -172,15 +177,15 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
i++;
if(ip->max < ip->desired)
- {
- f1 = "";
+ {
+ f1 = "";
f2 = "";
limit_count++;
- }
- else if(ip->prio > highest_priority+1)
- {
- f1 = "";
- f2 = "";
+ }
+ else if(ip->prio > highest_priority+1)
+ {
+ f1 = "";
+ f2 = "";
prio_count++;
}
@@ -193,18 +198,28 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
if(use_jquery_popups)
{
- fprintf(f,"",i);
+ fprintf(f, "",i);
popup_button=0;
- for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing))
+
+ for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */
+ {
+ 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\n", log_url, sharedip->name, sharedip->name);
+ fprintf(f, "
%s/64\n",
+ log_url, sharedip->addr, sharedip->addr);
popup_button++;
}
+
fputs("\n",f);
if(popup_button)
{
- fprintf(f,"[+%d]",
- i, i, i, popup_button);
+ fprintf(f, "[+%d]",
+ i, i, i, popup_button);
}
}
fputs("\n",f);
@@ -232,8 +247,12 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
fprintf(f,"%Lu", ip->direct);
if(use_jquery_popups)
{
- fprintf(f,"",i);
- for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing))
+ fprintf(f,"", i);
+ for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */
+ {
+ fprintf(f," %Lu", sharedip->direct);
+ }
+ for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */
{
fprintf(f," %Lu", sharedip->direct);
}
@@ -250,8 +269,12 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
fprintf(f," | %Lu", ip->upload);
if(use_jquery_popups)
{
- fprintf(f,"",i);
- for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing))
+ fprintf(f,"", i);
+ for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */
+ {
+ fprintf(f," %Lu", sharedip->upload);
+ }
+ for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */
{
fprintf(f," %Lu", sharedip->upload);
}
@@ -260,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;
@@ -293,13 +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);
+
+ 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("IP protocols usage\n",f);
+ fprintf(f, "%sTotal %d IPv4 addreses | %Lu MB (%.2f %%) | %Lu packets (%.2f %%) | \n",
+ tr_odd_even(), count4, bytes4, (double)(bytes4)/(bytes4+bytes6)*100, 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);
}
- 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)
@@ -315,7 +367,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\
@@ -325,7 +377,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\
@@ -335,7 +387,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\
@@ -345,7 +397,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\
@@ -355,7 +407,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;
@@ -369,7 +421,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\
@@ -389,7 +441,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\
@@ -404,7 +456,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)
@@ -414,9 +466,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