⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stat.c

📁 -
💻 C
📖 第 1 页 / 共 4 页
字号:
static voidstat_vmobjects_get(StoreEntry * sentry){    statObjectsStart(sentry, statObjectsVmFilter);}#if DEBUG_OPENFDstatic intstatObjectsOpenfdFilter(const StoreEntry * e){    if (e->mem_obj == NULL)	return 0;    if (e->mem_obj->swapout.fd < 0)	return 0;;    return 1;}static voidstatOpenfdObj(StoreEntry * sentry){    statObjectsStart(sentry, statObjectsOpenfdFilter);}#endif#ifdef XMALLOC_STATISTICSstatic voidinfo_get_mallstat(int size, int number, StoreEntry * sentry){    if (number > 0)	storeAppendPrintf(sentry, "\t%d = %d\n", size, number);}#endifstatic const char *fdRemoteAddr(const fde * f){    LOCAL_ARRAY(char, buf, 32);    if (f->type != FD_SOCKET)	return null_string;    snprintf(buf, 32, "%s.%d", f->ipaddr, (int) f->remote_port);    return buf;}static voidstatFiledescriptors(StoreEntry * sentry){    int i;    fde *f;    storeAppendPrintf(sentry, "Active file descriptors:\n");    storeAppendPrintf(sentry, "%-4s %-6s %-4s %-7s* %-7s* %-21s %s\n",	"File",	"Type",	"Tout",	"Nread",	"Nwrite",	"Remote Address",	"Description");    storeAppendPrintf(sentry, "---- ------ ---- -------- -------- --------------------- ------------------------------\n");    for (i = 0; i < Squid_MaxFD; i++) {	f = &fd_table[i];	if (!f->flags.open)	    continue;	storeAppendPrintf(sentry, "%4d %-6.6s %4d %7d%c %7d%c %-21s %s\n",	    i,	    fdTypeStr[f->type],	    f->timeout_handler ? (int) (f->timeout - squid_curtime) / 60 : 0,	    f->bytes_read,	    f->read_handler ? '*' : ' ',	    f->bytes_written,	    f->write_handler ? '*' : ' ',	    fdRemoteAddr(f),	    f->desc);    }}static voidinfo_get(StoreEntry * sentry){    struct rusage rusage;    double cputime;    double runtime;#if HAVE_MSTATS && HAVE_GNUMALLOC_H    struct mstats ms;#elif HAVE_MALLINFO    struct mallinfo mp;    int t;#endif    runtime = tvSubDsec(squid_start, current_time);    if (runtime == 0.0)	runtime = 1.0;    storeAppendPrintf(sentry, "Squid Object Cache: Version %s\n",	version_string);    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 clients accessing cache:\t%u\n",	Counter.client_http.clients);    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, "\tNumber of queued ICP replies:\t%u\n",	Counter.icp.replies_queued);    storeAppendPrintf(sentry, "\tRequest failure ratio:\t%5.2f%%\n",	request_failure_ratio);    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",	Counter.select_loops, 1000.0 * runtime / Counter.select_loops);    storeAppendPrintf(sentry, "Cache information for %s:\n",	appname);    storeAppendPrintf(sentry, "\tRequest Hit Ratios:\t5min: %3.1f%%, 60min: %3.1f%%\n",	statRequestHitRatio(5),	statRequestHitRatio(60));    storeAppendPrintf(sentry, "\tByte Hit Ratios:\t5min: %3.1f%%, 60min: %3.1f%%\n",	statByteHitRatio(5),	statByteHitRatio(60));    storeAppendPrintf(sentry, "\tStorage Swap size:\t%d KB\n",	store_swap_size);    storeAppendPrintf(sentry, "\tStorage Mem size:\t%d KB\n",	(int) (store_mem_size >> 10));    storeAppendPrintf(sentry, "\tStorage LRU Expiration Age:\t%6.2f days\n",	(double) storeExpiredReferenceAge() / 86400.0);    storeAppendPrintf(sentry, "\tMean Object Size:\t%0.2f KB\n",	n_disk_objects ? (double) store_swap_size / n_disk_objects : 0.0);    storeAppendPrintf(sentry, "\tRequests given to unlinkd:\t%d\n",	Counter.unlink.requests);    storeAppendPrintf(sentry, "Median Service Times (seconds)  5 min    60 min:\n");    storeAppendPrintf(sentry, "\tHTTP Requests (All):  %8.5f %8.5f\n",	statMedianSvc(5, MEDIAN_HTTP) / 1000.0,	statMedianSvc(60, MEDIAN_HTTP) / 1000.0);    storeAppendPrintf(sentry, "\tCache Misses:         %8.5f %8.5f\n",	statMedianSvc(5, MEDIAN_MISS) / 1000.0,	statMedianSvc(60, MEDIAN_MISS) / 1000.0);    storeAppendPrintf(sentry, "\tCache Hits:           %8.5f %8.5f\n",	statMedianSvc(5, MEDIAN_HIT) / 1000.0,	statMedianSvc(60, MEDIAN_HIT) / 1000.0);    storeAppendPrintf(sentry, "\tNear Hits:            %8.5f %8.5f\n",	statMedianSvc(5, MEDIAN_NH) / 1000.0,	statMedianSvc(60, MEDIAN_NH) / 1000.0);    storeAppendPrintf(sentry, "\tNot-Modified Replies: %8.5f %8.5f\n",	statMedianSvc(5, MEDIAN_NM) / 1000.0,	statMedianSvc(60, MEDIAN_NM) / 1000.0);    storeAppendPrintf(sentry, "\tDNS Lookups:          %8.5f %8.5f\n",	statMedianSvc(5, MEDIAN_DNS) / 1000.0,	statMedianSvc(60, MEDIAN_DNS) / 1000.0);    storeAppendPrintf(sentry, "\tICP Queries:          %8.5f %8.5f\n",	statMedianSvc(5, MEDIAN_ICP_QUERY) / 1000000.0,	statMedianSvc(60, MEDIAN_ICP_QUERY) / 1000000.0);    squid_getrusage(&rusage);    cputime = rusage_cputime(&rusage);    storeAppendPrintf(sentry, "Resource usage for %s:\n", appname);    storeAppendPrintf(sentry, "\tUP Time:\t%.3f seconds\n", runtime);    storeAppendPrintf(sentry, "\tCPU Time:\t%.3f seconds\n", cputime);    storeAppendPrintf(sentry, "\tCPU Usage:\t%.2f%%\n",	dpercent(cputime, runtime));    storeAppendPrintf(sentry, "\tCPU Usage, 5 minute avg:\t%.2f%%\n",	statCPUUsage(5));    storeAppendPrintf(sentry, "\tCPU Usage, 60 minute avg:\t%.2f%%\n",	statCPUUsage(60));    storeAppendPrintf(sentry, "\tMaximum Resident Size: %d KB\n",	rusage_maxrss(&rusage));    storeAppendPrintf(sentry, "\tPage faults with physical i/o: %d\n",	rusage_pagefaults(&rusage));#if HAVE_MSTATS && HAVE_GNUMALLOC_H    ms = mstats();    storeAppendPrintf(sentry, "Memory usage for %s via mstats():\n",	appname);    storeAppendPrintf(sentry, "\tTotal space in arena:  %6d KB\n",	ms.bytes_total >> 10);    storeAppendPrintf(sentry, "\tTotal free:            %6d KB %d%%\n",	ms.bytes_free >> 10, percent(ms.bytes_free, ms.bytes_total));#elif HAVE_MALLINFO    mp = mallinfo();    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",	mp.uordblks >> 10, mp.ordblks);    storeAppendPrintf(sentry, "\tSmall blocks:          %6d KB %6d blks\n",	mp.usmblks >> 10, mp.smblks);    storeAppendPrintf(sentry, "\tHolding blocks:        %6d KB %6d blks\n",	mp.hblkhd >> 10, mp.hblks);    storeAppendPrintf(sentry, "\tFree Small blocks:     %6d KB\n",	mp.fsmblks >> 10);    storeAppendPrintf(sentry, "\tFree Ordinary blocks:  %6d KB\n",	mp.fordblks >> 10);    t = mp.uordblks + mp.usmblks + mp.hblkhd;    storeAppendPrintf(sentry, "\tTotal in use:          %6d KB %d%%\n",	t >> 10, percent(t, mp.arena));    t = mp.fsmblks + mp.fordblks;    storeAppendPrintf(sentry, "\tTotal free:            %6d KB %d%%\n",	t >> 10, percent(t, mp.arena));#if HAVE_EXT_MALLINFO    storeAppendPrintf(sentry, "\tmax size of small blocks:\t%d\n", mp.mxfast);    storeAppendPrintf(sentry, "\tnumber of small blocks in a holding block:\t%d\n",	mp.nlblks);    storeAppendPrintf(sentry, "\tsmall block rounding factor:\t%d\n", mp.grain);    storeAppendPrintf(sentry, "\tspace (including overhead) allocated in ord. blks:\t%d\n"	,mp.uordbytes);    storeAppendPrintf(sentry, "\tnumber of ordinary blocks allocated:\t%d\n",	mp.allocated);    storeAppendPrintf(sentry, "\tbytes used in maintaining the free tree:\t%d\n",	mp.treeoverhead);#endif /* HAVE_EXT_MALLINFO */#endif /* HAVE_MALLINFO */    storeAppendPrintf(sentry, "Memory accounted for:\n");    storeAppendPrintf(sentry, "\tTotal accounted:       %6d KB\n",	memTotalAllocated() >> 10);    storeAppendPrintf(sentry, "File descriptor usage for %s:\n", appname);    storeAppendPrintf(sentry, "\tMaximum number of file descriptors:   %4d\n",	Squid_MaxFD);    storeAppendPrintf(sentry, "\tLargest file desc currently in use:   %4d\n",	Biggest_FD);    storeAppendPrintf(sentry, "\tNumber of file desc currently in use: %4d\n",	Number_FD);    storeAppendPrintf(sentry, "\tFiles queued for open:                %4d\n",	Opening_FD);    storeAppendPrintf(sentry, "\tAvailable number of file descriptors: %4d\n",	fdNFree());    storeAppendPrintf(sentry, "\tReserved number of file descriptors:  %4d\n",	RESERVED_FD);    storeAppendPrintf(sentry, "\tStore Disk files open:                %4d\n",	store_open_disk_fd);    storeAppendPrintf(sentry, "Internal Data Structures:\n");    storeAppendPrintf(sentry, "\t%6d StoreEntries\n",	memInUse(MEM_STOREENTRY));    storeAppendPrintf(sentry, "\t%6d StoreEntries with MemObjects\n",	memInUse(MEM_MEMOBJECT));    storeAppendPrintf(sentry, "\t%6d Hot Object Cache Items\n",	hot_obj_count);    storeAppendPrintf(sentry, "\t%6d Filemap bits set\n",	storeDirMapBitsInUse());    storeAppendPrintf(sentry, "\t%6d on-disk objects\n",	n_disk_objects);#if XMALLOC_STATISTICS    storeAppendPrintf(sentry, "Memory allocation statistics\n");    malloc_statistics(info_get_mallstat, sentry);#endif}#define XAVG(X) (dt ? (double) (f->X - l->X) / dt : 0.0)static voidstatAvgDump(StoreEntry * sentry, int minutes, int hours){    StatCounters *f;    StatCounters *l;    double dt;    double ct;    double x;    assert(N_COUNT_HIST > 1);    assert(minutes > 0 || hours > 0);    f = &CountHist[0];    l = f;    if (minutes > 0 && hours == 0) {	/* checking minute readings ... */	if (minutes > N_COUNT_HIST - 1)	    minutes = N_COUNT_HIST - 1;	l = &CountHist[minutes];    } else if (minutes == 0 && hours > 0) {	/* checking hour readings ... */	if (hours > N_COUNT_HOUR_HIST - 1)	    hours = N_COUNT_HOUR_HIST - 1;	l = &CountHourHist[hours];    } else {	debug(18, 1) ("statAvgDump: Invalid args, minutes=%d, hours=%d\n",	    minutes, hours);	return;    }    dt = tvSubDsec(l->timestamp, f->timestamp);    ct = f->cputime - l->cputime;    storeAppendPrintf(sentry, "sample_start_time = %d.%d (%s)\n",	(int) l->timestamp.tv_sec,	(int) l->timestamp.tv_usec,	mkrfc1123(l->timestamp.tv_sec));    storeAppendPrintf(sentry, "sample_end_time = %d.%d (%s)\n",	(int) f->timestamp.tv_sec,	(int) f->timestamp.tv_usec,	mkrfc1123(f->timestamp.tv_sec));    storeAppendPrintf(sentry, "client_http.requests = %f/sec\n",	XAVG(client_http.requests));    storeAppendPrintf(sentry, "client_http.hits = %f/sec\n",	XAVG(client_http.hits));    storeAppendPrintf(sentry, "client_http.errors = %f/sec\n",	XAVG(client_http.errors));    storeAppendPrintf(sentry, "client_http.kbytes_in = %f/sec\n",	XAVG(client_http.kbytes_in.kb));    storeAppendPrintf(sentry, "client_http.kbytes_out = %f/sec\n",	XAVG(client_http.kbytes_out.kb));    x = statHistDeltaMedian(&l->client_http.all_svc_time,	&f->client_http.all_svc_time);    storeAppendPrintf(sentry, "client_http.all_median_svc_time = %f seconds\n",	x / 1000.0);    x = statHistDeltaMedian(&l->client_http.miss_svc_time,	&f->client_http.miss_svc_time);    storeAppendPrintf(sentry, "client_http.miss_median_svc_time = %f seconds\n",	x / 1000.0);    x = statHistDeltaMedian(&l->client_http.nm_svc_time,	&f->client_http.nm_svc_time);    storeAppendPrintf(sentry, "client_http.nm_median_svc_time = %f seconds\n",	x / 1000.0);    x = statHistDeltaMedian(&l->client_http.nh_svc_time,	&f->client_http.nh_svc_time);    storeAppendPrintf(sentry, "client_http.nh_median_svc_time = %f seconds\n",	x / 1000.0);    x = statHistDeltaMedian(&l->client_http.hit_svc_time,	&f->client_http.hit_svc_time);    storeAppendPrintf(sentry, "client_http.hit_median_svc_time = %f seconds\n",	x / 1000.0);    storeAppendPrintf(sentry, "server.all.requests = %f/sec\n",	XAVG(server.all.requests));    storeAppendPrintf(sentry, "server.all.errors = %f/sec\n",	XAVG(server.all.errors));    storeAppendPrintf(sentry, "server.all.kbytes_in = %f/sec\n",	XAVG(server.all.kbytes_in.kb));    storeAppendPrintf(sentry, "server.all.kbytes_out = %f/sec\n",	XAVG(server.all.kbytes_out.kb));    storeAppendPrintf(sentry, "server.http.requests = %f/sec\n",	XAVG(server.http.requests));    storeAppendPrintf(sentry, "server.http.errors = %f/sec\n",	XAVG(server.http.errors));    storeAppendPrintf(sentry, "server.http.kbytes_in = %f/sec\n",	XAVG(server.http.kbytes_in.kb));    storeAppendPrintf(sentry, "server.http.kbytes_out = %f/sec\n",	XAVG(server.http.kbytes_out.kb));    storeAppendPrintf(sentry, "server.ftp.requests = %f/sec\n",	XAVG(server.ftp.requests));    storeAppendPrintf(sentry, "server.ftp.errors = %f/sec\n",	XAVG(server.ftp.errors));    storeAppendPrintf(sentry, "server.ftp.kbytes_in = %f/sec\n",	XAVG(server.ftp.kbytes_in.kb));    storeAppendPrintf(sentry, "server.ftp.kbytes_out = %f/sec\n",	XAVG(server.ftp.kbytes_out.kb));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -