json improvements
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Tue, 12 Jun 2012 09:21:52 +0000 (09:21 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Tue, 12 Jun 2012 09:21:52 +0000 (09:21 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@192 251d49ef-1d17-4917-a970-b30cf55b089b

prometheus.c

index 17c77af..b6eeb27 100644 (file)
@@ -7,7 +7,7 @@
 /*  Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
 \r
-/* Modified by: xChaos, 20120610\r
+/* Modified by: xChaos, 20120612\r
                  ludva, 20080415\r
  \r
    Prometheus QoS is free software; you can redistribute it and/or\r
@@ -57,8 +57,9 @@ char    *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for
 char          *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */\r
 char        *classmap = "/var/lib/misc/prometheus.classes"; /* credit log file */\r
 char            *html = "/var/www/traffic.html"; /* hall of fame - html version */\r
-char         *preview = "/var/www/preview.html"; /* hall of fame preview */\r
+char         *preview = "/var/www/preview.html"; /* hall of fame preview - html version */\r
 char            *json = "/var/www/logs/traffic.json"; /* hall of fame - json version */\r
+char    *json_preview = "/var/www/logs/preview.json"; /* hall of fame preview - json version */\r
 char          *cmdlog = "/var/log/prometheuslog"; /* command log filename */\r
 char         *log_dir = "/var/www/logs/"; /* log directory pathname, ended with slash */\r
 char         *log_url = "/logs/"; /* log directory relative URI prefix (partial URL) */\r
@@ -439,6 +440,7 @@ void get_config(char *config_filename)
   option("hall-of-fame-filename",html);\r
   option("json-filename",json);\r
   option("hall-of-fame-preview",preview);\r
+  option("json-preview",json_preview);\r
   option("log-filename",cmdlog);\r
   option("credit-filename",credit);\r
   option("classmap-filename",classmap);\r
@@ -1673,13 +1675,14 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    }\r
    done; /* ugly macro end */\r
   }\r
-  f=fopen(preview,"w");\r
-  ptr=preview; \r
+  html=preview;\r
+  json=json_preview;\r
  }\r
- else if(!dry_run && !just_flush)\r
+\r
+ if(!dry_run && !just_flush)\r
  {\r
   /*-----------------------------------------------------------------*/\r
-  printf("Writing daily statistics  %s ... ", json);\r
+  printf("Writing json overview  %s ... ", json);\r
   /*-----------------------------------------------------------------*/\r
   f=fopen(json, "w");\r
   if(f > 0)\r
@@ -1695,8 +1698,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
      {\r
       fprintf(f, ",\n");\r
      }\r
-     fprintf(f, " \"%s\":{ \"lms\": %d, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \"proxy\":%Lu, \"up\":%Lu }",\r
-                ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload);\r
+     fprintf(f, " \"%s\":{ \"lms\": %d, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \"proxy\":%Lu, \"up\":%Lu, \"min\":%d, \"max\":%d, \"limit\":%d }",\r
+                ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload, ip->min, ip->desired, ip->max);\r
      jsoncount++;\r
     }\r
    }\r
@@ -1708,17 +1711,16 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   {\r
    perror(json);\r
   }\r
-  f=fopen(html,"w");\r
-  ptr=html;\r
  }\r
 \r
- if(f)\r
+ f=fopen(html,"w");\r
+ if(f > 0)\r
  {\r
   int count=1;\r
   i=0;\r
 \r
   /*-----------------------------------------------------------------*/\r
-  printf("Sorting data and generating statistics page %s ...\n", ptr);\r
+  printf("Sorting data and generating statistics page %s ...\n", html);\r
   /*-----------------------------------------------------------------*/\r
 \r
   if(use_jquery_popups)\r
@@ -1779,7 +1781,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  }\r
 \r
  i=0;\r
- if(f)\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
@@ -2226,7 +2228,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
      safe_run(str);\r
    }\r
   \r
-   if(f)\r
+   if(f > 0)\r
    {\r
      fprintf(f, "%s %d\n", ip->addr, ip->mark);\r
    }\r
@@ -2239,7 +2241,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   }\r
   i++;\r
  }\r
- if(f)\r
+ if(f > 0)\r
  {\r
   puts("done.");\r
   fclose(f);\r
This page took 0.159879 seconds and 4 git commands to generate.