/*
- * $Id: client_side.cc,v 1.151 1997/11/14 17:20:13 wessels Exp $
+ * $Id: client_side.cc,v 1.152 1997/11/15 00:14:46 wessels Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
for (H = &conn->chr; *H; H = &(*H)->next);
*H = http;
conn->nrequests++;
+ Counter.client_http.requests++;
commSetTimeout(fd, Config.Timeout.lifetime, NULL, NULL);
if ((request = urlParse(method, http->url)) == NULL) {
debug(12, 5) ("Invalid URL: %s\n", http->url);
break;
} else {
/* parser returned -1 */
+ Counter.client_http.requests++;
debug(12, 1) ("clientReadRequest: FD %d Invalid Request\n", fd);
err = errorCon(ERR_INVALID_REQ, HTTP_BAD_REQUEST);
err->callback = clientErrorComplete;
sock, xstrerror());
return;
}
- ntcpconn++;
debug(12, 4) ("httpAccept: FD %d: accepted\n", fd);
connState = xcalloc(1, sizeof(ConnStateData));
connState->peer = peer;
/*
- * $Id: comm.cc,v 1.204 1997/11/14 17:21:15 wessels Exp $
+ * $Id: comm.cc,v 1.205 1997/11/15 00:14:47 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
#endif
for (;;) {
num = poll(pfds, nfds, poll_time);
- select_loops++;
+ Counter.select_loops++;
if (num >= 0)
break;
if (errno == EINTR)
poll_time.tv_sec = sec > 0 ? 1 : 0;
poll_time.tv_usec = 0;
num = select(maxfd, &readfds, &writefds, NULL, &poll_time);
- select_loops++;
+ Counter.select_loops++;
if (num >= 0)
break;
if (errno == EINTR)
/*
- * $Id: globals.h,v 1.17 1997/11/05 05:29:25 wessels Exp $
+ * $Id: globals.h,v 1.18 1997/11/15 00:14:48 wessels Exp $
*/
extern FILE *debug_log; /* NULL */
extern int opt_syslog_enable; /* 0 */
extern int opt_udp_hit_obj; /* 0 */
extern int opt_zap_disk_store; /* 0 */
-extern int select_loops; /* 0 */
extern int syslog_enable; /* 0 */
extern int theInIcpConnection; /* -1 */
extern int theOutIcpConnection; /* -1 */
extern struct in_addr no_addr;
extern struct in_addr theOutICPAddr;
extern struct timeval current_time;
+extern struct timeval squid_start;
extern time_t squid_curtime; /* 0 */
-extern time_t squid_starttime; /* 0 */
extern volatile int reconfigure_pending; /* 0 */
extern volatile int shutdown_pending; /* 0 */
-extern volatile unsigned long nudpconn; /* 0 */
-extern volatile unsigned long ntcpconn; /* 0 */
-extern int unlinkd_count; /* 0 */
extern int fileno_stack_count; /* 0 */
extern int store_rebuilding; /* 1 */
extern int store_swap_size; /* 0 */
extern icpUdpData *UdpQueueHead; /* NULL */
extern icpUdpData *UdpQueueTail; /* NULL */
extern time_t hit_only_mode_until; /* 0 */
+extern StatCounters Counter;
#ifdef HAVE_SYSLOG
extern int _db_level;
queue->len,
inet_ntoa(queue->address.sin_addr),
ntohs(queue->address.sin_port));
+ Counter.icp.pkts_sent++;
x = comm_udp_sendto(fd,
&queue->address,
sizeof(struct sockaddr_in),
if (x < 0) {
if (ignoreErrno(errno))
break; /* don't de-queue */
+ } else {
+ Counter.icp.bytes_sent += x;
}
UdpQueueHead = queue->next;
if (queue->logcode)
switch (header.opcode) {
case ICP_OP_QUERY:
- nudpconn++;
/* We have a valid packet */
url = buf + sizeof(header) + sizeof(u_num32);
if ((icp_request = urlParse(METHOD_GET, url)) == NULL) {
sock, xstrerror());
return;
}
+ Counter.icp.pkts_recv++;
+ Counter.icp.bytes_recv += len;
buf[len] = '\0';
debug(12, 4) ("icpHandleUdp: FD %d: received %d bytes from %s.\n",
sock,
switch (header.opcode) {
case ICP_OP_QUERY:
- nudpconn++;
/* We have a valid packet */
url = buf + sizeof(header) + sizeof(u_num32);
if ((icp_request = urlParse(METHOD_GET, url)) == NULL) {
/*
- * $Id: main.cc,v 1.191 1997/11/13 05:25:49 wessels Exp $
+ * $Id: main.cc,v 1.192 1997/11/15 00:14:49 wessels Exp $
*
* DEBUG: section 1 Startup and Main Loop
* AUTHOR: Harvest Derived
shut_down(int sig)
{
shutdown_pending = sig == SIGINT ? -1 : 1;
- debug(1, 1) ("Preparing for shutdown after %d connections\n",
- ntcpconn + nudpconn);
+ debug(1, 1) ("Preparing for shutdown after %d requests\n",
+ Counter.client_http.requests);
debug(1, 1) ("Waiting %d seconds for active connections to finish\n",
shutdown_pending > 0 ? Config.shutdownLifetime : 0);
#ifdef KILL_PARENT_OPT
if (Config.onoff.announce)
eventAdd("start_announce", start_announce, NULL, 3600);
eventAdd("ipcache_purgelru", ipcache_purgelru, NULL, 10);
+ statAvgInit();
}
configured_once = 1;
}
safe_inet_addr("255.255.255.255", &no_addr);
squid_srandom(time(NULL));
- squid_starttime = getCurrentTime();
+ getCurrentTime();
+ squid_start = current_time;
failure_notify = fatal_dump;
mainParseOptions(argc, argv);
extern void stat_init(cacheinfo **, const char *);
extern void pconnHistCount(int, int);
+extern void statAvgInit(void);
/* To reduce memory fragmentation, we now store the memory version of an
* object in fixed size blocks of size PAGE_SIZE and instead of calling
extern time_t getCurrentTime(void);
extern void normal_shutdown(void);
extern int percent(int, int);
+extern int dpercent(double, double);
extern void squid_signal(int sig, SIGHDLR *, int flags);
extern pid_t readPidFile(void);
extern struct in_addr inaddrFromHostent(const struct hostent *hp);
extern void debug_trap(const char *);
extern void logsFlush(void);
extern char *checkNullString(char *p);
+extern void squid_getrusage(struct rusage *r);
+extern double rusage_cputime(struct rusage *r);
+extern int rusage_maxrss(struct rusage *r);
+extern int rusage_pagefaults(struct rusage *r);
extern void unlinkdInit(void);
extern void unlinkdClose(void);
extern char *urlClean(char *);
extern char *urlCanonicalClean(const request_t *);
-
extern void useragentOpenLog(void);
extern void useragentRotateLog(void);
extern void logUserAgent(const char *, const char *);
/*
- * $Id: stat.cc,v 1.171 1997/11/14 20:00:39 wessels Exp $
+ * $Id: stat.cc,v 1.172 1997/11/15 00:14:51 wessels Exp $
*
* DEBUG: section 18 Cache Manager Statistics
* AUTHOR: Harvest Derived
static void proto_purgeobject(cacheinfo *, protocol_t, int);
static void proto_touchobject(cacheinfo *, protocol_t, int);
static int memoryAccounted(void);
+static void statAvgTick(void *notused);
#ifdef XMALLOC_STATISTICS
static void info_get_mallstat(int, int, StoreEntry *);
int client_pconn_hist[PCONN_HIST_SZ];
int server_pconn_hist[PCONN_HIST_SZ];
+#define N_DELTAS 5
+static StatCounters Deltas[N_DELTAS];
+
/* process utilization information */
static void
statUtilization(cacheinfo * obj, StoreEntry * sentry, const char *desc)
proto_stat *p = &obj->proto_stat_data[PROTO_MAX];
proto_stat *q = NULL;
int secs = 0;
- secs = (int) (squid_curtime - squid_starttime);
+ secs = (int) (squid_curtime - squid_start.tv_sec);
storeAppendPrintf(sentry, "{ %s\n", desc); /* } */
strcpy(p->protoname, "TOTAL");
p->object_count = 0;
void
info_get(StoreEntry * sentry)
{
- const char *tod = NULL;
- float f;
-#if defined(HAVE_GETRUSAGE) && defined(RUSAGE_SELF)
struct rusage rusage;
-#endif
+ double cputime;
+ double runtime;
#if HAVE_MSTATS && HAVE_GNUMALLOC_H
struct mstats ms;
#elif HAVE_MALLINFO
int t;
#endif
+ runtime = tvSubDsec(squid_start, current_time);
+ if (runtime == 0.0)
+ runtime = 1.0;
storeAppendPrintf(sentry, open_bracket);
storeAppendPrintf(sentry, "{Squid Object Cache: Version %s}\n",
version_string);
- tod = mkrfc1123(squid_starttime);
- storeAppendPrintf(sentry, "{Start Time:\t%s}\n", tod);
- tod = mkrfc1123(squid_curtime);
- storeAppendPrintf(sentry, "{Current Time:\t%s}\n", tod);
+ storeAppendPrintf(sentry, "{Start Time:\t%s}\n",
+ mkrfc1123(squid_start.tv_sec));
+ storeAppendPrintf(sentry, "{Current Time:\t%s}\n",
+ mkrfc1123(current_time.tv_sec));
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);
-
-
- f = (float) (squid_curtime - squid_starttime);
- storeAppendPrintf(sentry, "{\tConnections per hour:\t%.1f}\n",
- f == 0.0 ? 0.0 : ((ntcpconn + nudpconn) / (f / 3600.0)));
+ storeAppendPrintf(sentry, "{\tNumber of HTTP requests received:\t%u}\n",
+ Counter.client_http.requests);
+ storeAppendPrintf(sentry, "{\tNumber of ICP messages received:\t%u}\n",
+ Counter.icp.pkts_recv);
+ storeAppendPrintf(sentry, "{\tNumber of ICP messages sent:\t%u}\n",
+ Counter.icp.pkts_sent);
+
+ storeAppendPrintf(sentry, "{\tHTTP requests per minute:\t%.1f}\n",
+ Counter.client_http.requests / (runtime / 60.0));
+ storeAppendPrintf(sentry, "{\tICP messages per minute:\t%.1f}\n",
+ (Counter.icp.pkts_sent + Counter.icp.pkts_recv) / (runtime / 60.0));
storeAppendPrintf(sentry, "{\tSelect loop called: %d times, %0.3f ms avg}\n",
- select_loops, 1000.0 * f / select_loops);
+ Counter.select_loops, 1000.0 * runtime / Counter.select_loops);
storeAppendPrintf(sentry, "{Cache information for %s:}\n",
appname);
storeAppendPrintf(sentry, "{\tStorage LRU Expiration Age:\t%6.2f days}\n",
(double) storeExpiredReferenceAge() / 86400.0);
storeAppendPrintf(sentry, "{\tRequests given to unlinkd:\t%d}\n",
- unlinkd_count);
+ Counter.unlink.requests);
storeAppendPrintf(sentry, "{\tUnused fileno stack count:\t%d}\n",
fileno_stack_count);
-#if HAVE_GETRUSAGE && defined(RUSAGE_SELF)
+ squid_getrusage(&rusage);
+ cputime = rusage_cputime(&rusage);
storeAppendPrintf(sentry, "{Resource usage for %s:}\n", appname);
-#ifdef _SQUID_SOLARIS_
- /* Solaris 2.5 has getrusage() permission bug -- Arjan de Vet */
- enter_suid();
-#endif
- getrusage(RUSAGE_SELF, &rusage);
-#ifdef _SQUID_SOLARIS_
- leave_suid();
-#endif
- 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));
-#if defined(_SQUID_SGI_) || defined(_SQUID_OSF_) || defined(BSD4_4)
- storeAppendPrintf(sentry, "{\tMaximum Resident Size: %ld KB}\n",
- rusage.ru_maxrss);
-#else
+ storeAppendPrintf(sentry, "{\tUP Time:\t%.3f seconds}\n", runtime);
+ storeAppendPrintf(sentry, "{\tCPU Time:\t%.3f seconds}\n", cputime);
+ storeAppendPrintf(sentry, "{\tCPU Usage:\t%d%%}\n",
+ dpercent(cputime, runtime));
storeAppendPrintf(sentry, "{\tMaximum Resident Size: %ld KB}\n",
- (rusage.ru_maxrss * getpagesize()) >> 10);
-#endif
+ rusage_maxrss(&rusage));
storeAppendPrintf(sentry, "{\tPage faults with physical i/o: %ld}\n",
- rusage.ru_majflt);
-#endif
+ rusage_pagefaults(&rusage));
#if HAVE_MSTATS && HAVE_GNUMALLOC_H
ms = mstats();
storeAppendPrintf(e, "\t%4d %9d\n", i, server_pconn_hist[i]);
}
}
+
+void
+statAvgInit(void)
+{
+ memset(Deltas, '\0', N_DELTAS * sizeof(StatCounters));
+ eventAdd("statAvgTick", statAvgTick, NULL, 60);
+}
+
+static void
+statAvgTick(void *notused)
+{
+ StatCounters *t = &Deltas[0];
+ StatCounters *p = &Deltas[1];
+ StatCounters *c = &Counter;
+ struct rusage rusage;
+ eventAdd("statAvgTick", statAvgTick, NULL, 60);
+ memmove(p, t, (N_DELTAS - 1) * sizeof(StatCounters));
+ t->client_http.requests = c->client_http.requests - p->client_http.requests;
+ t->client_http.hits = c->client_http.hits - p->client_http.hits;
+ t->client_http.errors = c->client_http.errors - p->client_http.errors;
+ t->client_http.bytes_in = c->client_http.bytes_in - p->client_http.bytes_in;
+ t->client_http.bytes_out = c->client_http.bytes_out - p->client_http.bytes_out;
+ t->icp.pkts_sent = c->icp.pkts_sent - p->icp.pkts_sent;
+ t->icp.pkts_recv = c->icp.pkts_recv - p->icp.pkts_recv;
+ t->icp.bytes_sent = c->icp.bytes_sent - p->icp.bytes_sent;
+ t->icp.bytes_recv = c->icp.bytes_recv - p->icp.bytes_recv;
+ t->unlink.requests = c->unlink.requests - p->unlink.requests;
+ t->page_faults = c->page_faults - p->page_faults;
+ t->select_loops = c->select_loops - p->select_loops;
+ t->cputime = c->cputime - p->cputime;
+ squid_getrusage(&rusage);
+ c->page_faults = rusage_pagefaults(&rusage);
+ c->cputime = rusage_cputime(&rusage);
+}
char *reply;
} ftp;
};
+
+struct _StatCounters {
+ struct {
+ int requests;
+ int hits;
+ int errors;
+ int bytes_in;
+ int bytes_out;
+ } client_http;
+ struct {
+ int pkts_sent;
+ int pkts_recv;
+ int bytes_sent;
+ int bytes_recv;
+ } icp;
+ struct {
+ int requests;
+ } unlink;
+ int page_faults;
+ int select_loops;
+ double cputime;
+};
/*
- * $Id: tools.cc,v 1.129 1997/11/05 05:29:40 wessels Exp $
+ * $Id: tools.cc,v 1.130 1997/11/15 00:14:52 wessels Exp $
*
* DEBUG: section 21 Misc Functions
* AUTHOR: Harvest Derived
#endif /* HAVE_MALLINFO */
}
-static void
-PrintRusage(void)
+void
+squid_getrusage(struct rusage *r)
{
#if HAVE_GETRUSAGE && defined(RUSAGE_SELF)
- struct rusage rusage;
#ifdef _SQUID_SOLARIS_
/* Solaris 2.5 has getrusage() permission bug -- Arjan de Vet */
enter_suid();
#endif
- getrusage(RUSAGE_SELF, &rusage);
+ getrusage(RUSAGE_SELF, r);
#ifdef _SQUID_SOLARIS_
leave_suid();
#endif
- fprintf(debug_log, "CPU Usage: user %d sys %d\n",
- (int) rusage.ru_utime.tv_sec, (int) rusage.ru_stime.tv_sec);
-#if defined(_SQUID_SGI_) || defined(_SQUID_OSF_) || defined(BSD4_4)
- fprintf(debug_log, "Maximum Resident Size: %ld KB\n", rusage.ru_maxrss);
-#else /* _SQUID_SGI_ */
- fprintf(debug_log, "Maximum Resident Size: %ld KB\n",
- (rusage.ru_maxrss * getpagesize()) >> 10);
-#endif /* _SQUID_SGI_ */
- fprintf(debug_log, "Page faults with physical i/o: %ld\n",
- rusage.ru_majflt);
-#endif /* HAVE_GETRUSAGE */
+#else
+ memset(r, '\0', sizeof(struct rusage));
+#endif
+}
+
+double
+rusage_cputime(struct rusage *r)
+{
+ return (double) r->ru_stime.tv_sec +
+ (double) r->ru_utime.tv_sec +
+ (double) r->ru_stime.tv_usec / 1000000.0 +
+ (double) r->ru_utime.tv_usec / 1000000.0;
+}
+
+int
+rusage_maxrss(struct rusage *r)
+{
+#if defined(_SQUID_SGI_)
+ return r->ru_maxrss;
+#elif defined(_SQUID_OSF_)
+ return r->ru_maxrss;
+#elif defined(BSD4_4)
+ return r->ru_maxrss;
+#else
+ return (r->ru_maxrss * getpagesize()) >> 10;
+#endif
+}
+
+int
+rusage_pagefaults(struct rusage *r)
+{
+ return r->ru_majflt;
+}
+
+
+static void
+PrintRusage(void)
+{
+ struct rusage rusage;
+ squid_getrusage(&rusage);
+ fprintf(debug_log, "CPU Usage: %.3f seconds\n", rusage_cputime(&rusage));
+ fprintf(debug_log, "Maximum Resident Size: %d KB\n",
+ rusage_maxrss(&rusage));
+ fprintf(debug_log, "Page faults with physical i/o: %d\n",
+ rusage_pagefaults(&rusage));
}
return b ? ((int) (100.0 * a / b + 0.5)) : 0;
}
+int
+dpercent(double a, double b)
+{
+ return b ? (100.0 * a / b) : 0.0;
+}
+
void
squid_signal(int sig, SIGHDLR * func, int flags)
{
typedef struct _ErrorState ErrorState;
typedef struct _dlink_node dlink_node;
typedef struct _dlink_list dlink_list;
+typedef struct _StatCounters StatCounters;
typedef void AIOCB(void *, int aio_return, int aio_errno);
typedef void CWCB(int fd, char *, size_t size, int flag, void *data);
/*
- * $Id: unlinkd.cc,v 1.10 1997/10/25 17:23:04 wessels Exp $
+ * $Id: unlinkd.cc,v 1.11 1997/11/15 00:14:53 wessels Exp $
*
* DEBUG: section 43 Unlink Daemon
* AUTHOR: Duane Wessels
NULL, /* Handler */
NULL, /* Handler-data */
xfree);
- unlinkd_count++;
+ Counter.unlink.requests++;
}
void
void
unlinkdInit(void)
{
- unlinkd_count = 0;
unlinkd_fd = unlinkdCreate();
if (unlinkd_fd < 0)
fatal("unlinkdInit: failed to start unlinkd\n");