X-Git-Url: https://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=prometheus.c;h=64012559235dc72987d087318984737e747a92bf;hp=b6eeb27beb663cf9a18eed5131cd5b72bd9d766b;hb=5692c7757847ed4d412173d820392dbf2cfb5a70;hpb=6fb3c58ad91b3214a985824e1eb51ecaae442c60 diff --git a/prometheus.c b/prometheus.c index b6eeb27..6401255 100644 --- a/prometheus.c +++ b/prometheus.c @@ -26,7 +26,7 @@ GNU General Public License is located in file COPYING */ -#define STRLEN 256 +#define STRLEN 512 #define FIRSTGROUPID 1024 #define FIRSTIPCLASS 2048 #undef DEBUG @@ -71,6 +71,9 @@ int use_jquery_popups = 1; int row_odd_even = 0; /* */ +void parse_ip_log(int argc, char **argv); +/* implementid in parselog.c */ + const char *tr_odd_even(void) { row_odd_even = 1 - row_odd_even; @@ -776,283 +779,8 @@ char *parse_datafile_line(char *str) } } -struct IpLog -{ - char *name; - long traffic; - long guaranted; - int i; - int lmsid; - long l; - list(IpLog); -} *iplog,*iplogs; - -void parse_ip_log(int argc, char **argv) -{ - char *month, *year, *str, *name="(undefined)", *ptr, *ptr2, *filename; - long traffic=0l, traffic_month, total=0, guaranted; - int col, col2, y_ok, m_ok, accept_month, i=1, any_month=0, lmsid; - char mstr[4], ystr[5]; - FILE *f; - string(str,STRLEN); - string(filename,STRLEN); - - if(argv[1][1]=='l') /* -l */ - { - if(argc<4) - { - puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)"); - exit(-1); - } - else - { - month=argv[2]; - if(eq(month,"Year")) any_month=1; - year=argv[3]; - } - } - else - { - time_t t = time(NULL) - 3600*24 ; /* yesterday's timestamp*/ - struct tm *timep = localtime(&t); - - if(argv[1][1]=='m') /* -m yestarday - month */ - { - strftime(mstr, 4, "%b", timep); - month=mstr; - strftime(ystr, 5, "%Y", timep); - year=ystr; - } - else /* -y yesterday - year */ - { - month="Year"; - any_month=1; - strftime(ystr, 5, "%Y", timep); - year=ystr; - } - } - printf("Analysing traffic for %s %s ...\n",month,year); - - /* sorry... next release of C<<1 header file will include for_path_files(name,path) { } macro */ - sprintf(str,"%s %s/",ls,log_dir); - shell(str); - input(str,STRLEN) - { - if(strstr(str,".log")) - { - ptr=strrchr(str,'\n'); - if(ptr) *ptr='\0'; - sprintf(filename,"%s/%s",log_dir,str); - printf("Parsing %s ...",filename); - accept_month=0; - traffic_month=0; - guaranted=0; - lmsid=-1; - parse(filename) - { - y_ok=m_ok=0; - valid_columns(ptr,_,'\t',col) switch(col) - { - case 2: name = ptr;break; - case 3: traffic = atol(ptr);break; - /* column number - was 7, now 11...*/ - case 7: - case 8: - case 9: - case 10: - case 11: if(isalpha(*ptr)) /* character, not numeric string = date, just one*/ - { - valid_columns(ptr2,ptr,' ',col2) switch(col2) - { - case 2: if(any_month || eq(ptr2,month)) m_ok = 1; break; - case 5: if(eq(ptr2,year)) y_ok = 1; break; - } - } - else - { - if(col == 7) guaranted = atol(ptr); - if(col == 10) lmsid = atoi(ptr); - } - } - - if(y_ok && m_ok) - { - traffic_month += traffic; - accept_month = 1; - } - } - done; /* ugly macro end */ - - if(accept_month) - { - create(iplog,IpLog); - iplog->name = name; - iplog->guaranted = guaranted; - iplog->traffic = traffic_month; - iplog->lmsid = lmsid; - insert(iplog,iplogs,desc_order_by,traffic); - printf(" %ld MB\n",iplog->traffic); - } - else - { - puts(" no records."); - } - } - } - sprintf(str,"%s/%s-%s.html",html_log_dir,year,month); - printf("Writing %s ... ",str); - f=fopen(str,"w"); - if(f > 0) - { - fprintf(f, "\n\ -\n\ -\n\ -\n\ -\n\ -\n ", - month, year); - row_odd_even = 0; - for_each(iplog, iplogs) - { - if(iplog->traffic) - { - fprintf(f, "%s\n\ -\n\ -\n\ - \n\ - \n", - iplog->traffic, iplog->traffic>>10, iplog->guaranted); - total+=iplog->traffic>>10; - iplog->i=i; - iplog->l=total; - } - } - fprintf(f,"\ - \ - \ - \n", total, line); - fputs("
%s %slmsData transfersMin.speed
%d%s", - tr_odd_even(), i++, log_url, iplog->name, 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 MB%ld GB%ld kb/s
Total:%ld GB%Ld kb/s
\n", f); - row_odd_even = 0; - if(i>10) - { - fputs("

