X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=prometheus.c;h=ed4661d46bbcefb8ebc6121c65c6223e641fed50;hb=3365c6a28452f26ca278fc73bf0c6a0393418224;hp=25a7233a71ae2d7051dc185f133bdb9639bc6afb;hpb=a1d21464b252ba1931f4ef6774633a625a07454f;p=svn%2FPrometheus-QoS%2F.git diff --git a/prometheus.c b/prometheus.c index 25a7233..ed4661d 100644 --- a/prometheus.c +++ b/prometheus.c @@ -7,7 +7,7 @@ /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Modified by: xChaos, 20110427 +/* Modified by: xChaos, 20111130 ludva, 20080415 Prometheus QoS is free software; you can redistribute it and/or @@ -33,7 +33,7 @@ #include "cll1-0.6.2.h" -const char *version = "0.8.3"; +const char *version = "0.8.3-b"; /* Version numbers: 0.8.3 is development releases ("beta"), 0.8.4 will be "stable" */ /* Debian(RPM) package versions/patchlevels: 0.7.9-2, 0.8.0-1, 0.8.0-2, etc. */ @@ -62,6 +62,10 @@ char *log_dir = "/var/www/logs/"; /* log directory pathname, ended with char *log_url = "logs/"; /* log directory relative URI prefix (partial URL) */ char *html_log_dir = "/var/www/logs/html/"; +char *jquery_url = "http://code.jquery.com/jquery-latest.js"; +char *lms_url = "/lms/?m=customerinfo&id="; +int use_jquery_popups = 1; + /* ======= Help screen is hopefuly self-documenting part of code :-) ======= */ void help(void) @@ -408,6 +412,9 @@ void get_config(char *config_filename) option("log-traffic-directory",log_dir); option("log-traffic-html-directory",html_log_dir); option("log-traffic-url-path",log_url); + option("jquery-url",jquery_url); + option("lms-url",lms_url); + ioption("use-jquery-popups",use_jquery_popups); option("qos-free-zone",qos_free_zone); ioption("qos-free-delay",qos_free_delay); ioption("qos-proxy-enable",qos_proxy); @@ -620,7 +627,7 @@ void save_line(char *line) void run_restore(void) { - char *restor, *str; + char *restor; string(restor,STRLEN); /*-----------------------------------------------------------------*/ @@ -839,25 +846,37 @@ void parse_ip_log(int argc, char **argv) f=fopen(str,"w"); if(f) { - fprintf(f,"\n ",month,year); + fprintf(f, "
%s %sData transfersMin.speed
\n ", + month, year); - for_each(iplog,iplogs) + for_each(iplog, iplogs) { if(iplog->traffic) { - fprintf(f,"\n", - i++, iplog->name, iplog->traffic, iplog->traffic>>10, iplog->guaranted); + fprintf(f, "\n", + iplog->traffic, iplog->traffic>>10, iplog->guaranted); total+=iplog->traffic>>10; iplog->i=i; iplog->l=total; } } - fprintf(f,"\n", total, line); + fprintf(f,"\n", total, line); fputs("
%s %slmsData transfersMin.speed
%d%s%ld M%ld G%ld kbps
%d%s", + i++, iplog->name); + if(iplog->lmsid > 0) + { + /*base URL will be configurable soon ... */ + fprintf(f, "%04d\n", lms_url, iplog->lmsid, iplog->lmsid); + } + else if(iplog->lmsid == 0) + { + fputs("-------",f); + } + fprintf(f, "%ld M%ld G%ld kbps
Total:%ld GB%Ld kbps
Total:%ld GB%Ld kbps
\n", f); if(i>10) { - fputs("

\n",f); + fputs("

Enterprise Research and Planning (ERP)
\n",f); fputs("\n",f); fputs("\n",f); @@ -937,6 +956,7 @@ program int just_preview=FALSE; /* preview - generate just stats */ int just_logs=FALSE; /* just parse logs */ int run=FALSE; + int total=0; char *chain_forward, *chain_postrouting; char *althosts=NULL; @@ -1116,13 +1136,14 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); /*-----------------------------------------------------------------*/ puts("Resolving shared connections ..."); /*-----------------------------------------------------------------*/ - for_selected(ip,ips,ip->sharing) + for_each(ip,ips) if(ip->sharing) { - for_selected(sharedip,ips,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; break; } if(!sharedip) @@ -1221,7 +1242,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); save_line(":post_common - [0:0]"); save_line(":forw_common - [0:0]"); - for_selected(ip,ips,ip->addr && *(ip->addr) && !eq(ip->addr,"0.0.0.0/0")) + for_each(ip,ips) if (ip->addr && *(ip->addr) && !eq(ip->addr,"0.0.0.0/0")) { buf=hash_id(ip->addr,bitmask); if_exists(idx,idxs,eq(idx->id,buf)) @@ -1247,7 +1268,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); bitmask-=idxtable_bitmask2; idxcount=0; - for_selected(idx,idxs,idx->parent==NULL) + for_each(idx,idxs) if(idx->parent == NULL) { buf=hash_id(idx->addr,bitmask); if_exists(metaindex,idxs,eq(metaindex->id,buf)) @@ -1344,7 +1365,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); sleep(qos_free_delay); } - sprintf(str,"%s qdisc add dev %s root handle 1: htb r2q %d default 1",tc,lan,htb_r2q); + sprintf(str,"%s qdisc add dev %s root handle 1: htb r2q %d default 1", + tc,lan,htb_r2q); safe_run(str); sprintf(str, "%s class add dev %s parent 1: classid 1:2 htb rate %s ceil %s burst %dk prio %d", @@ -1375,14 +1397,14 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); /*-----------------------------------------------------------------*/ /* sub-scope - local variables */ { - long long int rate=line; - long long int max=line; - int group_count=0; - FILE *credit_file=NULL; + long long int rate = line; + long long int max = line; + int group_count = 0; + FILE *credit_file = NULL; if(!just_preview && !dry_run && enable_credit) { - credit_file=fopen(credit,"w"); + credit_file = fopen(credit,"w"); } for_each(group,groups) @@ -1400,27 +1422,27 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); safe_run(str); } - if(group_count++id; + parent = group->id; } - rate-=digital_divide*group->min; - if(ratemin) + rate -= digital_divide*group->min; + if(rate < group->min) { - rate=group->min; + rate = group->min; } /*shaping of aggresive downloaders, with credit file support */ if(use_credit) { - int group_rate=group->min, priority_sequence=lowest_priority; + int group_rate = group->min, priority_sequence = lowest_priority; - for_selected(ip, ips, ip->min==group->min && ip->max>ip->min) + for_each(ip, ips) if(ip->min == group->min && ip->max > ip->min) { - if( ip->keyword->data_limit && !ip->fixedprio && - ip->traffic>ip->credit+ - (ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)) ) + if( ip->keyword->data_limit && !ip->fixedprio + && ( ip->traffic>ip->credit + + (ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20))) ) { if(group_ratemax) { @@ -1435,9 +1457,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); } else { - if( ip->keyword->data_prio && !ip->fixedprio && - ip->traffic>ip->credit+ - (ip->min*ip->keyword->data_prio+(ip->keyword->fixed_prio<<20)) ) + if( ip->keyword->data_prio + && !ip->fixedprio + && ( ip->traffic>ip->credit + + (ip->min*ip->keyword->data_prio+(ip->keyword->fixed_prio<<20))) ) { ip->prio=priority_sequence--; if(ip->prioaddr,lcredit); } } - } - + } } } if(credit_file) @@ -1480,8 +1502,11 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); f=fopen("/var/run/prometheus.previous","w"); if(f) { - for_selected(ip,ips,ip->traffic || ip->direct || ip->proxy ||ip->upload) - fprintf(f,"%s %Lu %Lu %Lu %Lu\n",ip->addr,ip->traffic,ip->direct,ip->proxy,ip->upload); + for_each(ip,ips) if(ip->traffic || ip->direct || ip->proxy || ip->upload) + { + fprintf(f,"%s %Lu %Lu %Lu %Lu\n", + ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload); + } fclose(f); } @@ -1491,62 +1516,72 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); if(f) { - int total=0; int count=1; i=0; /*-----------------------------------------------------------------*/ - printf("Sorting data and generating statistics page %s ...\n",ptr); + printf("Sorting data and generating statistics page %s ...\n", ptr); /*-----------------------------------------------------------------*/ + if(use_jquery_popups) + { + fprintf(f,"\n", jquery_url); + } fputs("
Enterprise Resource Planning (ERP)
Analytic categoryActive ClassesData transfers
\n\n",f); - fprintf(f,"\n",keywordcount); + fprintf(f,"\n", keywordcount); fputs("\n",f); - for_each(group,groups) + for_each(group, groups) { #ifdef DEBUG printf("%d k group: %d bandwidth requested: %d k\n",group->min,group->count,group->desired); #endif - fprintf(f,"",count,group->min); - fprintf(f,"",group->count,group->desired); + fprintf(f,"", + count, group->min); + fprintf(f,"", + group->count, group->desired); - for_each(keyword,keywords) + for_each(keyword, keywords) { - fprintf(f,"",keyword->html_color,group->min*keyword->data_limit); + fprintf(f,"", + keyword->html_color, group->min*keyword->data_limit); } - i+=group->desired; - total+=group->count; + i += group->desired; + total += group->count; count++; } #ifdef DEBUG - printf("Total groups: %d Total bandwidth requested: %d k\nAGGREGATION: 1/%d\n",count,i,i/line); + printf("Total groups: %d Total bandwidth requested: %d k\nAGGREGATION: 1/%d\n", + count, i, i/line); #endif fprintf(f,"",keyword->ip_count); } - fprintf(f,"\n",(int)(0.5+i/line)); - fprintf(f,"\n",keywordcount,total); + fprintf(f,"\n", (int)(0.5+i/line)); + fprintf(f,"\n", keywordcount, total); fputs("
#groupIPsrequesteddata limitsdata limits
%d%d k%d%d k
%d%d k%d%d k%d M%d M
Line %Ld k",line); fprintf(f,"%d%d k",total,i); - for_each(keyword,keywords) + for_each(keyword, keywords) { fprintf(f,"%d IPs
Aggregation 1/%d%d traffic classes
Aggregation 1/%d%d traffic classes
\n",f); } - else if(!dry_run && !just_flush) + else if(!dry_run && !just_flush) + { perror(html); + } - i=1; + i=0; if(f) { - unsigned long long total=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum=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; + int colspan=11; FILE *iplog; struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums=NULL; + int limit_count=0, prio_count=0; + int popup_button=0; - colspan=11; if(qos_proxy) { colspan++; @@ -1577,50 +1612,104 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); maximum\ prio\n",f); - for_each(ip,ips) + for_each(ip,ips) if(!use_jquery_popups || !ip->sharing) { char *f1="", *f2=""; - if(ip->maxdesired) + i++; + + if(ip->max < ip->desired) { - f1=""; - f2=""; + f1=""; + f2=""; + limit_count++; } - else if(ip->prio>highest_priority+1) + else if(ip->prio > highest_priority+1) { - f1=""; - f2=""; + f1=""; + f2=""; + prio_count++; } #ifdef DEBUG printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); #endif - fprintf(f,"%d%s\n", ip->name, i, log_url, ip->name, ip->name); + /* hostnames -------------------------------------- */ + fprintf(f,"%d%s\n", ip->name, i, log_url, ip->name, ip->name); + if(use_jquery_popups) + { + fprintf(f,"",i); + popup_button=0; + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing)) + { + fprintf(f,"
%s\n", log_url, sharedip->name, sharedip->name); + popup_button++; + } + fputs("
\n",f); + if(popup_button) + { + fprintf(f,"[+%d]", + i, i, i, popup_button); + } + } + fputs("\n",f); + /* ----------------------------------------------- */ + if(found_lmsid) { fputs("",f); if(ip->lmsid > 0) { /*base URL will be configurable soon ... */ - fprintf(f,"%04d\n", ip->lmsid, ip->lmsid); + fprintf(f,"%04d\n", lms_url, ip->lmsid, ip->lmsid); } else if(ip->lmsid == 0) { - fputs("----",f); + fputs("-------",f); } - fputs("\n",f); + fputs("\n",f); + } + fprintf(f,"%Lu M\n", ip->credit); + fprintf(f,"%Lu M", + ip->keyword->html_color, + ip->credit+(ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20))); + fprintf(f,"%s%Lu M%s", f1, ip->traffic, f2); + + /* download --------------------------------------- */ + fprintf(f,"%Lu M", ip->direct); + if(use_jquery_popups) + { + fprintf(f,"",i); + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing)) + { + fprintf(f,"
%Lu M", sharedip->direct); + } + fputs("
\n",f); } - fprintf(f,"%Lu M\n", ip->credit); - fprintf(f,"%Lu M", - ip->keyword->html_color, ip->credit+(ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20))); - fprintf(f,"%s%Lu M%s%Lu M\n", f1, ip->traffic, f2, ip->direct); + fputs("\n",f); + /* ----------------------------------------------- */ + if(qos_proxy) { - fprintf(f,"%Lu M\n", ip->proxy); + fprintf(f,"%Lu M\n", ip->proxy); } - fprintf(f,"%Lu M\n", ip->upload); - fprintf(f,"%d k%d k%s%d k%s%s%d%s\n", + /* upload ---------------------------------------- */ + fprintf(f,"%Lu M", ip->upload); + if(use_jquery_popups) + { + fprintf(f,"",i); + for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing)) + { + fprintf(f,"
%Lu M", sharedip->upload); + } + fputs("
\n",f); + } + fputs("\n",f); + /* ----------------------------------------------- */ + + fprintf(f,"%d k%d k%s%d k%s%s%d%s\n", ip->min,ip->desired,f1,ip->max,f2,f1,ip->prio,f2); - total+=ip->traffic; + + total_traffic+=ip->traffic; total_direct+=ip->direct; total_proxy+=ip->proxy; total_upload+=ip->upload; @@ -1633,9 +1722,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); sum->i=active_classes; insert(sum,sums,order_by,i); } - - i++; - + if(!just_preview) { sprintf(str,"%s/%s.log",log_dir,ip->name); @@ -1643,80 +1730,102 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); if(iplog) { fprintf(iplog,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s", - time(NULL),ip->name,ip->traffic,ip->direct,ip->proxy,ip->upload,ip->min,ip->max,ip->desired,ip->lmsid,d); /* d = date*/ + time(NULL), ip->name, ip->traffic, ip->direct, ip->proxy, + ip->upload, ip->min, ip->max, ip->desired, ip->lmsid, d); /* d = date*/ fclose(iplog); } } - } - fprintf(f,"SUMMARY:",colspan-7); - fprintf(f,"%Lu M\ - %Lu M\n", total, total_direct); + fprintf(f,"%d CLASSES", colspan-7, i); + fprintf(f,"%Lu M%Lu M\n", total_traffic, total_direct); if(qos_proxy) { - fprintf(f,"%Lu M\n", total_proxy); + fprintf(f,"%Lu M\n", total_proxy); } - fprintf(f,"%Lu M", total_upload); - fputs("\n\n",f); + fprintf(f,"%Lu M", total_upload); + fprintf(f,"FUP-LIMIT %dx LOW-PRIO %dx\n\n",limit_count,prio_count); if(active_classes>10) { - fputs("

\n",f); + int top20_count=0,top20_perc1=0; + long long top20_perc2=0; + unsigned long long top20_sum=0l; + + fputs("

Enterprise Research and Planning (ERP)
\n",f); fputs("\n",f); fputs("\n",f); - if_exists(sum,sums,sum->l>=total/4) + if_exists(sum,sums,sum->l>=total_traffic/4) { fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } if_exists(sum,sums,sum->i==10) { fprintf(f,"\n"); - fprintf(f,"\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + fprintf(f,"\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->l>=total/2) + if_exists(sum,sums,sum->l>=total_traffic/2) { fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->l>=4*total/5) + if_exists(sum,sums,sum->l>=4*total_traffic/5) { fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + fprintf(f,"\n",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,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + top20_count=sum->i; + top20_perc1=(100*sum->i+50)/active_classes; + top20_sum=sum->l; + top20_perc2=(100*sum->l+50)/total_traffic; + fprintf(f,"\n",top20_count,top20_perc1,top20_sum,top20_perc2); } if_exists(sum,sums,sum->i>=(active_classes+1)/4) { fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + fprintf(f,"\n",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)/2) { fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + fprintf(f,"\n",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) { fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } - fprintf(f,"\n"); - fprintf(f,"\n",active_classes,total); + fprintf(f,"\n", log_url); + fprintf(f,"\n",active_classes,total_traffic); fputs("
Enterprise Resource Planning (ERP)
Analytic categoryActive ClassesData transfers
Top 25%% of traffic%d%d %%%Lu M%Ld %%
%d%d %%%Lu M%Ld %%
Top 10 downloaders10%d %%%Lu M%Ld %%
10%d %%%Lu M%Ld %%
Top 50%% of traffic%d%d %%%Lu M%Ld %%
%d%d %%%Lu M%Ld %%
Top 80%% of traffic%d%d %%%Lu M%Ld %%
%d%d %%%Lu M%Ld %%
Top 20%% downloaders%d%d %%%Lu M%Ld %%
%d%d %%%Lu M%Ld %%
Top 25%% downloaders%d%d %%%Lu M%Ld %%
%d%d %%%Lu M%Ld %%
Top 50%% downloaders%d%d %%%Lu M%Ld %%
%d%d %%%Lu M%Ld %%
Top 80%% downloaders%d%d %%%Lu M%Ld %%
%d%d %%%Lu M%Ld %%
All users, all traffic%d100 %%%Lu M100 %%
All users, all traffic%d100 %%%Lu M100 %%
\n", f); + + /* write basic ERP data to log directory */ + if(!just_preview) + { + sprintf(str,"%s/ERP.log",log_dir); + 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*/ + fclose(iplog); + } + } } + fprintf(f, stats_html_signature, version); fclose(f); } @@ -1734,9 +1843,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); i=0; printf("%-22s %-15s mark\n","name","ip"); - for_selected(ip,ips,ip->mark>0) + for_each(ip,ips) if(ip->mark>0) { - if(idxs) { char *buf;