]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
mucho cleanup, mostly separate filedescriptor output into separate function
authorwessels <>
Wed, 10 Jul 1996 05:00:55 +0000 (05:00 +0000)
committerwessels <>
Wed, 10 Jul 1996 05:00:55 +0000 (05:00 +0000)
src/stat.cc

index 181a0aa1622d26d95336733d22e41aeb4f7b9348..4ac1b7551196e501bafec3bf2842c83e7ce86a0e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: stat.cc,v 1.36 1996/07/09 04:47:24 wessels Exp $
+ * $Id: stat.cc,v 1.37 1996/07/09 23:00:55 wessels Exp $
  *
  * DEBUG: section 18    Cache Manager Statistics
  * AUTHOR: Harvest Derived
@@ -136,6 +136,7 @@ char *diskFileName();
 /* LOCALS */
 char *open_bracket = "{\n";
 char *close_bracket = "}\n";
+static void statFiledescriptors _PARAMS((StoreEntry *));
 
 /* process utilization information */
 void stat_utilization_get(obj, sentry)
@@ -321,6 +322,8 @@ void stat_get(obj, req, sentry)
        stat_io_get(sentry);
     } else if (strcmp(req, "reply_headers") == 0) {
        httpReplyHeaderStats(sentry);
+    } else if (strcmp(req, "filedescriptors") == 0) {
+       statFiledescriptors(sentry);
     }
 }
 
@@ -499,20 +502,90 @@ void info_get_mallstat(size, number, sentry)
      int size, number;
      StoreEntry *sentry;
 {
-    static char line[MAX_LINELEN];
     if (number > 0)
        storeAppendPrintf(sentry, "{\t%d = %d}\n", size, number);
 }
 #endif
 
+static char *host_port_fmt (host, port)
+       char *host;
+       u_short port;
+{
+       static char buf[32];
+       sprintf (buf, "%s.%d", host, (int) port);
+       return buf;
+}
+
+static void statFiledescriptors(sentry)
+       StoreEntry *sentry;
+{
+    int i;
+    int j;
+    char *s = NULL;
+    int lft;
+    int to;
+
+    storeAppendPrintf(sentry, open_bracket);
+    storeAppendPrintf(sentry, "{Active file descriptors:}\n");
+    storeAppendPrintf(sentry, "{%-4s %-6s %-4s %-4s %-21s %s}\n",
+       "File",
+       "Type",
+       "Lftm",
+       "Tout",
+       "Remote Address",
+       "Description");
+    storeAppendPrintf(sentry, "{---- ------ ---- ---- --------------------- ------------------------------}\n");
+    storeAppendPrintf(sentry, "{}\n");
+    for (i = 0; i < FD_SETSIZE; i++) {
+       if (!fdstat_isopen(i))
+           continue;
+       j = fdstatGetType(i);
+       storeAppendPrintf(sentry, "{%4d %-6s ",
+               i,
+               fdstatTypeStr[j]);
+       switch (j) {
+       case FD_SOCKET:
+           if ((lft = comm_get_fd_lifetime(i)) < 0)
+               lft = 0;
+           to = comm_get_fd_timeout(i);
+           if (lft > 0)
+               lft = (lft - squid_curtime) / 60;
+           if (to > 0)
+               to = (to - squid_curtime) / 60;
+           storeAppendPrintf(sentry, "%4d %4d %-21s %s}\n",
+               lft,
+               to,
+               host_port_fmt(fd_table[i].ipaddr, fd_table[i].remote_port),
+               fd_note(i, NULL));
+           break;
+       case FD_FILE:
+           storeAppendPrintf(sentry, "%31s %s}\n",
+               "",
+               (s = diskFileName(i)) ? s : "-");
+           break;
+       case FD_PIPE:
+           storeAppendPrintf(sentry, "%31s %s}\n", "", fd_note(i, NULL));
+           break;
+       case FD_LOG:
+           storeAppendPrintf(sentry, "%31s %s}\n", "", fd_note(i, NULL));
+           break;
+       case FD_UNKNOWN:
+       default:
+           storeAppendPrintf(sentry, "%31s %s}\n", "", fd_note(i, NULL));
+           break;
+       }
+    }
+    storeAppendPrintf(sentry, close_bracket);
+}
+
 
 void info_get(obj, sentry)
      cacheinfo *obj;
      StoreEntry *sentry;
 {
     char *tod = NULL;
-    static char line[MAX_LINELEN];
     wordlist *p = NULL;
+    float f;
 #ifdef HAVE_MALLINFO
     int t;
 #endif
@@ -525,32 +598,23 @@ void info_get(obj, sentry)
     struct mallinfo mp;
 #endif
 
-    memset(line, '\0', SM_PAGE_SIZE);
-
     storeAppendPrintf(sentry, open_bracket);
-    storeAppendPrintf(sentry, "{Squid Object Cache: Version %s}\n", version_string);
+    storeAppendPrintf(sentry, "{Squid Object Cache: Version %s}\n",
+       version_string);
     tod = mkrfc850(&squid_starttime);
     storeAppendPrintf(sentry, "{Start Time:\t%s}\n", tod);
     tod = mkrfc850(&squid_curtime);
     storeAppendPrintf(sentry, "{Current Time:\t%s}\n", tod);
+    storeAppendPrintf(sentry, "{Connection information for %s:}\n",
+       appname);
+    storeAppendPrintf(sentry, "{\tNumber of TCP connections:\t%lu}\n",
+       ntcpconn);
+    storeAppendPrintf(sentry, "{\tNumber of UDP connections:\t%lu}\n",
+       nudpconn);
 
-    /* -------------------------------------------------- */
-
-    storeAppendPrintf(sentry, "{Connection information for %s:}\n", appname);
-
-    storeAppendPrintf(sentry, "{\tNumber of TCP connections:\t%lu}\n", ntcpconn);
-
-    storeAppendPrintf(sentry, "{\tNumber of UDP connections:\t%lu}\n", nudpconn);
-
-    {
-       float f;
        f = squid_curtime - squid_starttime;
-       storeAppendPrintf(sentry, "{\tConnections per hour:\t%.1f}\n", f == 0.0 ? 0.0 :
-           ((ntcpconn + nudpconn) / (f / 3600)));
-    }
-
-    /* -------------------------------------------------- */
-
+       storeAppendPrintf(sentry, "{\tConnections per hour:\t%.1f}\n",
+       f == 0.0 ? 0.0 : ((ntcpconn + nudpconn) / (f / 3600)));
 
     storeAppendPrintf(sentry, "{Cache information for %s:}\n",
        appname);
@@ -564,20 +628,23 @@ void info_get(obj, sentry)
 #if HAVE_GETRUSAGE && defined(RUSAGE_SELF)
     storeAppendPrintf(sentry, "{Resource usage for %s:}\n", appname);
     getrusage(RUSAGE_SELF, &rusage);
-    storeAppendPrintf(sentry, "{\tCPU Usage: user %d sys %d}\n",
-       (int) rusage.ru_utime.tv_sec, (int) rusage.ru_stime.tv_sec);
+    storeAppendPrintf(sentry, "{\tCPU Time: %d seconds (%d user %d sys)}\n",
+       (int) rusage.ru_utime.tv_sec + (int) rusage.ru_stime.tv_sec,
+       (int) rusage.ru_utime.tv_sec,
+       (int) rusage.ru_stime.tv_sec);
+    storeAppendPrintf(sentry, "{\tCPU Usage: %d%%}\n",
+       percent(rusage.ru_utime.tv_sec + rusage.ru_stime.tv_sec,
+           squid_curtime - squid_starttime));
     storeAppendPrintf(sentry, "{\tProcess Size: rss %ld KB}\n",
        rusage.ru_maxrss * getpagesize() >> 10);
-
     storeAppendPrintf(sentry, "{\tPage faults with physical i/o: %ld}\n",
        rusage.ru_majflt);
-
 #endif
 
 #if HAVE_MALLINFO
     mp = mallinfo();
-    storeAppendPrintf(sentry, "{Memory usage for %s via mallinfo():}\n", appname
-       );
+    storeAppendPrintf(sentry, "{Memory usage for %s via mallinfo():}\n",
+       appname);
     storeAppendPrintf(sentry, "{\tTotal space in arena:  %6d KB}\n",
        mp.arena >> 10);
     storeAppendPrintf(sentry, "{\tOrdinary blocks:       %6d KB %6d blks}\n",
@@ -624,47 +691,6 @@ void info_get(obj, sentry)
     storeAppendPrintf(sentry, "{\tReserved number of file descriptors:  %4d}\n",
        RESERVED_FD);
 
-    {
-       int i;
-       char *s = NULL;
-
-       storeAppendPrintf(sentry, "{\tActive file descriptors:}\n");
-
-       for (i = 0; i < FD_SETSIZE; i++) {
-           int lft, to;
-           if (!fdstat_isopen(i))
-               continue;
-           line[0] = '\0';
-           switch (fdstat_type(i)) {
-           case FD_SOCKET:
-               /* the lifetime should be greater than curtime */
-               lft = comm_get_fd_lifetime(i);
-               to = comm_get_fd_timeout(i);
-               storeAppendPrintf(sentry, "{\t\t(%3d = %3d, %3d) NET %s}\n",
-                   i,
-                   (int) (lft > 0 ? lft - squid_curtime : -1),
-                   (int) max((to - squid_curtime), 0),
-                   fd_note(i, NULL));
-               break;
-           case FD_FILE:
-               storeAppendPrintf(sentry, "{\t\t(%3d = FILE) %s}\n", i,
-                   (s = diskFileName(i)) ? s : "Unknown");
-               break;
-           case FD_PIPE:
-               storeAppendPrintf(sentry, "{\t\t(%3d = PIPE) %s}\n", i, fd_note(i, NULL));
-               break;
-           case FD_LOG:
-               storeAppendPrintf(sentry, "{\t\t(%3d = LOG) %s}\n", i, fd_note(i, NULL));
-               break;
-           case FD_UNKNOWN:
-           default:
-               storeAppendPrintf(sentry, "{\t\t(%3d = UNKNOWN) %s}\n", i, fd_note(i, NULL));
-               break;
-           }
-       }
-    }
-
-
     storeAppendPrintf(sentry, "{Stop List:}\n");
     if ((p = getHttpStoplist())) {
        storeAppendPrintf(sentry, "{\tHTTP:}\n");
@@ -694,7 +720,6 @@ void info_get(obj, sentry)
        meta_data.store_in_mem_objects);
 
     storeAppendPrintf(sentry, "{Meta Data:}\n");
-
     storeAppendPrintf(sentry, "{\t%-25.25s %7d x %4d bytes = %6d KB}\n",
        "StoreEntry",
        meta_data.store_entries,
@@ -769,68 +794,63 @@ void info_get(obj, sentry)
     storeAppendPrintf(sentry, close_bracket);
 }
 
-
 void parameter_get(obj, sentry)
      cacheinfo *obj;
      StoreEntry *sentry;
-
 {
-    /* be careful if an object is bigger than 4096, 
-     * need more malloc here */
-    static char line[MAX_LINELEN];
-
-    memset(line, '\0', MAX_LINELEN);
-
     storeAppendPrintf(sentry, open_bracket);
-
-    storeAppendPrintf(sentry, "{VM-Max %d \"# Maximum hot-vm cache (MB)\"}\n",
+    storeAppendPrintf(sentry,
+       "{VM-Max %d \"# Maximum hot-vm cache (MB)\"}\n",
        getCacheMemMax() / (1 << 20));
-
-    storeAppendPrintf(sentry, "{VM-High %d \"# High water mark hot-vm cache (%%)\"}\n",
+    storeAppendPrintf(sentry,
+       "{VM-High %d \"# High water mark hot-vm cache (%%)\"}\n",
        getCacheMemHighWaterMark());
-
-    storeAppendPrintf(sentry, "{VM-Low %d \"# Low water-mark hot-vm cache (%%)\"}\n",
+    storeAppendPrintf(sentry,
+       "{VM-Low %d \"# Low water-mark hot-vm cache (%%)\"}\n",
        getCacheMemLowWaterMark());
-
-    storeAppendPrintf(sentry, "{Swap-Max %d \"# Maximum disk cache (MB)\"}\n",
+    storeAppendPrintf(sentry,
+       "{Swap-Max %d \"# Maximum disk cache (MB)\"}\n",
        getCacheSwapMax() / (1 << 10));
-
-    storeAppendPrintf(sentry, "{Swap-High %d \"# High Water mark disk cache (%%)\"}\n",
+    storeAppendPrintf(sentry,
+       "{Swap-High %d \"# High Water mark disk cache (%%)\"}\n",
        getCacheSwapHighWaterMark());
-
-    storeAppendPrintf(sentry, "{Swap-Low %d \"# Low water mark disk cache (%%)\"}\n",
+    storeAppendPrintf(sentry,
+       "{Swap-Low %d \"# Low water mark disk cache (%%)\"}\n",
        getCacheSwapLowWaterMark());
-
-    storeAppendPrintf(sentry, "{HTTP-Max %d\"# Maximum size HTTP objects (KB)\"}\n",
+    storeAppendPrintf(sentry,
+       "{HTTP-Max %d\"# Maximum size HTTP objects (KB)\"}\n",
        getHttpMax() / (1 << 10));
-
-    storeAppendPrintf(sentry, "{HTTP-TTL %d \"# Http object default TTL (hrs)\"}\n", getHttpTTL() / 3600);
-
-    storeAppendPrintf(sentry, "{Gopher-Max %d \"# Maximum size gopher objects (KB)\"}\n",
+    storeAppendPrintf(sentry,
+       "{HTTP-TTL %d \"# Http object default TTL (hrs)\"}\n",
+       getHttpTTL() / 3600);
+    storeAppendPrintf(sentry,
+       "{Gopher-Max %d \"# Maximum size gopher objects (KB)\"}\n",
        getGopherMax() / (1 << 10));
-
-    storeAppendPrintf(sentry, "{Gopher-TTL %d \"# TTL for gopher objects (hrs)\"}\n", getGopherTTL() / 3600);
-
-    storeAppendPrintf(sentry, "{FTP-Max %d \"# Maximum size FTP objects (KB)\"}\n",
+    storeAppendPrintf(sentry,
+       "{Gopher-TTL %d \"# TTL for gopher objects (hrs)\"}\n",
+       getGopherTTL() / 3600);
+    storeAppendPrintf(sentry,
+       "{FTP-Max %d \"# Maximum size FTP objects (KB)\"}\n",
        getFtpMax() / (1 << 10));
-
-    storeAppendPrintf(sentry, "{FTP-TTL %d \"# TTL for FTP objects (hrs)\"}\n", getFtpTTL() / 3600);
-
-    storeAppendPrintf(sentry, "{Neg-TTL %d \"# TTL for negative cache (s)\"}\n",
+    storeAppendPrintf(sentry,
+       "{FTP-TTL %d \"# TTL for FTP objects (hrs)\"}\n",
+       getFtpTTL() / 3600);
+    storeAppendPrintf(sentry,
+       "{Neg-TTL %d \"# TTL for negative cache (s)\"}\n",
        getNegativeTTL());
-
-    storeAppendPrintf(sentry, "{ReadTimeout %d \"# Maximum idle connection (s)\"}\n", getReadTimeout());
-
-    storeAppendPrintf(sentry, "{ClientLifetime %d \"# Lifetime for incoming HTTP requests or outgoing clients (s)\"}\n", getClientLifetime());
-
-    storeAppendPrintf(sentry, "{CleanRate %d \"# Rate for periodic object expiring\"}\n",
+    storeAppendPrintf(sentry,
+       "{ReadTimeout %d \"# Maximum idle connection (s)\"}\n",
+       getReadTimeout());
+    storeAppendPrintf(sentry,
+       "{ClientLifetime %d \"# Lifetime for incoming HTTP requests\"}\n",
+       getClientLifetime());
+    storeAppendPrintf(sentry,
+       "{CleanRate %d \"# Rate for periodic object expiring\"}\n",
        getCleanRate());
-
     /* Cachemgr.cgi expects an integer in the second field of the string */
-    storeAppendPrintf(sentry, "{HttpAccelMode %d \"# Is operating as an HTTP accelerator\"}\n",
+    storeAppendPrintf(sentry,
+       "{HttpAccelMode %d \"# Is operating as an HTTP accelerator\"}\n",
        httpd_accel_mode);
-
-    /* end of stats */
     storeAppendPrintf(sentry, close_bracket);
 }