ještě ERP
[svn/Prometheus-QoS/.git] / prometheus.c
index 3cc2662..5420588 100644 (file)
@@ -620,7 +620,7 @@ void save_line(char *line)
 \r
 void run_restore(void)\r
 {\r
- char *restor, *str;\r
+ char *restor;\r
  string(restor,STRLEN);\r
 \r
  /*-----------------------------------------------------------------*/\r
@@ -839,25 +839,35 @@ void parse_ip_log(int argc, char **argv)
  f=fopen(str,"w");\r
  if(f)\r
  {\r
-  fprintf(f,"<table border><tr><th colspan=\"2\">%s %s</th><th colspan=\"2\">Data transfers</th><th align=\"right\">Min.speed</th></tr>\n ",month,year);\r
+  fprintf(f,"<table border><tr><th colspan=\"2\">%s %s</th><th align=\"right\">lms</th><th colspan=\"2\">Data transfers</th><th align=\"right\">Min.speed</th></tr>\n ",month,year);\r
 \r
   for_each(iplog,iplogs)\r
   {\r
    if(iplog->traffic)\r
    {\r
-    fprintf(f,"<tr><td align=\"right\">%d</td><th align=\"left\">%s</td><td align=\"right\">%ld M</td><th align=\"right\">%ld G</th><td align=\"right\">%ld kbps</th></tr>\n",\r
-              i++, iplog->name, iplog->traffic, iplog->traffic>>10, iplog->guaranted);\r
+    fprintf(f,"<tr><td align=\"right\">%d</td><th align=\"left\">%s</td><td align=\"right\">", i++, iplog->name); \r
+    if(iplog->lmsid > 0)\r
+    {\r
+     /*base URL will be configurable soon ... */\r
+     fprintf(f,"<a href=\"https://hermes.spoje.net/?m=customerinfo&amp;id=%d\">%04d</a>\n", iplog->lmsid, iplog->lmsid);\r
+    }\r
+    else if(iplog->lmsid == 0)\r
+    {\r
+     fputs("-------",f);\r
+    }    \r
+    fprintf(f,"<td align=\"right\">%ld M</td><th align=\"right\">%ld G</th><td align=\"right\">%ld kbps</th></tr>\n",\r
+              iplog->traffic, iplog->traffic>>10, iplog->guaranted);\r
     total+=iplog->traffic>>10;\r
     iplog->i=i;\r
     iplog->l=total;\r
    }\r
   }\r
-  fprintf(f,"<tr><th colspan=\"3\" align=\"left\">Total:</th><th align=\"right\">%ld GB</th><th align=\"right\">%Ld kbps</th></tr>\n", total, line);\r
+  fprintf(f,"<tr><th colspan=\"4\" align=\"left\">Total:</th><th align=\"right\">%ld GB</th><th align=\"right\">%Ld kbps</th></tr>\n", total, line);\r
   fputs("</table>\n", f);\r
 \r
   if(i>10)\r
   {\r
-   fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Research and Planning (ERP)</th></tr>\n",f);\r
+   fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Resource Planning (ERP)</th></tr>\n",f);\r
    fputs("<tr><td>Analytic category</td>\n",f);\r
    fputs("<td colspan=\"2\" align=\"center\">Active Classes</td><td colspan=\"2\" align=\"center\">Data transfers</td></tr>\n",f);\r
 \r
@@ -937,6 +947,7 @@ program
  int just_preview=FALSE;                /* preview - generate just stats */\r
  int just_logs=FALSE;                   /* just parse logs */\r
  int run=FALSE;\r
+ int total=0;\r
  \r
  char *chain_forward, *chain_postrouting;\r
  char *althosts=NULL;\r
@@ -1492,7 +1503,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 \r
  if(f)\r
  {\r
-  int total=0;\r
+\r
   int count=1;\r
   i=0;\r
 \r
@@ -1541,7 +1552,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  i=1;\r
  if(f)\r
  {\r
-  unsigned long long total=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum=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;\r
   FILE *iplog;\r
@@ -1606,7 +1617,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     }\r
     else if(ip->lmsid == 0)\r
     {\r
-     fputs("------",f);\r
+     fputs("-------",f);\r
     }\r
     fputs("</td>\n",f);    \r
    }\r
@@ -1621,7 +1632,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    fprintf(f,"<td align=\"right\">%Lu M</td>\n", ip->upload);\r
    fprintf(f,"<td align=\"right\">%d k</td><td align=\"right\">%d k</td><td align=\"right\">%s%d k%s</td><td>%s%d%s</td></tr>\n",\r
              ip->min,ip->desired,f1,ip->max,f2,f1,ip->prio,f2);\r
-   total+=ip->traffic;\r
+   total_traffic+=ip->traffic;\r
    total_direct+=ip->direct;\r
    total_proxy+=ip->proxy;\r
    total_upload+=ip->upload;\r
@@ -1648,11 +1659,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
      fclose(iplog);\r
     }\r
    }\r
-\r
   }\r
   fprintf(f,"<tr><th colspan=\"%d\" align=\"left\">SUMMARY:</td>",colspan-7);\r
   fprintf(f,"<th align=\"right\">%Lu M</th>\\r
-  <th align=\"right\">%Lu M</th>\n", total, total_direct);\r
+  <th align=\"right\">%Lu M</th>\n", total_traffic, total_direct);\r
   if(qos_proxy)\r
   {\r
    fprintf(f,"<th align=\"right\">%Lu M</th>\n", total_proxy);\r
@@ -1662,62 +1672,84 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 \r
   if(active_classes>10)\r
   {\r
-   fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Research and Planning (ERP)</th></tr>\n",f);\r
+   int top20_count=0,top20_perc1=0;\r
+   long long top20_perc2=0;\r
+   unsigned long long top20_sum=0l;\r
+  \r
+   fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Resource Planning (ERP)</th></tr>\n",f);\r
    fputs("<tr><td>Analytic category</td>\n",f);\r
    fputs("<td colspan=\"2\" align=\"center\">Active Classes</td><td colspan=\"2\" align=\"center\">Data transfers</td></tr>\n",f);\r
 \r
-   if_exists(sum,sums,sum->l>=total/4)\r
+   if_exists(sum,sums,sum->l>=total_traffic/4)\r
    {\r
     fprintf(f,"<tr><td>Top 25%% of traffic</td>\n");\r
-    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",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
    {\r
     fprintf(f,"<tr><td>Top 10 downloaders</td>\n");\r
-    fprintf(f,"<th align=\"right\">10</th><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+    fprintf(f,"<th align=\"right\">10</th><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
    }\r
 \r
-   if_exists(sum,sums,sum->l>=total/2)\r
+   if_exists(sum,sums,sum->l>=total_traffic/2)\r
    {\r
     fprintf(f,"<tr><td>Top 50%% of traffic</td>\n");\r
-    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><th align=\"right\">%Ld %%</th></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><th align=\"right\">%Ld %%</th></tr>\n",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/5)\r
+   if_exists(sum,sums,sum->l>=4*total_traffic/5)\r
    {\r
     fprintf(f,"<tr><td>Top 80%% of traffic</td>\n");\r
-    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><th align=\"right\">%Ld %%</th></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><th align=\"right\">%Ld %%</th></tr>\n",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,"<tr><td>Top 20%% downloaders</td>\n");\r
-    fprintf(f,"<td align=\"right\">%d</td><th align=\"right\">%d %%</th><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+    top20_count=sum->i;\r
+    top20_perc1=(100*sum->i+50)/active_classes;\r
+    top20_sum=sum->l;\r
+    top20_perc2=(100*sum->l+50)/total_traffic;\r
+    fprintf(f,"<td align=\"right\">%d</td><th align=\"right\">%d %%</th><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",top20_count,top20_perc1,top20_sum,top20_perc2);\r
    }\r
 \r
    if_exists(sum,sums,sum->i>=(active_classes+1)/4)\r
    {\r
     fprintf(f,"<tr><td>Top 25%% downloaders</td>\n");\r
-    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",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)/2)\r
    {\r
     fprintf(f,"<tr><td>Top 50%% downloaders</td>\n");\r
-    fprintf(f,"<td align=\"right\">%d</td><th align=\"right\">%d %%</th><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+    fprintf(f,"<td align=\"right\">%d</td><th align=\"right\">%d %%</th><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",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
    {\r
     fprintf(f,"<tr><td>Top 80%% downloaders</td>\n");\r
-    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
    }\r
 \r
-   fprintf(f,"<tr><td>All users, all traffic</td>\n");\r
-   fprintf(f,"<th align=\"right\">%d</th><th align=\"right\">100 %%</th><th align=\"right\">%Lu M</th><th align=\"right\">100 %%</th></tr>\n",active_classes,total);\r
+   fprintf(f,"<tr><td><a href=\"%sERP.log\">All users, all traffic</a></td>\n", log_url);\r
+   fprintf(f,"<th align=\"right\">%d</th><th align=\"right\">100 %%</th><th align=\"right\">%Lu M</th><th align=\"right\">100 %%</th></tr>\n",active_classes,total_traffic);\r
    fputs("</table>\n", f);\r
+\r
+   /* write basic ERP data to log directory */\r
+   if(!just_preview)\r
+   {\r
+    sprintf(str,"%s/ERP.log",log_dir);\r
+    iplog=fopen(str,"a");\r
+    if(iplog)\r
+    {\r
+     fprintf(iplog,"%ld\t%d\t%d %%\t%Lu M\t%Ld %%\t%d\t%Lu M\t%d\t%s",\r
+                    time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, active_classes, total_traffic, total, d); /* d = date*/\r
+     fclose(iplog);\r
+    }\r
+   }\r
   }\r
+\r
   fprintf(f, stats_html_signature, version);\r
   fclose(f);\r
  }\r
This page took 0.235727 seconds and 4 git commands to generate.