improved logging
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Thu, 24 Jan 2013 15:19:47 +0000 (15:19 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Thu, 24 Jan 2013 15:19:47 +0000 (15:19 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@218 251d49ef-1d17-4917-a970-b30cf55b089b

htmlandlogs.c
parsehosts.c
prometheus.c

index f16580a..0443c7b 100644 (file)
@@ -123,12 +123,16 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
  i=0;\r
  if(f > 0)\r
  {\r
-  unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum=0;\r
-  int active_classes=0;\r
-  int colspan=12;\r
-  struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums=NULL;\r
-  int limit_count=0, prio_count=0;\r
-  int popup_button=0;\r
+  unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum = 0;\r
+  int active_classes = 0;\r
+  int colspan = 12;\r
+  struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums = NULL;\r
+  int limit_count = 0, prio_count = 0;\r
+  int popup_button = 0;\r
+  /* IPv6 vs. IPv4 stats */\r
+  unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0;\r
+  int count4 = 0, count6 = 0;\r
+  double perc6;\r
 \r
   if(qos_proxy)\r
   {\r
@@ -279,13 +283,13 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
    fputs("</td>\n",f);\r
    /* ----------------------------------------------- */\r
 \r
-   fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
+   fprintf(f, "<td style=\"text-align: right\">%d</td>\n\\r
 <td style=\"text-align: right\">%d</td>\n\\r
 <td style=\"text-align: right\">%s%d%s</td>\n\\r
 <td>%s%d%s</td></tr>\n",\r
-             ip->min, ip->desired, \r
-             f1, ip->max, f2, \r
-             f1, ip->prio, f2);\r
+              ip->min, ip->desired, \r
+              f1, ip->max, f2, \r
+              f1, ip->prio, f2);\r
 \r
    total_traffic+=ip->traffic;\r
    total_direct+=ip->direct;\r
@@ -312,37 +316,42 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
   }\r
   fprintf(f,"</tbody><thead><tr>\n\\r
 <th colspan=\"%d\" style=\"text-align: left\">%d CLASSES</th>", colspan-7, i);\r
-  fprintf(f,"<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%Lu</th>\n", total_traffic, total_direct);\r
+  fprintf(f, "<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%Lu</th>\n", \r
+             total_traffic, total_direct);\r
   if(qos_proxy)\r
   {\r
-   fprintf(f,"<th style=\"text-align: right\">%Lu</th>\n", total_proxy);\r
+   fprintf(f," <th style=\"text-align: right\">%Lu</th>\n", total_proxy);\r
   }\r
-  fprintf(f,"<th style=\"text-align: right\">%Lu</th>", total_upload);\r
-  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);\r
+  fprintf(f, "<th style=\"text-align: right\">%Lu</th>", total_upload);\r
+  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",\r
+             limit_count, prio_count);\r
 \r
   if(ip6prefix)\r
   {\r
-   unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0;\r
\r
    for_each(ip, ips)\r
    { \r
     if(ip->v6)\r
     {\r
      bytes6 += ip->traffic;\r
      pkts6 += ip->pktsdown+ip->pktsup;\r
+     count6++;\r
     }\r
     else\r
     {\r
      bytes4 += ip->traffic;\r
      pkts4 += ip->pktsdown+ip->pktsup;\r
+     count4++;\r
     }\r
    }\r
+   perc6=(double)(100*bytes6)/(bytes4+bytes6);\r
 \r
    fputs("<p><table class=\"decorated last\"><caption>IP protocols usage</caption>\n",f);\r
-   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",\r
-              tr_odd_even(), bytes4, (float)(100*bytes4)/(bytes4+bytes6), pkts4, (float)(100*pkts4)/(pkts4+pkts6));\r
-   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",\r
-              tr_odd_even(), bytes6, (float)(100*bytes6)/(bytes4+bytes6), pkts6, (float)(100*pkts6)/(pkts4+pkts6));\r
-   fputs("</table>\n", f);\r
+   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
+              tr_odd_even(), count4, bytes4, (double)(100*bytes4)/(bytes4+bytes6), pkts4, (float)(100*pkts4)/(pkts4+pkts6));\r
+   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
+              tr_odd_even(), count6, bytes6, perc6, pkts6, (float)(100*pkts6)/(pkts4+pkts6));\r
+   fputs("</table></p>\n", f);\r
   }\r
 \r
   row_odd_even = 0;\r
@@ -359,7 +368,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
 <th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\\r
 </tr></thead><tbody>\n",f);\r
 \r
