f16580adbb597adf97499255bc9280316255ce89
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;
138 fprintf(f
,"<p><table class=\"decorated last\">\n<caption>%s",title
);
139 fprintf(f
," (%s)</caption>\n", d
);
140 fputs("<thead><tr>\n<th colspan=\"3\"> </th>\n",f
);
141 fputs("<th style=\"text-align: right\">credit</th>\n\
142 <th style=\"text-align: right\">FUP</th>\n\
143 <th style=\"text-align: right\">total</th>\n\
144 <th style=\"text-align: right\">down</th>\n",f
);
147 fputs("<th style=\"text-align: right\">proxy</th>\n",f
);
149 fputs("<th style=\"text-align: right\">up</th>\n\
150 <th style=\"text-align: right\">min</th>\n\
151 <th style=\"text-align: right\">max</th>\n\
152 <th style=\"text-align: right\">limit</th>\n\
155 <th style=\"text-align: right\">#</th>\n\
156 <th>hostname [+sharing]</th>\n\
157 <th style=\"text-align: right\">LMS</th>\n\
158 <th style=\"text-align: right\">MB</th>\n\
159 <th style=\"text-align: right\">MB</th>\n\
160 <th style=\"text-align: right\">MB</th>\n\
161 <th style=\"text-align: right\">MB</th>\n\
162 <th style=\"text-align: right\">MB</th>\n\
163 <th style=\"text-align: right\">kb/s</th>\n\
164 <th style=\"text-align: right\">kb/s</th>\n\
165 <th style=\"text-align: right\">kb/s</th>\n\
167 </tr></thead><tbody>\n",f
);
170 for_each(ip
,ips
) if(!use_jquery_popups
|| !ip
->sharing
)
175 if(ip
->max
< ip
->desired
)
177 f1
= "<span style=\"color:red\">";
181 else if(ip
->prio
> highest_priority
+1)
183 f1
= "<span style=\"color:brown\">";
189 printf("%03d. %-22s %10Lu (%d/%d)\n",i
,ip
->name
, ip
->traffic
, ip
->min
, ip
->max
);
191 /* hostnames -------------------------------------- */
192 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",
193 tr_odd_even(), ip
->name
, i
, log_url
, ip
->name
, ip
->name
);
195 if(use_jquery_popups
)
197 fprintf(f
, "<span id=\"sharing_%d\" style=\"display:none\">",i
);
200 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
202 fprintf(f
, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n",
203 log_url
, sharedip
->name
, sharedip
->name
);
207 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
209 fprintf(f
, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s/64</a>\n",
210 log_url
, sharedip
->addr
, sharedip
->addr
);
214 fputs("</span>\n",f
);
217 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>",
218 i
, i
, i
, popup_button
);
222 /* ----------------------------------------------- */
226 fputs("<td style=\"text-align: right\">",f
);
229 fprintf(f
,"<a class=\"blue\" target=\"_blank\" href=\"%s%d\">%04d</a>\n", lms_url
, ip
->lmsid
, ip
->lmsid
);
231 else if(ip
->lmsid
== 0)
237 fprintf(f
,"<td style=\"text-align: right\">%Lu</td>\n", ip
->credit
);
238 fprintf(f
,"<td style=\"text-align: right\"><span style=\"color:#%s\">%Lu</span></td>",
239 ip
->keyword
->html_color
, ip
->realquota
);
240 fprintf(f
,"<td style=\"text-align: right\">%s%Lu%s", f1
, ip
->traffic
, f2
);
242 /* download --------------------------------------- */
243 fprintf(f
,"</td><td style=\"text-align: right\">%Lu", ip
->direct
);
244 if(use_jquery_popups
)
246 fprintf(f
,"<span id=\"download_%d\" style=\"display:none\">", i
);
247 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
249 fprintf(f
,"<br />%Lu", sharedip
->direct
);
251 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
253 fprintf(f
,"<br />%Lu", sharedip
->direct
);
255 fputs("</span>\n",f
);
258 /* ----------------------------------------------- */
262 fprintf(f
,"<td style=\"text-align: right\">%Lu</td>\n", ip
->proxy
);
264 /* upload ---------------------------------------- */
265 fprintf(f
,"<td style=\"text-align: right\">%Lu", ip
->upload
);
266 if(use_jquery_popups
)
268 fprintf(f
,"<span id=\"upload_%d\" style=\"display:none\">", i
);
269 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
271 fprintf(f
,"<br />%Lu", sharedip
->upload
);
273 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
275 fprintf(f
,"<br />%Lu", sharedip
->upload
);
277 fputs("</span>\n",f
);
280 /* ----------------------------------------------- */
282 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
283 <td style=\"text-align: right\">%d</td>\n\
284 <td style=\"text-align: right\">%s%d%s</td>\n\
285 <td>%s%d%s</td></tr>\n",
286 ip
->min
, ip
->desired
,
290 total_traffic
+=ip
->traffic
;
291 total_direct
+=ip
->direct
;
292 total_proxy
+=ip
->proxy
;
293 total_upload
+=ip
->upload
;
297 tmp_sum
+=ip
->traffic
;
300 sum
->i
=active_classes
;
301 insert(sum
,sums
,order_by
,i
);
307 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
))
309 append_log(sharedip
);
313 fprintf(f
,"</tbody><thead><tr>\n\
314 <th colspan=\"%d\" style=\"text-align: left\">%d CLASSES</th>", colspan
-7, i
);
315 fprintf(f
,"<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%Lu</th>\n", total_traffic
, total_direct
);
318 fprintf(f
,"<th style=\"text-align: right\">%Lu</th>\n", total_proxy
);
320 fprintf(f
,"<th style=\"text-align: right\">%Lu</th>", total_upload
);
321 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",limit_count
,prio_count
);
325 unsigned long long pkts4
=0, pkts6
= 0, bytes4
= 0, bytes6
= 0;
330 bytes6
+= ip
->traffic
;
331 pkts6
+= ip
->pktsdown
+ip
->pktsup
;
335 bytes4
+= ip
->traffic
;
336 pkts4
+= ip
->pktsdown
+ip
->pktsup
;
340 fputs("<p><table class=\"decorated last\"><caption>IP protocols usage</caption>\n",f
);
341 fprintf(f
, "%s<td>Total IPv4</td><td style=\"text-align: right\">%Lu MB (%.2f %%)</td><td style=\"text-align: right\">%Lu packets (%d %%)</td></tr>\n",
342 tr_odd_even(), bytes4
, (float)(100*bytes4
)/(bytes4
+bytes6
), pkts4
, (float)(100*pkts4
)/(pkts4
+pkts6
));
343 fprintf(f
, "%s<td>Total IPv6</td><td style=\"text-align: right\">%Lu MB (%.2f %%)</td><td style=\"text-align: right\">%Lu packets (%d %%)</td></tr>\n",
344 tr_odd_even(), bytes6
, (float)(100*bytes6
)/(bytes4
+bytes6
), pkts6
, (float)(100*pkts6
)/(pkts4
+pkts6
));
345 fputs("</table>\n", f
);
349 if(active_classes
>10)
351 int top20_count
=0,top20_perc1
=0;
352 long long top20_perc2
=0;
353 unsigned long long top20_sum
=0l;
355 fputs("<a name=\"erp\"></a><p><table class=\"decorated last\"><caption>Enterprise Resource Planning (ERP)</caption>\n",f
);
356 fputs("<thead><tr>\n\
357 <th>Analytic category</th>\n\
358 <th colspan=\"2\" style=\"text-align: center\">Active Classes</th>\n\
359 <th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\
360 </tr></thead><tbody>\n",f
);
362 if_exists(sum
,sums
,sum
->l
>=total_traffic
/4)
364 fprintf(f
,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());
365 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
366 <td style=\"text-align: right\">%d %%</td>\n\
367 <td style=\"text-align: right\">%Lu MB</td>\n\
368 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
369 sum
->i
, (100*sum
->i
+50)/active_classes
, sum
->l
, (100*sum
->l
+50)/total_traffic
);
372 if_exists(sum
,sums
,sum
->i
==10)
374 fprintf(f
,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());
375 fprintf(f
,"<td style=\"text-align: right\"><strong>10</strong></td>\n\
376 <td style=\"text-align: right\">%d %%</td>\n\
377 <td style=\"text-align: right\">%Lu MB</td>\n\
378 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
379 (100*sum
->i
+50)/active_classes
, sum
->l
, (100*sum
->l
+50)/total_traffic
);
382 if_exists(sum
,sums
,sum
->l
>=total_traffic
/2)
384 fprintf(f
,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());
385 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
386 <td style=\"text-align: right\">%d %%</td>\n\
387 <td style=\"text-align: right\">%Lu MB</td>\n\
388 <td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",
389 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
392 if_exists(sum
,sums
,sum
->l
>=4*total_traffic
/5)
394 fprintf(f
,"%s<td>Top 80%% of traffic</td>\n", tr_odd_even());
395 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
396 <td style=\"text-align: right\">%d %%</td>\n\
397 <td style=\"text-align: right\">%Lu MB</td>\n\
398 <td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",
399 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
402 if_exists(sum
,sums
,sum
->i
>=(active_classes
+1)/5)
404 fprintf(f
,"%s<td>Top 20%% downloaders</td>\n", tr_odd_even());
406 top20_perc1
=(100*sum
->i
+50)/active_classes
;
408 top20_perc2
=(100*sum
->l
+50)/total_traffic
;
409 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
410 <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\
411 <td style=\"text-align: right\">%Lu MB</td>\n\
412 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
413 top20_count
,top20_perc1
,top20_sum
,top20_perc2
);
416 if_exists(sum
,sums
,sum
->i
>=(active_classes
+1)/4)
418 fprintf(f
,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());
419 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
420 <td style=\"text-align: right\">%d %%</td>\n\
421 <td style=\"text-align: right\">%Lu MB</td>\n\
422 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
423 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
426 if_exists(sum
,sums
,sum
->i
>=(active_classes
+1)/2)
428 fprintf(f
,"%s<td>Top 50%% downloaders</td>\n", tr_odd_even());
429 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
430 <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\
431 <td style=\"text-align: right\">%Lu MB</td>\n\
432 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
433 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
436 if_exists(sum
,sums
,sum
->i
>=4*(active_classes
+1)/5)
438 fprintf(f
,"%s<td>Top 80%% downloaders</td>\n", tr_odd_even());
439 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
440 <td style=\"text-align: right\">%d %%</td>\n\
441 <td style=\"text-align: right\">%Lu MB</td>\n\
442 <td style=\"text-align: right\">%Ld %%</td></tr></tbody>\n",
443 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
446 fprintf(f
,"<thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url
);
447 fprintf(f
,"<th style=\"text-align: right\">%d</th>\n\
448 <th style=\"text-align: right\">100 %%</th>\n\
449 <th style=\"text-align: right\">%Lu MB</th>\n\
450 <th style=\"text-align: right\">100 %%</th></tr>\n",active_classes
,total_traffic
);
451 fputs("</thead></table>\n", f
);
453 /* write basic ERP data to log directory */
457 sprintf(str
,"%s/ERP.log",log_dir
);
458 iplog
=fopen(str
,"a");
461 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\t%s",
462 time(NULL
), top20_count
, top20_perc1
, top20_sum
, top20_perc2
,
463 active_classes
, total_traffic
, i
, limit_count
, prio_count
, d
); /* d = date*/
473 fprintf(f
, stats_html_signature
, version
);
This page took 0.619368 seconds and 4 git commands to generate.