6 const char *logdir
="/var/www/logs";
7 const char *htmldir
="/var/www/logs/html";
9 /* Modified: Michal Polak (xChaos) 20070202 */
18 int main (int argc
, char **argv
)
20 char *month
,*year
,*str
,*name
,*ptr
,*ptr2
;
21 long traffic
,traffic_month
,total
=0;
22 int col
,col2
,y_ok
,m_ok
,accept_month
,i
=1;
29 puts("Usage: monthly-stats Mmm YYYY (Mmm=Jan-Dec, YYYY=year)");
38 sprintf(str
,"/bin/ls %s/*.log",logdir
);
42 ptr
=strrchr(str
,'\n');
44 printf("Parsing %s ...",str
);
50 valid_columns(ptr
,_
,'\t',col
) switch(col
)
52 case 2: name
=ptr
;break;
53 case 3: traffic
=atol(ptr
);break;
54 case 7: valid_columns(ptr2
,ptr
,' ',col2
) switch(col2
)
56 case 2: if(eq(ptr2
,month
)) m_ok
=1; break;
57 case 5: if(eq(ptr2
,year
)) y_ok
=1; break;
62 traffic_month
+=traffic
;
71 ip
->traffic
=traffic_month
;
72 insert(ip
,ips
,desc_order_by
,traffic
);
73 printf(" %ld MB\n",ip
->traffic
);
78 sprintf(str
,"%s/%s-%s.html",htmldir
,year
,month
);
79 printf("Writing %s ...",str
);
83 fprintf(f
,"<table border><tr><th colspan=\"4\">Data transfers - %s %s</th></tr>\n ",month
,year
);
87 fprintf(f
,"<tr><td align=\"right\">%d</td><th>%s</td><td align=\"right\"> %ld MB</td><th align=\"right\"> %ld GB</td></tr>\n",i
++,ip
->name
,ip
->traffic
,ip
->traffic
>>10); fprintf(f
,"<tr><td align=\"right\">%d</td><th>%s</td><td align=\"right\">%ld MB</td><th align=\"right\">%ld GB</th></tr>\n",i
++,ip
->name
,ip
->traffic
,ip
->traffic
>>10);
88 total
+=ip
->traffic
>>10;
90 fprintf(f
,"<tr><th colspan=\"3\" align=\"left\">Total:</th><th align=\"right\">%ld GB</th></tr>\n",total
);
91 fputs("</table>\n",f
);
This page took 0.594036 seconds and 4 git commands to generate.