average speed calculation when analysing logs
[svn/Prometheus-QoS/.git] / htmlandlogs.c
CommitLineData
8e7aa995 1/* Modified by: xChaos, 20131119 */\r
2\r
9a56ab25 3#include "cll1-0.6.2.h"\r
4#include "ipstruct.h"\r
5#define STRLEN 512\r
6\r
7extern int row_odd_even;\r
8extern int use_jquery_popups;\r
9extern struct IP *ips, *ip, *sharedip;\r
10extern struct Group *groups, *group;\r
11extern struct Keyword *keyword, *defaultkeyword, *keywords;\r
12extern const int highest_priority;\r
13extern const char *version;\r
14extern const char *stats_html_signature;\r
15extern char *jquery_url;\r
16extern int keywordcount;\r
17extern long long int line;\r
18extern int dry_run;\r
19extern int qos_proxy;\r
20extern char *title;\r
21extern char *log_url;\r
22extern int found_lmsid;\r
23extern char *lms_url;\r
24extern char *log_dir;\r
ca6f7e80 25extern char *ip6prefix;\r
9a56ab25 26\r
27const char *tr_odd_even(void);\r
28/* implemented in prometheus.c, shared with parselogs.c */\r
29\r
30void append_log(struct IP *self) /*using global variables*/\r
31{\r
32 char *d, *str;\r
33 FILE *f; \r
34\r
35 date(d); /* this is typical cll1.h macro - prints current date */ \r
0995c4ad 36 string(str, STRLEN); \r
37 sprintf(str, "%s/%s.log", log_dir, self->name);\r
38\r
39 /*-----------------------------------------------------------------*/\r
40 printf("Writing traffic log %s ...\n", str);\r
41 /*-----------------------------------------------------------------*/\r
42 f = fopen(str, "a");\r
9a56ab25 43 if(f > 0)\r
44 {\r
0995c4ad 45 fprintf(f, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",\r
46 time(NULL), self->name, self->traffic, self->direct, self->proxy,\r
47 self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/\r
9a56ab25 48 fclose(f);\r
49 }\r
50 else\r
51 {\r
52 perror(str);\r
53 }\r
54}\r
55\r
56void write_htmlandlogs(char *html, char *d, int total, int just_preview)\r
57{\r
58 int i;\r
59 char *str;\r
0db8e993 60 FILE *f=fopen(html, "w");\r
9a56ab25 61\r
62 string(str,STRLEN); \r
63 if(f > 0)\r
64 {\r
65 int count=1;\r
66 i=0;\r
67\r
9a56ab25 68 if(use_jquery_popups)\r
69 {\r
70 fprintf(f,"<script type=\"text/javascript\" src=\"%s\"></script>\n", jquery_url);\r
71 }\r
72 fputs("<table class=\"decorated last\">\n\\r
73<caption>Bandwidth classes</caption>\n\\r
74<thead><tr>\n\\r
75<th style=\"text-align: right\">#</th>\n\\r
76<th style=\"text-align: right\">group</th>\n\\r
77<th style=\"text-align: right\">IPs</th>\n\\r
78<th style=\"text-align: right\">requested</th>\n",f);\r
79 fprintf(f,"<th colspan=\"%d\">data limits</th>\n", keywordcount);\r
80 fputs("</tr></thead><tbody>\n",f);\r
81\r
82 row_odd_even = 0;\r
83 for_each(group, groups) \r
84 { \r
85#ifdef DEBUG\r
86 printf("%d kb/s group: %d bandwidth requested: %d kb/s\n",group->min,group->count,group->desired);\r
87#endif\r
88 fprintf(f, "%s<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d&nbsp;kb/s</td>",\r
89 tr_odd_even(), count, group->min);\r
90 fprintf(f, "<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d&nbsp;kb/s</td>",\r
91 group->count, group->desired);\r
92\r
93 for_each(keyword, keywords) if(keyword->ip_count)\r
94 {\r
ca6f7e80 95 fprintf(f, "<td style=\"text-align: right\"><span style=\"color:#%s\">%d&nbsp;MB</span></td>",\r
96 keyword->html_color, group->min*keyword->data_limit);\r
9a56ab25 97 } \r
98 i += group->desired; \r
99 total += group->count;\r
100 count++; \r
101 }\r
102#ifdef DEBUG\r
103 printf("Total groups: %d Total bandwidth requested: %d kb/s\nAGGREGATION: 1/%d\n",\r
104 count, i, i/line);\r
105#endif\r
106 fprintf(f,"</tr></tbody>\n\\r
107<thead><tr>\n\\r
108<th colspan=\"2\" style=\"text-align: left\">Line %Ld kb/s</td>",line);\r
109 fprintf(f,"<th style=\"text-align: right\">%d</td><th style=\"text-align: right\">%d kb/s</td>",total,i);\r
110\r
111 for_each(keyword, keywords) if(keyword->ip_count)\r
112 {\r
113 fprintf(f,"<th style=\"text-align: right\">%d IPs</th>",keyword->ip_count);\r
114 }\r
115 fprintf(f,"</tr><tr><th colspan=\"4\">Aggregation 1/%d</th>\n", (int)(0.5+i/line));\r
116 fprintf(f,"<th colspan=\"%d\">%d traffic classes</th></tr>\n", keywordcount, total);\r
117\r
118 fputs("</thead></table>\n",f);\r
119 }\r
120 else\r
121 {\r
122 perror(html);\r
123 }\r
124\r
125 i=0;\r
126 if(f > 0)\r
127 {\r
b1a5c883 128 unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum = 0;\r
8e7aa995 129 unsigned long long total_pktup = 0, total_pktdown = 0;\r
b1a5c883 130 int active_classes = 0;\r
8e7aa995 131// int colspan = 14;\r
b1a5c883 132 struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums = NULL;\r
133 int limit_count = 0, prio_count = 0;\r
134 int popup_button = 0;\r
135 /* IPv6 vs. IPv4 stats */\r
136 unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0;\r
137 int count4 = 0, count6 = 0;\r
8e7aa995 138 int mpkts;\r
b1a5c883 139 double perc6;\r
9a56ab25 140\r
8e7aa995 141/*\r
9a56ab25 142 if(qos_proxy)\r
143 {\r
144 colspan++;\r
145 }\r
8e7aa995 146*/ \r
147 if(use_jquery_popups)\r
148 {\r
149 fprintf(f,"<script type=\"text/javascript\">\\r
150function show_section(n) {\\r
151$(\'#sharing_\'+n).show();\\r
152$(\'#download_'+n).show();\\r
153$(\'#pktsdown_\'+n).show();\\r
154$(\'#upload_'+n).show();\\r
155$(\'#pktsup_\'+n).show();\\r
156} </script>");\r
157 }\r
158\r
9a56ab25 159 fprintf(f,"<p><table class=\"decorated last\">\n<caption>%s",title);\r
160 fprintf(f," (%s)</caption>\n", d);\r
161 fputs("<thead><tr>\n<th colspan=\"3\">&nbsp;</th>\n",f);\r
8e7aa995 162 fputs("<th style=\"text-align: right\">cred.</th>\n\\r
9a56ab25 163<th style=\"text-align: right\">FUP</th>\n\\r
164<th style=\"text-align: right\">total</th>\n\\r
8e7aa995 165<th style=\"text-align: center\" colspan=\"2\">upload</th>\n",f);\r
166/*\r
9a56ab25 167 if(qos_proxy)\r
168 {\r
169 fputs("<th style=\"text-align: right\">proxy</th>\n",f);\r
170 }\r
8e7aa995 171*/\r
172 fputs("<th style=\"text-align: center\" colspan=\"2\">download</th>\n\\r
9a56ab25 173<th style=\"text-align: right\">min</th>\n\\r
174<th style=\"text-align: right\">max</th>\n\\r
175<th style=\"text-align: right\">limit</th>\n\\r
176<th>&nbsp;</th>\n\\r
177</tr><tr>\n\\r
178<th style=\"text-align: right\">#</th>\n\\r
179<th>hostname [+sharing]</th>\n\\r
180<th style=\"text-align: right\">LMS</th>\n\\r
181<th style=\"text-align: right\">MB</th>\n\\r
182<th style=\"text-align: right\">MB</th>\n\\r
183<th style=\"text-align: right\">MB</th>\n\\r
184<th style=\"text-align: right\">MB</th>\n\\r
8e7aa995 185<th style=\"text-align: right\">pkt</th>\n\\r
9a56ab25 186<th style=\"text-align: right\">MB</th>\n\\r
8e7aa995 187<th style=\"text-align: right\">pkt</th>\n\\r
9a56ab25 188<th style=\"text-align: right\">kb/s</th>\n\\r
189<th style=\"text-align: right\">kb/s</th>\n\\r
190<th style=\"text-align: right\">kb/s</th>\n\\r
8e7aa995 191<th>!</th>\n\\r
9a56ab25 192</tr></thead><tbody>\n",f); \r
193\r
194 row_odd_even = 0;\r
195 for_each(ip,ips) if(!use_jquery_popups || !ip->sharing)\r
196 {\r
197 char *f1="", *f2="";\r
198 i++;\r
199\r
200 if(ip->max < ip->desired) \r
ca6f7e80 201 {\r
202 f1 = "<span style=\"color:red\">";\r
9a56ab25 203 f2 = "</span>"; \r
204 limit_count++; \r
ca6f7e80 205 }\r
206 else if(ip->prio > highest_priority+1)\r
207 {\r
208 f1 = "<span style=\"color:brown\">";\r
209 f2 = "</span>";\r
9a56ab25 210 prio_count++; \r
211 } \r
212\r
213#ifdef DEBUG\r
214 printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); \r
215#endif\r
216 /* hostnames -------------------------------------- */\r
8e7aa995 217 fprintf(f,"%s<td style=\"text-align: right\"><a name=\"%s\"></a>%d</td>\\r
218<td><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", \r
9a56ab25 219 tr_odd_even(), ip->name, i, log_url, ip->name, ip->name);\r
220\r
221 if(use_jquery_popups)\r
222 {\r
ca6f7e80 223 fprintf(f, "<span id=\"sharing_%d\" style=\"display:none\">",i);\r
9a56ab25 224 popup_button=0;\r
ca6f7e80 225\r
0b9c3c19 226 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
9a56ab25 227 {\r
ca6f7e80 228 fprintf(f, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", \r
229 log_url, sharedip->name, sharedip->name);\r
9a56ab25 230 popup_button++;\r
231 }\r
ca6f7e80 232\r
0b9c3c19 233 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
f64d5431 234 {\r
64b2d125 235 fprintf(f, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s/%d</a>\n", \r
236 log_url, sharedip->addr, sharedip->addr, sharedip->mask);\r
f64d5431 237 popup_button++;\r
238 }\r
ca6f7e80 239\r
9a56ab25 240 fputs("</span>\n",f);\r
241 if(popup_button)\r
242 {\r
8e7aa995 243 fprintf(f, "<span>[<a class=\"blue\" href=\"#\" \\r
244onClick=\"$(this).parent().hide();show_section(\'%d\');return(false);\" \\r
245style=\"cursor: pointer;\">+%d</a>]</span>",\r
246 i, popup_button);\r
9a56ab25 247 }\r
248 }\r
249 fputs("</td>\n",f);\r
250 /* ----------------------------------------------- */\r
251\r
252 if(found_lmsid)\r
253 {\r
254 fputs("<td style=\"text-align: right\">",f);\r
255 if(ip->lmsid > 0)\r
256 {\r
8e7aa995 257 fprintf(f, "<a class=\"blue\" target=\"_blank\" href=\"%s%d\">%04d</a>\n",\r
258 lms_url, ip->lmsid, ip->lmsid);\r
9a56ab25 259 }\r
260 else if(ip->lmsid == 0)\r
261 {\r
3856be6a 262 fputs("------",f);\r
9a56ab25 263 }\r
264 fputs("</td>\n",f);\r
265 }\r
266 fprintf(f,"<td style=\"text-align: right\">%Lu</td>\n", ip->credit);\r
267 fprintf(f,"<td style=\"text-align: right\"><span style=\"color:#%s\">%Lu</span></td>",\r
e48d46c9 268 ip->keyword->html_color, ip->realquota);\r
8e7aa995 269 fprintf(f,"<td style=\"text-align: right\">%s%Lu%s</td>", f1, ip->traffic, f2);\r
9a56ab25 270\r
8e7aa995 271 /* upload --------------------------------------- */\r
272 fprintf(f,"<td style=\"text-align: right\">%Lu", ip->upload);\r
9a56ab25 273 if(use_jquery_popups)\r
274 {\r
8e7aa995 275 fprintf(f,"<span id=\"upload_%d\" style=\"display:none\">", i);\r
0b9c3c19 276 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
f64d5431 277 {\r
8e7aa995 278 fprintf(f,"<br />%Lu", sharedip->upload);\r
f64d5431 279 }\r
0b9c3c19 280 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
9a56ab25 281 {\r
8e7aa995 282 fprintf(f,"<br />%Lu", sharedip->upload);\r
283 }\r
284 fputs("</span>\n",f);\r
285 }\r
286 fputs("</td>\n",f);\r
287\r
288 /* pkts up ----------------------------------- */\r
289 mpkts = ip->pktsup>>20;\r
290 total_pktup += mpkts;\r
291 if(mpkts == 0)\r
292 {\r
293 mpkts = 1; /* prevent divide by zero*/\r
294 }\r
295 fprintf(f,"<td style=\"text-align: right\"><span style=\"color: gray\">%d</span>", ip->upload/mpkts);\r
296 if(use_jquery_popups)\r
297 {\r
298 fprintf(f,"<span id=\"pktsup_%d\" style=\"display:none\">", i);\r
299 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
300 {\r
301 mpkts = sharedip->pktsup>>20;\r
302 if(mpkts == 0)\r
303 {\r
304 mpkts = 1; /* prevent divide by zero*/\r
305 } \r
306 fprintf(f,"<br /><span style=\"color: gray\">%d</span>", sharedip->upload/mpkts);\r
307 }\r
308 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
309 {\r
310 mpkts = sharedip->pktsup>>20;\r
311 if(mpkts == 0)\r
312 {\r
313 mpkts = 1; /* prevent divide by zero*/\r
314 } \r
315 fprintf(f,"<br /><span style=\"color: gray\">%d</span>", sharedip->upload/mpkts);\r
9a56ab25 316 }\r
317 fputs("</span>\n",f);\r
318 }\r
319 fputs("</td>\n",f);\r
9a56ab25 320\r
8e7aa995 321/*\r
9a56ab25 322 if(qos_proxy)\r
323 {\r
324 fprintf(f,"<td style=\"text-align: right\">%Lu</td>\n", ip->proxy);\r
325 }\r
8e7aa995 326*/\r
327 /* download ---------------------------------------- */\r
328 fprintf(f,"<td style=\"text-align: right\">%Lu", ip->direct);\r
9a56ab25 329 if(use_jquery_popups)\r
330 {\r
8e7aa995 331 fprintf(f,"<span id=\"download_%d\" style=\"display:none\">", i);\r
0b9c3c19 332 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
f64d5431 333 {\r
8e7aa995 334 fprintf(f,"<br />%Lu", sharedip->direct);\r
f64d5431 335 }\r
0b9c3c19 336 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
9a56ab25 337 {\r
8e7aa995 338 fprintf(f,"<br />%Lu", sharedip->direct);\r
339 }\r
340 fputs("</span>\n",f);\r
341 }\r
342 fputs("</td>\n",f);\r
343\r
344 /* pkts down ---------------------------------------- */\r
345 mpkts = ip->pktsdown>>20;\r
346 total_pktdown += mpkts;\r
347 if(mpkts == 0)\r
348 {\r
349 mpkts = 1; /* prevent divide by zero*/\r
350 }\r
351 fprintf(f,"<td style=\"text-align: right\"><span style=\"color: gray\">%d</span>", ip->direct/mpkts);\r
352 if(use_jquery_popups)\r
353 {\r
354 fprintf(f,"<span id=\"pktsdown_%d\" style=\"display:none\">", i);\r
355 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
356 {\r
357 mpkts = sharedip->pktsdown>>20;\r
358 if(mpkts == 0)\r
359 {\r
360 mpkts = 1; /* prevent divide by zero*/\r
361 } \r
362 fprintf(f,"<br /><span style=\"color: gray\">%d</span>", sharedip->direct/mpkts);\r
363 }\r
364 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
365 {\r
366 mpkts = sharedip->pktsdown>>20;\r
367 if(mpkts == 0)\r
368 {\r
369 mpkts = 1; /* prevent divide by zero*/\r
370 } \r
371 fprintf(f,"<br /><span style=\"color: gray\">%d</span>", sharedip->direct/mpkts);\r
9a56ab25 372 }\r
373 fputs("</span>\n",f);\r
374 }\r
375 fputs("</td>\n",f);\r
376 /* ----------------------------------------------- */\r
377\r
b1a5c883 378 fprintf(f, "<td style=\"text-align: right\">%d</td>\n\\r
9a56ab25 379<td style=\"text-align: right\">%d</td>\n\\r
380<td style=\"text-align: right\">%s%d%s</td>\n\\r
381<td>%s%d%s</td></tr>\n",\r
b1a5c883 382 ip->min, ip->desired, \r
383 f1, ip->max, f2, \r
384 f1, ip->prio, f2);\r
9a56ab25 385\r
386 total_traffic+=ip->traffic;\r
387 total_direct+=ip->direct;\r
388 total_proxy+=ip->proxy;\r
389 total_upload+=ip->upload;\r
390 if(ip->traffic>0)\r
391 {\r
392 active_classes++;\r
393 tmp_sum+=ip->traffic;\r
394 create(sum,Sum);\r
395 sum->l=tmp_sum;\r
396 sum->i=active_classes;\r
397 insert(sum,sums,order_by,i);\r
398 }\r
399\r
400 if(!just_preview)\r
401 {\r
402 append_log(ip);\r
403 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing))\r
404 {\r
405 append_log(sharedip);\r
406 }\r
407 }\r
408 }\r
8e7aa995 409 fprintf(f, "</tbody><thead><tr>\n\\r
410<th colspan=\"5\" style=\"text-align: left\">%d CLASSES</th>", i);\r
411 fprintf(f, "<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%Lu</th>\\r
412<th style=\"text-align: right\">%d</th>\n",\r
413 total_traffic, total_upload, total_pktup/i);\r
414/*\r
9a56ab25 415 if(qos_proxy)\r
416 {\r
b1a5c883 417 fprintf(f," <th style=\"text-align: right\">%Lu</th>\n", total_proxy);\r
9a56ab25 418 }\r
8e7aa995 419*/\r
420 fprintf(f, "<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%d</th>",\r
421 total_direct, total_pktdown/i);\r
422 fprintf(f, "<th colspan=\"6\"><span style=\"color:red\">LIMIT %dx</span> \\r
423<span style=\"color:brown\">LOW-PRIO %dx</span></th></tr>\n</thead></table>\n",\r
b1a5c883 424 limit_count, prio_count);\r
9a56ab25 425\r
ca6f7e80 426 if(ip6prefix)\r
c2237b8a 427 { \r
ca6f7e80 428 for_each(ip, ips)\r
429 { \r
430 if(ip->v6)\r
431 {\r
c2237b8a 432 bytes6 += ip->upload + ip->direct;\r
433 pkts6 += ip->pktsdown + ip->pktsup;\r
b1a5c883 434 count6++;\r
ca6f7e80 435 }\r
436 else\r
437 {\r
c2237b8a 438 bytes4 += ip->upload + ip->direct;\r
439 pkts4 += ip->pktsdown + ip->pktsup;\r
b1a5c883 440 count4++;\r
ca6f7e80 441 }\r
442 }\r
443\r
c2237b8a 444 perc6=(double)(bytes6)/(bytes4+bytes6)*100;\r
ca6f7e80 445 fputs("<p><table class=\"decorated last\"><caption>IP protocols usage</caption>\n",f);\r
62b118c2 446 fprintf(f, "%s<td>Total %d IPv4 addreses</td><td style=\"text-align: right\">%Lu MB (%.2f %%)</td><td style=\"text-align: right\">%Lu packets (%.2f %%)</td></tr>\n",\r
c2237b8a 447 tr_odd_even(), count4, bytes4, (double)(bytes4)/(bytes4+bytes6)*100, pkts4, (float)(100*pkts4)/(pkts4+pkts6));\r
62b118c2 448 fprintf(f, "%s<td>Total %d IPv6 /64 ranges</td><td style=\"text-align: right\">%Lu MB (%.2f %%)</td><td style=\"text-align: right\">%Lu packets (%.2f %%)</td></tr>\n",\r
b1a5c883 449 tr_odd_even(), count6, bytes6, perc6, pkts6, (float)(100*pkts6)/(pkts4+pkts6));\r
450 fputs("</table></p>\n", f);\r
ca6f7e80 451 }\r
452\r
9a56ab25 453 row_odd_even = 0;\r
454 if(active_classes>10)\r
455 {\r
456 int top20_count=0,top20_perc1=0;\r
457 long long top20_perc2=0;\r
458 unsigned long long top20_sum=0l;\r
459 \r
460 fputs("<a name=\"erp\"></a><p><table class=\"decorated last\"><caption>Enterprise Resource Planning (ERP)</caption>\n",f);\r
461 fputs("<thead><tr>\n\\r
462<th>Analytic category</th>\n\\r
463<th colspan=\"2\" style=\"text-align: center\">Active Classes</th>\n\\r
464<th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\\r
465</tr></thead><tbody>\n",f);\r
466\r
b1a5c883 467 if_exists(sum,sums,sum->l >= total_traffic/4)\r
9a56ab25 468 {\r
469 fprintf(f,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());\r
470 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
471<td style=\"text-align: right\">%d %%</td>\n\\r
472<td style=\"text-align: right\">%Lu MB</td>\n\\r
473<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
474 sum->i, (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r
475 }\r
476 \r
b1a5c883 477 if_exists(sum,sums,sum->i == 10)\r
9a56ab25 478 {\r
479 fprintf(f,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());\r
480 fprintf(f,"<td style=\"text-align: right\"><strong>10</strong></td>\n\\r
481<td style=\"text-align: right\">%d %%</td>\n\\r
482<td style=\"text-align: right\">%Lu MB</td>\n\\r
483<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
484 (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r
485 }\r
486\r
b1a5c883 487 if_exists(sum,sums,sum->l >= total_traffic/2)\r
9a56ab25 488 {\r
489 fprintf(f,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());\r
490 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
491<td style=\"text-align: right\">%d %%</td>\n\\r
492<td style=\"text-align: right\">%Lu MB</td>\n\\r
493<td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",\r
494 sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
495 }\r
496\r
b1a5c883 497 if_exists(sum,sums,sum->l >= 4*total_traffic/5)\r
9a56ab25 498 {\r
499 fprintf(f,"%s<td>Top 80%% of traffic</td>\n", tr_odd_even());\r
500 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
501<td style=\"text-align: right\">%d %%</td>\n\\r
502<td style=\"text-align: right\">%Lu MB</td>\n\\r
503<td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",\r
504 sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
505 }\r
506\r
b1a5c883 507 if_exists(sum,sums,sum->i >= (active_classes+1)/5)\r
9a56ab25 508 {\r
509 fprintf(f,"%s<td>Top 20%% downloaders</td>\n", tr_odd_even());\r
510 top20_count=sum->i;\r
511 top20_perc1=(100*sum->i+50)/active_classes;\r
512 top20_sum=sum->l;\r
513 top20_perc2=(100*sum->l+50)/total_traffic;\r
514 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
515<td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r
516<td style=\"text-align: right\">%Lu MB</td>\n\\r
517<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
518 top20_count,top20_perc1,top20_sum,top20_perc2);\r
519 }\r
520\r
b1a5c883 521 if_exists(sum,sums,sum->i >= (active_classes+1)/4)\r
9a56ab25 522 {\r
523 fprintf(f,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());\r
524 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
525<td style=\"text-align: right\">%d %%</td>\n\\r
526<td style=\"text-align: right\">%Lu MB</td>\n\\r
527<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
528 sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
529 }\r
530\r
531 if_exists(sum,sums,sum->i>=(active_classes+1)/2)\r
532 {\r
533 fprintf(f,"%s<td>Top 50%% downloaders</td>\n", tr_odd_even());\r
534 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
535<td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r
536<td style=\"text-align: right\">%Lu MB</td>\n\\r
537<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
538 sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
539 }\r
540\r
b1a5c883 541 if_exists(sum,sums,sum->i >= 4*(active_classes+1)/5)\r
9a56ab25 542 {\r
543 fprintf(f,"%s<td>Top 80%% downloaders</td>\n", tr_odd_even());\r
544 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
545<td style=\"text-align: right\">%d %%</td>\n\\r
546<td style=\"text-align: right\">%Lu MB</td>\n\\r
547<td style=\"text-align: right\">%Ld %%</td></tr></tbody>\n",\r
548 sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
549 }\r
550\r
551 fprintf(f,"<thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url);\r
552 fprintf(f,"<th style=\"text-align: right\">%d</th>\n\\r
553<th style=\"text-align: right\">100 %%</th>\n\\r
554<th style=\"text-align: right\">%Lu MB</th>\n\\r
555<th style=\"text-align: right\">100 %%</th></tr>\n",active_classes,total_traffic);\r
b1a5c883 556 fputs("</thead></table></p>\n", f);\r
9a56ab25 557\r
558 /* write basic ERP data to log directory */\r
559 if(!just_preview)\r
560 {\r
561 FILE *iplog;\r
562 sprintf(str,"%s/ERP.log",log_dir);\r
563 iplog=fopen(str,"a");\r
564 if(iplog)\r
565 {\r
62b118c2 566 fprintf(iplog, "%ld\t%d\t%d %%\t%Lu M\t%Ld %%\tACTIVE %d\tTRAFFIC %Lu M\tCLASSES %d\tFUP-LIMIT %d\tLOW-PRIO %d\tIPv6 %Lu M\t%.2f %%\t%s",\r
b1a5c883 567 time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, \r
568 active_classes, total_traffic, i, limit_count, prio_count,\r
569 bytes6, perc6, d); /* d = date*/\r
9a56ab25 570 fclose(iplog);\r
571 }\r
572 else\r
573 {\r
574 perror(str);\r
575 }\r
576 }\r
577 }\r
578\r
579 fprintf(f, stats_html_signature, version);\r
580 fclose(f);\r
581 }\r
582}
This page took 0.686326 seconds and 4 git commands to generate.