1 #include "cll1-0.6.2.h"
5 extern int row_odd_even
;
6 extern int use_jquery_popups
;
7 extern struct IP
*ips
, *ip
, *sharedip
;
8 extern struct Group
*groups
, *group
;
9 extern struct Keyword
*keyword
, *defaultkeyword
, *keywords
;
10 extern const int highest_priority
;
11 extern const char *version
;
12 extern const char *stats_html_signature
;
13 extern char *jquery_url
;
14 extern int keywordcount
;
15 extern long long int line
;
20 extern int found_lmsid
;
23 extern char *ip6prefix
;
25 const char *tr_odd_even(void);
26 /* implemented in prometheus.c, shared with parselogs.c */
28 void append_log(struct IP
*self
) /*using global variables*/
33 date(d
); /* this is typical cll1.h macro - prints current date */
35 sprintf(str
, "%s/%s.log", log_dir
, self
->name
);
37 /*-----------------------------------------------------------------*/
38 printf("Writing traffic log %s ...\n", str
);
39 /*-----------------------------------------------------------------*/
43 fprintf(f
, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",
44 time(NULL
), self
->name
, self
->traffic
, self
->direct
, self
->proxy
,
45 self
->upload
, self
->min
, self
->max
, self
->desired
, self
->lmsid
, d
); /* d = date*/
54 void write_htmlandlogs(char *html
, char *d
, int total
, int just_preview
)
58 FILE *f
=fopen(html
, "w");
68 fprintf(f
,"<script type=\"text/javascript\" src=\"%s\"></script>\n", jquery_url
);
70 fputs("<table class=\"decorated last\">\n\
71 <caption>Bandwidth classes</caption>\n\
73 <th style=\"text-align: right\">#</th>\n\
74 <th style=\"text-align: right\">group</th>\n\
75 <th style=\"text-align: right\">IPs</th>\n\
76 <th style=\"text-align: right\">requested</th>\n",f
);
77 fprintf(f
,"<th colspan=\"%d\">data limits</th>\n", keywordcount
);
78 fputs("</tr></thead><tbody>\n",f
);
81 for_each(group
, groups
)
84 printf("%d kb/s group: %d bandwidth requested: %d kb/s\n",group
->min
,group
->count
,group
->desired
);
86 fprintf(f
, "%s<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d kb/s</td>",
87 tr_odd_even(), count
, group
->min
);
88 fprintf(f
, "<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d kb/s</td>",
89 group
->count
, group
->desired
);
91 for_each(keyword
, keywords
) if(keyword
->ip_count
)
93 fprintf(f
, "<td style=\"text-align: right\"><span style=\"color:#%s\">%d MB</span></td>",
94 keyword
->html_color
, group
->min
*keyword
->data_limit
);
97 total
+= group
->count
;
101 printf("Total groups: %d Total bandwidth requested: %d kb/s\nAGGREGATION: 1/%d\n",
104 fprintf(f
,"</tr></tbody>\n\
106 <th colspan=\"2\" style=\"text-align: left\">Line %Ld kb/s</td>",line
);
107 fprintf(f
,"<th style=\"text-align: right\">%d</td><th style=\"text-align: right\">%d kb/s</td>",total
,i
);
109 for_each(keyword
, keywords
) if(keyword
->ip_count
)
111 fprintf(f
,"<th style=\"text-align: right\">%d IPs</th>",keyword
->ip_count
);
113 fprintf(f
,"</tr><tr><th colspan=\"4\">Aggregation 1/%d</th>\n", (int)(0.5+i
/line
));
114 fprintf(f
,"<th colspan=\"%d\">%d traffic classes</th></tr>\n", keywordcount
, total
);
116 fputs("</thead></table>\n",f
);
126 unsigned long long total_traffic
=0, total_direct
=0, total_proxy
=0, total_upload
=0, tmp_sum
= 0;
127 int active_classes
= 0;
129 struct Sum
{unsigned long long l
; int i
; list(Sum
);} *sum
,*sums
= NULL
;
130 int limit_count
= 0, prio_count
= 0;
131 int popup_button
= 0;
132 /* IPv6 vs. IPv4 stats */
133 unsigned long long pkts4
=0, pkts6
= 0, bytes4
= 0, bytes6
= 0;
134 int count4
= 0, count6
= 0;
142 fprintf(f
,"<p><table class=\"decorated last\">\n<caption>%s",title
);
143 fprintf(f
," (%s)</caption>\n", d
);
144 fputs("<thead><tr>\n<th colspan=\"3\"> </th>\n",f
);
145 fputs("<th style=\"text-align: right\">credit</th>\n\
146 <th style=\"text-align: right\">FUP</th>\n\
147 <th style=\"text-align: right\">total</th>\n\
148 <th style=\"text-align: right\">down</th>\n",f
);
151 fputs("<th style=\"text-align: right\">proxy</th>\n",f
);
153 fputs("<th style=\"text-align: right\">up</th>\n\
154 <th style=\"text-align: right\">min</th>\n\
155 <th style=\"text-align: right\">max</th>\n\
156 <th style=\"text-align: right\">limit</th>\n\
159 <th style=\"text-align: right\">#</th>\n\
160 <th>hostname [+sharing]</th>\n\
161 <th style=\"text-align: right\">LMS</th>\n\
162 <th style=\"text-align: right\">MB</th>\n\
163 <th style=\"text-align: right\">MB</th>\n\
164 <th style=\"text-align: right\">MB</th>\n\
165 <th style=\"text-align: right\">MB</th>\n\
166 <th style=\"text-align: right\">MB</th>\n\
167 <th style=\"text-align: right\">kb/s</th>\n\
168 <th style=\"text-align: right\">kb/s</th>\n\
169 <th style=\"text-align: right\">kb/s</th>\n\
171 </tr></thead><tbody>\n",f
);
174 for_each(ip
,ips
) if(!use_jquery_popups
|| !ip
->sharing
)
179 if(ip
->max
< ip
->desired
)
181 f1
= "<span style=\"color:red\">";
185 else if(ip
->prio
> highest_priority
+1)
187 f1
= "<span style=\"color:brown\">";
193 printf("%03d. %-22s %10Lu (%d/%d)\n",i
,ip
->name
, ip
->traffic
, ip
->min
, ip
->max
);
195 /* hostnames -------------------------------------- */
196 fprintf(f
,"%s<td style=\"text-align: right\"><a name=\"%s\"></a>%d</td><td><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n",
197 tr_odd_even(), ip
->name
, i
, log_url
, ip
->name
, ip
->name
);
199 if(use_jquery_popups
)
201 fprintf(f
, "<span id=\"sharing_%d\" style=\"display:none\">",i
);
204 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
206 fprintf(f
, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n",
207 log_url
, sharedip
->name
, sharedip
->name
);
211 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
213 fprintf(f
, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s/64</a>\n",
214 log_url
, sharedip
->addr
, sharedip
->addr
);
218 fputs("</span>\n",f
);
221 fprintf(f
, "<span>[<a class=\"blue\" href=\"#\" onClick=\"$(this).parent().hide();$(\'#sharing_%d\').show();$(\'#download_%d\').show();$(\'#upload_%d\').show();return(false);\" style=\"cursor: pointer;\">+%d</a>]</span>",
222 i
, i
, i
, popup_button
);
226 /* ----------------------------------------------- */
230 fputs("<td style=\"text-align: right\">",f
);
233 fprintf(f
,"<a class=\"blue\" target=\"_blank\" href=\"%s%d\">%04d</a>\n", lms_url
, ip
->lmsid
, ip
->lmsid
);
235 else if(ip
->lmsid
== 0)
241 fprintf(f
,"<td style=\"text-align: right\">%Lu</td>\n", ip
->credit
);
242 fprintf(f
,"<td style=\"text-align: right\"><span style=\"color:#%s\">%Lu</span></td>",
243 ip
->keyword
->html_color
, ip
->realquota
);
244 fprintf(f
,"<td style=\"text-align: right\">%s%Lu%s", f1
, ip
->traffic
, f2
);
246 /* download --------------------------------------- */
247 fprintf(f
,"</td><td style=\"text-align: right\">%Lu", ip
->direct
);
248 if(use_jquery_popups
)
250 fprintf(f
,"<span id=\"download_%d\" style=\"display:none\">", i
);
251 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
253 fprintf(f
,"<br />%Lu", sharedip
->direct
);
255 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
257 fprintf(f
,"<br />%Lu", sharedip
->direct
);
259 fputs("</span>\n",f
);
262 /* ----------------------------------------------- */
266 fprintf(f
,"<td style=\"text-align: right\">%Lu</td>\n", ip
->proxy
);
268 /* upload ---------------------------------------- */
269 fprintf(f
,"<td style=\"text-align: right\">%Lu", ip
->upload
);
270 if(use_jquery_popups
)
272 fprintf(f
,"<span id=\"upload_%d\" style=\"display:none\">", i
);
273 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
275 fprintf(f
,"<br />%Lu", sharedip
->upload
);
277 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
279 fprintf(f
,"<br />%Lu", sharedip
->upload
);
281 fputs("</span>\n",f
);
284 /* ----------------------------------------------- */
286 fprintf(f
, "<td style=\"text-align: right\">%d</td>\n\
287 <td style=\"text-align: right\">%d</td>\n\
288 <td style=\"text-align: right\">%s%d%s</td>\n\
289 <td>%s%d%s</td></tr>\n",
290 ip
->min
, ip
->desired
,
294 total_traffic
+=ip
->traffic
;
295 total_direct
+=ip
->direct
;
296 total_proxy
+=ip
->proxy
;
297 total_upload
+=ip
->upload
;
301 tmp_sum
+=ip
->traffic
;
304 sum
->i
=active_classes
;
305 insert(sum
,sums
,order_by
,i
);
311 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
))
313 append_log(sharedip
);
317 fprintf(f
,"</tbody><thead><tr>\n\
318 <th colspan=\"%d\" style=\"text-align: left\">%d CLASSES</th>", colspan
-7, i
);
319 fprintf(f
, "<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%Lu</th>\n",
320 total_traffic
, total_direct
);
323 fprintf(f
," <th style=\"text-align: right\">%Lu</th>\n", total_proxy
);
325 fprintf(f
, "<th style=\"text-align: right\">%Lu</th>", total_upload
);
326 fprintf(f
, "<th colspan=\"4\"><span style=\"color:red\">LIMIT %dx</span> <span style=\"color:brown\">LOW-PRIO %dx</span></th></tr>\n</thead></table>\n",
327 limit_count
, prio_count
);
335 bytes6
+= ip
->upload
+ ip
->direct
;
336 pkts6
+= ip
->pktsdown
+ ip
->pktsup
;
341 bytes4
+= ip
->upload
+ ip
->direct
;
342 pkts4
+= ip
->pktsdown
+ ip
->pktsup
;
347 perc6
=(double)(bytes6
)/(bytes4
+bytes6
)*100;
348 fputs("<p><table class=\"decorated last\"><caption>IP protocols usage</caption>\n",f
);
349 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",
350 tr_odd_even(), count4
, bytes4
, (double)(bytes4
)/(bytes4
+bytes6
)*100, pkts4
, (float)(100*pkts4
)/(pkts4
+pkts6
));
351 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",
352 tr_odd_even(), count6
, bytes6
, perc6
, pkts6
, (float)(100*pkts6
)/(pkts4
+pkts6
));
353 fputs("</table></p>\n", f
);
357 if(active_classes
>10)
359 int top20_count
=0,top20_perc1
=0;
360 long long top20_perc2
=0;
361 unsigned long long top20_sum
=0l;
363 fputs("<a name=\"erp\"></a><p><table class=\"decorated last\"><caption>Enterprise Resource Planning (ERP)</caption>\n",f
);
364 fputs("<thead><tr>\n\
365 <th>Analytic category</th>\n\
366 <th colspan=\"2\" style=\"text-align: center\">Active Classes</th>\n\
367 <th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\
368 </tr></thead><tbody>\n",f
);
370 if_exists(sum
,sums
,sum
->l
>= total_traffic
/4)
372 fprintf(f
,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());
373 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
374 <td style=\"text-align: right\">%d %%</td>\n\
375 <td style=\"text-align: right\">%Lu MB</td>\n\
376 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
377 sum
->i
, (100*sum
->i
+50)/active_classes
, sum
->l
, (100*sum
->l
+50)/total_traffic
);
380 if_exists(sum
,sums
,sum
->i
== 10)
382 fprintf(f
,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());
383 fprintf(f
,"<td style=\"text-align: right\"><strong>10</strong></td>\n\
384 <td style=\"text-align: right\">%d %%</td>\n\
385 <td style=\"text-align: right\">%Lu MB</td>\n\
386 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
387 (100*sum
->i
+50)/active_classes
, sum
->l
, (100*sum
->l
+50)/total_traffic
);
390 if_exists(sum
,sums
,sum
->l
>= total_traffic
/2)
392 fprintf(f
,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());
393 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
394 <td style=\"text-align: right\">%d %%</td>\n\
395 <td style=\"text-align: right\">%Lu MB</td>\n\
396 <td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",
397 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
400 if_exists(sum
,sums
,sum
->l
>= 4*total_traffic
/5)
402 fprintf(f
,"%s<td>Top 80%% of traffic</td>\n", tr_odd_even());
403 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
404 <td style=\"text-align: right\">%d %%</td>\n\
405 <td style=\"text-align: right\">%Lu MB</td>\n\
406 <td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",
407 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
410 if_exists(sum
,sums
,sum
->i
>= (active_classes
+1)/5)
412 fprintf(f
,"%s<td>Top 20%% downloaders</td>\n", tr_odd_even());
414 top20_perc1
=(100*sum
->i
+50)/active_classes
;
416 top20_perc2
=(100*sum
->l
+50)/total_traffic
;
417 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
418 <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\
419 <td style=\"text-align: right\">%Lu MB</td>\n\
420 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
421 top20_count
,top20_perc1
,top20_sum
,top20_perc2
);
424 if_exists(sum
,sums
,sum
->i
>= (active_classes
+1)/4)
426 fprintf(f
,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());
427 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
428 <td style=\"text-align: right\">%d %%</td>\n\
429 <td style=\"text-align: right\">%Lu MB</td>\n\
430 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
431 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
434 if_exists(sum
,sums
,sum
->i
>=(active_classes
+1)/2)
436 fprintf(f
,"%s<td>Top 50%% downloaders</td>\n", tr_odd_even());
437 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
438 <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\
439 <td style=\"text-align: right\">%Lu MB</td>\n\
440 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
441 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
444 if_exists(sum
,sums
,sum
->i
>= 4*(active_classes
+1)/5)
446 fprintf(f
,"%s<td>Top 80%% downloaders</td>\n", tr_odd_even());
447 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
448 <td style=\"text-align: right\">%d %%</td>\n\
449 <td style=\"text-align: right\">%Lu MB</td>\n\
450 <td style=\"text-align: right\">%Ld %%</td></tr></tbody>\n",
451 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
454 fprintf(f
,"<thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url
);
455 fprintf(f
,"<th style=\"text-align: right\">%d</th>\n\
456 <th style=\"text-align: right\">100 %%</th>\n\
457 <th style=\"text-align: right\">%Lu MB</th>\n\
458 <th style=\"text-align: right\">100 %%</th></tr>\n",active_classes
,total_traffic
);
459 fputs("</thead></table></p>\n", f
);
461 /* write basic ERP data to log directory */
465 sprintf(str
,"%s/ERP.log",log_dir
);
466 iplog
=fopen(str
,"a");
469 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",
470 time(NULL
), top20_count
, top20_perc1
, top20_sum
, top20_perc2
,
471 active_classes
, total_traffic
, i
, limit_count
, prio_count
,
472 bytes6
, perc6
, d
); /* d = date*/
482 fprintf(f
, stats_html_signature
, version
);
This page took 0.705043 seconds and 4 git commands to generate.