X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=optional-tools%2Fprometheus-stats.c;fp=optional-tools%2Fprometheus-stats.c;h=b9e2457bc6e94ddc685126147838202760560de9;hp=0000000000000000000000000000000000000000;hb=ae776b1091bfdea4e2764ccb2652471ee5c9ce00;hpb=128e038085291f40482e39e9481d47942af7ceee diff --git a/optional-tools/prometheus-stats.c b/optional-tools/prometheus-stats.c new file mode 100644 index 0000000..b9e2457 --- /dev/null +++ b/optional-tools/prometheus-stats.c @@ -0,0 +1,96 @@ + +#include "cll1-0.6.h" + +#define STRLEN 128 + +const char *logdir="/var/www/logs"; +const char *htmldir="/var/www/logs/html"; + +/* Modified: Michal Polak (xChaos) 20070202 */ + +struct Ip +{ + char *name; + long traffic; + list(Ip); +} *ip,*ips; + +int main (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; + FILE *f; + + string(str,STRLEN); + + if(argc<3) + { + puts("Usage: monthly-stats Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)"); + exit(-1); + } + else + { + month=argv[1]; + if(eq(month,"Year")) any_month=1; + year=argv[2]; + } + + sprintf(str,"/bin/ls %s/*.log",logdir); + shell(str); + input(str,STRLEN) + { + ptr=strrchr(str,'\n'); + if(ptr) *ptr='\0'; + printf("Parsing %s ...",str); + accept_month=0; + traffic_month=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; + case 7: 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; + } + } + if(y_ok && m_ok) + { + traffic_month+=traffic; + accept_month=1; + } + } + done; + if(accept_month) + { + create(ip,Ip); + ip->name=name; + ip->traffic=traffic_month; + insert(ip,ips,desc_order_by,traffic); + printf(" %ld MB\n",ip->traffic); + } + else + puts(" no records."); + } + sprintf(str,"%s/%s-%s.html",htmldir,year,month); + printf("Writing %s ...",str); + f=fopen(str,"w"); + if(f) + { + fprintf(f,"\n ",month,year); + every(ip,ips) + if(ip->traffic) + { + fprintf(f,"\n",i++,ip->name,ip->traffic,ip->traffic>>10); + total+=ip->traffic>>10; + } + fprintf(f,"\n",total); + fputs("
Data transfers - %s %s
%d%s%ld MB%ld GB
Total:%ld GB
\n",f); + fclose(f); + puts(" done."); + } +}