\n\ -\n\ -\n\ -\n\ -\n\ -\n\ -\n",f); - - if_exists(iplog,iplogs,iplog->l>=total/4) - { - fprintf(f,"%s\n", tr_odd_even()); - fprintf(f,"\n\ -\n\ -\n\ -\n", - iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total)); - } - - if_exists(iplog,iplogs,iplog->i==10) - { - fprintf(f,"%s\n", tr_odd_even()); - fprintf(f,"\n\ -\n\ -\n\ -\n", - (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total)); - } - - if_exists(iplog,iplogs,iplog->l>=total/2) - { - fprintf(f,"%s\n", tr_odd_even()); - fprintf(f,"\n\ -\n\ -\n\ -\n", - iplog->i,(100*iplog->i+50)/i,iplog->l,(int)((100*iplog->l+50)/total)); - } - - if_exists(iplog,iplogs,iplog->l>=4*total/5) - { - fprintf(f,"%s\n",tr_odd_even()); - fprintf(f,"\n\ -\n\ -\n\ -\n", - iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total)); - } - - if_exists (iplog,iplogs,iplog->i>=i/5) - { - fprintf(f,"%s\n",tr_odd_even()); - fprintf(f,"\n\ -\n\ -\n\ -\n", - iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total)); - } - - if_exists(iplog,iplogs,iplog->i>=i/4) - { - fprintf(f,"%s\n", tr_odd_even()); - fprintf(f,"\n\ -\n\ -\n\ -\n", - iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total)); - } - - if_exists(iplog,iplogs,iplog->i>=i/2) - { - fprintf(f,"%s\n",tr_odd_even()); - fprintf(f,"\n\ -\n\ -\n\ -\n", - iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total)); - } - - if_exists(iplog,iplogs,iplog->i>=4*i/5) - { - fprintf(f,"%s\n",tr_odd_even()); - fprintf(f,"\n\ -\n\ -\n\ -\n", - iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total)); - } - - fprintf(f,"\n", log_url); - fprintf(f,"\n\ -\n\ -\n\ -\n",i-1,total); - fputs("
Enterprise Resource Planning (ERP)
Analytic categoryActive ClassesData transfers
Top 25%% of traffic%d%d %%%ld GB%d %%
Top 10 downloaders10%d %%%ld GB%d %%
Top 50%% of traffic%d%d %%%ld GB%d %%
Top 80%% of traffic%d%d %%%ld GB%d %%
Top 20%% downloaders%d%d %%%ld GB%d %%
Top 25%% downloaders%d%d %%%ld GB%d %%
Top 50%% downloaders%d%d %%%ld GB%d %%
Top 80%% downloaders%d%d %%%ld GB%d %%
All users, all traffic%d100 %%%ld GB100 %%
\n", f); - } - - fprintf(f, stats_html_signature, version); - fclose(f); - puts("done."); - } - else - { - perror(str); - } -} void append_log(struct IP *self) /*using global variables*/ {