1 #include "cll1-0.6.2.h"
4 /* globals declared in prometheus.c */
6 extern const char *version
;
7 extern const char *stats_html_signature
;
9 extern char *html_log_dir
;
10 extern int row_odd_even
;
13 extern long long int line
;
15 /* function implemented in prometheus.c */
16 const char *tr_odd_even(void);
29 void parse_ip_log(int argc
, char **argv
)
31 char *month
, *year
, *str
, *name
="(undefined)", *ptr
, *ptr2
, *filename
;
32 long traffic
=0l, traffic_month
, total
=0, guaranted
;
33 int col
, col2
, y_ok
, m_ok
, accept_month
, i
=1, any_month
=0, lmsid
;
34 char mstr
[4], ystr
[5];
37 string(filename
,STRLEN
);
39 if(argv
[1][1]=='l') /* -l */
43 puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)");
49 if(eq(month
,"Year")) any_month
=1;
55 time_t t
= time(NULL
) - 3600*24 ; /* yesterday's timestamp*/
56 struct tm
*timep
= localtime(&t
);
58 if(argv
[1][1]=='m') /* -m yestarday - month */
60 strftime(mstr
, 4, "%b", timep
);
62 strftime(ystr
, 5, "%Y", timep
);
65 else /* -y yesterday - year */
69 strftime(ystr
, 5, "%Y", timep
);
73 printf("Analysing traffic for %s %s ...\n",month
,year
);
75 /* sorry... next release of C<<1 header file will include for_path_files(name,path) { } macro */
76 sprintf(str
,"%s %s/",ls
,log_dir
);
80 if(strstr(str
,".log"))
82 ptr
=strrchr(str
,'\n');
84 sprintf(filename
,"%s/%s",log_dir
,str
);
85 printf("Parsing %s ...",filename
);
93 valid_columns(ptr
,_
,'\t',col
) switch(col
)
95 case 2: name
= ptr
;break;
96 case 3: traffic
= atol(ptr
);break;
97 /* column number - was 7, now 11...*/
102 case 11: if(isalpha(*ptr
)) /* character, not numeric string = date, just one*/
104 valid_columns(ptr2
,ptr
,' ',col2
) switch(col2
)
106 case 2: if(any_month
|| eq(ptr2
,month
)) m_ok
= 1; break;
107 case 5: if(eq(ptr2
,year
)) y_ok
= 1; break;
112 if(col
== 7) guaranted
= atol(ptr
);
113 if(col
== 10) lmsid
= atoi(ptr
);
119 traffic_month
+= traffic
;
123 done
; /* ugly macro end */
129 iplog
->guaranted
= guaranted
;
130 iplog
->traffic
= traffic_month
;
131 iplog
->lmsid
= lmsid
;
132 insert(iplog
,iplogs
,desc_order_by
,traffic
);
133 printf(" %ld MB\n",iplog
->traffic
);
137 puts(" no records.");
141 sprintf(str
,"%s/%s-%s.html",html_log_dir
,year
,month
);
142 printf("Writing %s ... ",str
);
146 fprintf(f
, "<table class=\"decorated last\"><thead>\n\
147 <tr><th colspan=\"2\">%s %s</th>\n\
148 <th style=\"text-align: right\">lms</th>\n\
149 <th colspan=\"2\">Data transfers</th>\n\
150 <th style=\"text-align: right\">Min.speed</th>\n\
151 </tr></thead><tbody>\n ",
155 for_each(iplog
, iplogs
)
159 fprintf(f
, "%s<td style=\"text-align: right\">%d</td>\n\
160 <td style=\"text-align: left\"><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</td>\n\
161 <td style=\"text-align: right\">",
162 tr_odd_even(), i
++, log_url
, iplog
->name
, iplog
->name
);
165 /*base URL will be configurable soon ... */
166 fprintf(f
, "<a class=\"blue\" target=\"_blank\" href=\"%s%d\">%04d</a>\n", lms_url
, iplog
->lmsid
, iplog
->lmsid
);
168 else if(iplog
->lmsid
== 0)
172 fprintf(f
, "<td style=\"text-align: right\">%ld MB</td>\n\
173 <td style=\"text-align: right\"><strong>%ld GB</strong></td>\n\
174 <td style=\"text-align: right\">%ld kb/s</th></tr>\n",
175 iplog
->traffic
, iplog
->traffic
>>10, iplog
->guaranted
);
176 total
+=iplog
->traffic
>>10;
181 fprintf(f
,"</tbody><thead><tr>\
182 <th colspan=\"3\" style=\"text-align: left\">Total:</th>\
183 <th colspan=\"2\" style=\"text-align: right\"><strong>%ld GB</strong></th>\
184 <th style=\"text-align: right\"><strong>%Ld kb/s</strong></th></tr>\n", total
, line
);
185 fputs("</thead></table>\n", f
);
190 fputs("<a name=\"erp\"></a><p><table class=\"decorated last\">\n\
191 <caption>Enterprise Resource Planning (ERP)</caption>\n\
193 <th>Analytic category</th>\n\
194 <th colspan=\"2\" style=\"text-align: center\">Active Classes</th>\n\
195 <th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\
196 </tr></thead><tbody>\n",f
);
198 if_exists(iplog
,iplogs
,iplog
->l
>=total
/4)
200 fprintf(f
,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());
201 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
202 <td style=\"text-align: right\">%d %%</td>\n\
203 <td style=\"text-align: right\">%ld GB</td>\n\
204 <td style=\"text-align: right\">%d %%</td></tr>\n",
205 iplog
->i
, (100*iplog
->i
+50)/i
, iplog
->l
, (int)((100*iplog
->l
+50)/total
));
208 if_exists(iplog
,iplogs
,iplog
->i
==10)
210 fprintf(f
,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());
211 fprintf(f
,"<td style=\"text-align: right\"><strong>10</strong></td>\n\
212 <td style=\"text-align: right\">%d %%</td>\n\
213 <td style=\"text-align: right\">%ld GB</td>\n\
214 <td style=\"text-align: right\">%d %%</td></tr>\n",
215 (100*iplog
->i
+50)/i
, iplog
->l
, (int)((100*iplog
->l
+50)/total
));
218 if_exists(iplog
,iplogs
,iplog
->l
>=total
/2)
220 fprintf(f
,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());
221 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
222 <td style=\"text-align: right\">%d %%</td>\n\
223 <td style=\"text-align: right\">%ld GB</td>\n\
224 <td style=\"text-align: right\"><strong>%d %%</strong></td></tr>\n",
225 iplog
->i
,(100*iplog
->i
+50)/i
,iplog
->l
,(int)((100*iplog
->l
+50)/total
));
228 if_exists(iplog
,iplogs
,iplog
->l
>=4*total
/5)
230 fprintf(f
,"%s<td>Top 80%% of traffic</td>\n",tr_odd_even());
231 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
232 <td style=\"text-align: right\">%d %%</td>\n\
233 <td style=\"text-align: right\">%ld GB</td>\n\
234 <td style=\"text-align: right\"><strong>%d %%</strong></td></tr>\n",
235 iplog
->i
, (100*iplog
->i
+50)/i
, iplog
->l
, (int)((100*iplog
->l
+50)/total
));
238 if_exists (iplog
,iplogs
,iplog
->i
>=i
/5)
240 fprintf(f
,"%s<td>Top 20%% downloaders</td>\n",tr_odd_even());
241 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
242 <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\
243 <td style=\"text-align: right\">%ld GB</td>\n\
244 <td style=\"text-align: right\">%d %%</td></tr>\n",
245 iplog
->i
, (100*iplog
->i
+50)/i
, iplog
->l
, (int)((100*iplog
->l
+50)/total
));
248 if_exists(iplog
,iplogs
,iplog
->i
>=i
/4)
250 fprintf(f
,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());
251 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
252 <td style=\"text-align: right\">%d %%</td>\n\
253 <td style=\"text-align: right\">%ld GB</td>\n\
254 <td style=\"text-align: right\">%d %%</td></tr>\n",
255 iplog
->i
, (100*iplog
->i
+50)/i
, iplog
->l
, (int)((100*iplog
->l
+50)/total
));
258 if_exists(iplog
,iplogs
,iplog
->i
>=i
/2)
260 fprintf(f
,"%s<td>Top 50%% downloaders</td>\n",tr_odd_even());
261 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
262 <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\
263 <td style=\"text-align: right\">%ld GB</td>\n\
264 <td style=\"text-align: right\">%d %%</td></tr>\n",
265 iplog
->i
, (100*iplog
->i
+50)/i
, iplog
->l
, (int)((100*iplog
->l
+50)/total
));
268 if_exists(iplog
,iplogs
,iplog
->i
>=4*i
/5)
270 fprintf(f
,"%s<td>Top 80%% downloaders</td>\n",tr_odd_even());
271 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
272 <td style=\"text-align: right\">%d %%</td>\n\
273 <td style=\"text-align: right\">%ld GB</td>\n\
274 <td style=\"text-align: right\">%d %%</td></tr>\n",
275 iplog
->i
, (100*iplog
->i
+50)/i
, iplog
->l
, (int)((100*iplog
->l
+50)/total
));
278 fprintf(f
,"</tbody><thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url
);
279 fprintf(f
,"<th style=\"text-align: right\">%d</th>\n\
280 <th style=\"text-align: right\">100 %%</th>\n\
281 <th style=\"text-align: right\">%ld GB</th>\n\
282 <th style=\"text-align: right\">100 %%</th></tr>\n",i
-1,total
);
283 fputs("</thead></table>\n", f
);
286 fprintf(f
, stats_html_signature
, version
);
This page took 0.69582 seconds and 4 git commands to generate.