-   if_exists(sum,sums,sum->l>=total_traffic/4)\r
+   if_exists(sum,sums,sum->l >= total_traffic/4)\r
    {\r
     fprintf(f,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
@@ -369,7 +378,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
               sum->i, (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r
    }\r
    \r
-   if_exists(sum,sums,sum->i==10)\r
+   if_exists(sum,sums,sum->i == 10)\r
    {\r
     fprintf(f,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\"><strong>10</strong></td>\n\\r
@@ -379,7 +388,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
               (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r
    }\r
 \r
-   if_exists(sum,sums,sum->l>=total_traffic/2)\r
+   if_exists(sum,sums,sum->l >= total_traffic/2)\r
    {\r
     fprintf(f,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
@@ -389,7 +398,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
               sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
    }\r
 \r
-   if_exists(sum,sums,sum->l>=4*total_traffic/5)\r
+   if_exists(sum,sums,sum->l >= 4*total_traffic/5)\r
    {\r
     fprintf(f,"%s<td>Top 80%% of traffic</td>\n", tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
@@ -399,7 +408,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
               sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
    }\r
 \r
-   if_exists(sum,sums,sum->i>=(active_classes+1)/5)\r
+   if_exists(sum,sums,sum->i >= (active_classes+1)/5)\r
    {\r
     fprintf(f,"%s<td>Top 20%% downloaders</td>\n", tr_odd_even());\r
     top20_count=sum->i;\r
@@ -413,7 +422,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
               top20_count,top20_perc1,top20_sum,top20_perc2);\r
    }\r
 \r
-   if_exists(sum,sums,sum->i>=(active_classes+1)/4)\r
+   if_exists(sum,sums,sum->i >= (active_classes+1)/4)\r
    {\r
     fprintf(f,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
@@ -433,7 +442,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
               sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
    }\r
 \r
-   if_exists(sum,sums,sum->i>=4*(active_classes+1)/5)\r
+   if_exists(sum,sums,sum->i >= 4*(active_classes+1)/5)\r
    {\r
     fprintf(f,"%s<td>Top 80%% downloaders</td>\n", tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
@@ -448,7 +457,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
 <th style=\"text-align: right\">100 %%</th>\n\\r
 <th style=\"text-align: right\">%Lu MB</th>\n\\r
 <th style=\"text-align: right\">100 %%</th></tr>\n",active_classes,total_traffic);\r
-   fputs("</thead></table>\n", f);\r
+   fputs("</thead></table></p>\n", f);\r
 \r
    /* write basic ERP data to log directory */\r
    if(!just_preview)\r
@@ -458,9 +467,10 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
     iplog=fopen(str,"a");\r
     if(iplog)\r
     {\r
-     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",\r
-                   time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, \r
-                   active_classes, total_traffic, i, limit_count, prio_count, d); /* d = date*/\r
+     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\t%.2f %%\t%s",\r
+                    time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, \r
+                    active_classes, total_traffic, i, limit_count, prio_count,\r
+                    bytes6, perc6, d); /* d = date*/\r
      fclose(iplog);\r
     }\r
     else\r
index 92ee23a..1e8dbe6 100644 (file)
@@ -51,7 +51,7 @@ parse_ip(char *str)
 {\r
  char *ptr, *ipaddr, *ip6range = NULL, *ipname = NULL, *lmsid = NULL;\r
 \r
- if(ip6prefix) /* Try this only if IPv6 subsystem is active...*/\r
+ if(ip6prefix) /* Try this only if IPv6 subsystem is active... */\r
  {\r
   ptr = strstr(str, "::");\r
   if(ptr && ptr-str > 4)\r
@@ -160,6 +160,7 @@ void parse_hosts(char *hosts)
    if(lastIP6)\r
    {\r
     lastIP6->sharing = substring;\r
+    lastIP6 = NULL;\r
    }\r
    while(*substring and *substring != '\n')\r
    {\r
@@ -174,6 +175,11 @@ void parse_hosts(char *hosts)
    if_exists(keyword,keywords,(substring=strstr(str,keyword->key)))\r
    {\r
     parse_ip(str);\r
+    if(lastIP6)\r
+    {\r
+     lastIP6->sharing = ip->name;\r
+     lastIP6 = NULL;\r
+    }\r
     ip->keyword = keyword;\r
     keyword->ip_count++;\r
     ip->prio = keyword->default_prio;\r
index 20a7603..503bbac 100644 (file)
@@ -1,5 +1,6 @@
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
-/* Prometheus QoS - you can "steal fire" from your ISP         *//* "fair-per-IP" quality of service (QoS) utility              */\r
+/* Prometheus QoS - you can "steal fire" from your ISP         */\r
+/* "fair-per-IP" quality of service (QoS) utility              */\r
 /* requires Linux 2.4.x or 2.6.x with HTB support              */\r
 /* Copyright(C) 2005-2013 Michael Polak, Arachne Aerospace     */\r
 /* iptables-restore support Copyright(C) 2007-2008 ludva       */\r
@@ -563,12 +564,12 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  /*-----------------------------------------------------------------*/\r
  for_each(ip,ips) if(ip->sharing)\r
  {\r
-  for_each(sharedip,ips) if(eq(sharedip->name,ip->sharing))\r
+  for_each(sharedip,ips) if(eq(sharedip->name, ip->sharing))\r
   {\r
-   sharedip->traffic+=ip->traffic;\r
-   ip->traffic=0;\r
-   ip->mark=sharedip->mark; \r
-   ip->lmsid=sharedip->lmsid;\r
+   sharedip->traffic += ip->traffic;\r
+   ip->traffic = 0;\r
+   ip->mark = sharedip->mark; \r
+   ip->lmsid = sharedip->lmsid;\r
    break;\r
   }\r
   if(not sharedip)\r
This page took 0.228596 seconds and 4 git commands to generate.