From 5a8f2e77c57c7c7f2fcf1ef5933a0a771dd57777 Mon Sep 17 00:00:00 2001 From: xchaos Date: Sun, 4 May 2008 09:52:06 +0000 Subject: [PATCH] log bugfix + min. speed logging in monthly/yearly stats git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@84 251d49ef-1d17-4917-a970-b30cf55b089b --- prometheus.c | 57 +++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/prometheus.c b/prometheus.c index d8eaef2..8a567a1 100644 --- a/prometheus.c +++ b/prometheus.c @@ -552,7 +552,6 @@ void get_traffic_statistics(void) } } - free(cmd); } @@ -637,17 +636,17 @@ struct IpLog { char *name; long traffic; + long guaranted; list(IpLog); } *iplog,*iplogs; void parse_ip_log(int argc, char **argv) { - char *month,*year,*str,*name,*ptr,*ptr2; - long traffic,traffic_month,total=0; - int col,col2,y_ok,m_ok,accept_month,i=1,any_month=0; - char mstr[4],ystr[5]; - FILE *f; - + char *month, *year, *str, *name, *ptr, *ptr2; + long traffic, traffic_month, total=0, guaranted; + int col, col2, y_ok, m_ok, accept_month, i=1, any_month=0; + char mstr[4], ystr[5]; + FILE *f; string(str,STRLEN); if(argv[1][1]=='l') /* -l */ @@ -696,30 +695,36 @@ void parse_ip_log(int argc, char **argv) printf("Parsing %s ...",str); accept_month=0; traffic_month=0; + guaranted = 0; parse(str) { 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 9...*/ + case 2: name = ptr;break; + case 3: traffic = atol(ptr);break; + /* column number - was 7, now 10...*/ case 7: case 8: - case 9: if (isalnum(*ptr)) /* alphanumeric 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; - } - } + case 9: + case 10: if (isalnum(*ptr)) /* alphanumeric 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(y_ok && m_ok) { - traffic_month+=traffic; - accept_month=1; + traffic_month += traffic; + accept_month = 1; } } done; @@ -727,8 +732,9 @@ void parse_ip_log(int argc, char **argv) if(accept_month) { create(iplog,IpLog); - iplog->name=name; - iplog->traffic=traffic_month; + iplog->name = name; + iplog->guaranted = guaranted; + iplog->traffic = traffic_month; insert(iplog,iplogs,desc_order_by,traffic); printf(" %ld MB\n",iplog->traffic); } @@ -740,14 +746,15 @@ void parse_ip_log(int argc, char **argv) f=fopen(str,"w"); if(f) { - fprintf(f,"\n ",month,year); + fprintf(f,"
Data transfers - %s %s
\n ",month,year); every(iplog,iplogs) if(iplog->traffic) { - fprintf(f,"\n",i++,iplog->name,iplog->traffic,iplog->traffic>>10); + fprintf(f,"\n", + i++, iplog->name, iplog->traffic, iplog->traffic>>10, iplog->guaranted); total+=iplog->traffic>>10; } - fprintf(f,"\n",total); + fprintf(f,"\n", total, line); fputs("
Data transfers - %s %sMin.speed
%d%s%ld MB%ld GB
%d%s%ld MB%ld GB%ld kbps
Total:%ld GB
Total:%ld GB%Ld kbps
\n",f); fclose(f); puts(" done."); -- 2.30.2