]> git.ipfire.org Git - thirdparty/squid.git/blob - src/stat.cc
protos.h refactoring, part one.
[thirdparty/squid.git] / src / stat.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 18 Cache Manager Statistics
5 * AUTHOR: Harvest Derived
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 */
34
35 #include "squid.h"
36 #include "CacheDigest.h"
37 #include "client_side_request.h"
38 #include "client_side.h"
39 #include "comm/Connection.h"
40 #include "comm/Loops.h"
41 #include "event.h"
42 #include "fde.h"
43 #include "format/Token.h"
44 #include "globals.h"
45 #include "HttpRequest.h"
46 #include "MemObject.h"
47 #include "mem_node.h"
48 #include "MemBuf.h"
49 #include "mgr/CountersAction.h"
50 #include "mgr/FunAction.h"
51 #include "mgr/InfoAction.h"
52 #include "mgr/IntervalAction.h"
53 #include "mgr/IoAction.h"
54 #include "mgr/Registration.h"
55 #include "mgr/ServiceTimesAction.h"
56 #include "neighbors.h"
57 #include "PeerDigest.h"
58 #include "protos.h"
59 #include "SquidMath.h"
60 #include "SquidTime.h"
61 #include "StatCounters.h"
62 #include "stat.h"
63 #include "StoreClient.h"
64 #include "Store.h"
65 #if USE_AUTH
66 #include "auth/UserRequest.h"
67 #endif
68 #if USE_DELAY_POOLS
69 #include "DelayId.h"
70 #endif
71 #if USE_SSL
72 #include "ssl/support.h"
73 #endif
74
75 /* these are included because they expose stats calls */
76 /* TODO: provide a self registration mechanism for those classes
77 * to use during static construction
78 */
79 #include "comm.h"
80 #include "StoreSearch.h"
81
82 #define DEBUG_OPENFD 1
83
84 typedef int STOBJFLT(const StoreEntry *);
85
86 class StatObjectsState
87 {
88
89 public:
90 StoreEntry *sentry;
91 STOBJFLT *filter;
92 StoreSearchPointer theSearch;
93
94 private:
95 CBDATA_CLASS2(StatObjectsState);
96 };
97
98 /* LOCALS */
99 static const char *describeStatuses(const StoreEntry *);
100 static const char *describeTimestamps(const StoreEntry *);
101 static void statAvgTick(void *notused);
102 static void statAvgDump(StoreEntry *, int minutes, int hours);
103 #if STAT_GRAPHS
104 static void statGraphDump(StoreEntry *);
105 #endif
106 static void statCountersInit(StatCounters *);
107 static void statCountersInitSpecial(StatCounters *);
108 static void statCountersClean(StatCounters *);
109 static void statCountersCopy(StatCounters * dest, const StatCounters * orig);
110 static double statPctileSvc(double, int, int);
111 static void statStoreEntry(MemBuf * mb, StoreEntry * e);
112 static double statCPUUsage(int minutes);
113 static OBJH stat_objects_get;
114 static OBJH stat_vmobjects_get;
115 #if DEBUG_OPENFD
116 static OBJH statOpenfdObj;
117 #endif
118 static EVH statObjects;
119 static OBJH statCountersDump;
120 static OBJH statPeerSelect;
121 static OBJH statDigestBlob;
122 static OBJH statUtilization;
123 static OBJH statCountersHistograms;
124 static OBJH statClientRequests;
125 void GetAvgStat(Mgr::IntervalActionData& stats, int minutes, int hours);
126 void DumpAvgStat(Mgr::IntervalActionData& stats, StoreEntry* sentry);
127 void GetInfo(Mgr::InfoActionData& stats);
128 void DumpInfo(Mgr::InfoActionData& stats, StoreEntry* sentry);
129 void DumpMallocStatistics(StoreEntry* sentry);
130 void GetCountersStats(Mgr::CountersActionData& stats);
131 void DumpCountersStats(Mgr::CountersActionData& stats, StoreEntry* sentry);
132 void GetServiceTimesStats(Mgr::ServiceTimesActionData& stats);
133 void DumpServiceTimesStats(Mgr::ServiceTimesActionData& stats, StoreEntry* sentry);
134 void GetIoStats(Mgr::IoActionData& stats);
135 void DumpIoStats(Mgr::IoActionData& stats, StoreEntry* sentry);
136
137 #if XMALLOC_STATISTICS
138 static void info_get_mallstat(int, int, int, void *);
139 static double xm_time;
140 static double xm_deltat;
141 #endif
142
143 StatCounters CountHist[N_COUNT_HIST];
144 static int NCountHist = 0;
145 static StatCounters CountHourHist[N_COUNT_HOUR_HIST];
146 static int NCountHourHist = 0;
147 CBDATA_CLASS_INIT(StatObjectsState);
148
149 extern unsigned int mem_pool_alloc_calls;
150 extern unsigned int mem_pool_free_calls;
151
152 static void
153 statUtilization(StoreEntry * e)
154 {
155 storeAppendPrintf(e, "Cache Utilisation:\n");
156 storeAppendPrintf(e, "\n");
157 storeAppendPrintf(e, "Last 5 minutes:\n");
158
159 if (NCountHist >= 5)
160 statAvgDump(e, 5, 0);
161 else
162 storeAppendPrintf(e, "(no values recorded yet)\n");
163
164 storeAppendPrintf(e, "\n");
165
166 storeAppendPrintf(e, "Last 15 minutes:\n");
167
168 if (NCountHist >= 15)
169 statAvgDump(e, 15, 0);
170 else
171 storeAppendPrintf(e, "(no values recorded yet)\n");
172
173 storeAppendPrintf(e, "\n");
174
175 storeAppendPrintf(e, "Last hour:\n");
176
177 if (NCountHist >= 60)
178 statAvgDump(e, 60, 0);
179 else
180 storeAppendPrintf(e, "(no values recorded yet)\n");
181
182 storeAppendPrintf(e, "\n");
183
184 storeAppendPrintf(e, "Last 8 hours:\n");
185
186 if (NCountHourHist >= 8)
187 statAvgDump(e, 0, 8);
188 else
189 storeAppendPrintf(e, "(no values recorded yet)\n");
190
191 storeAppendPrintf(e, "\n");
192
193 storeAppendPrintf(e, "Last day:\n");
194
195 if (NCountHourHist >= 24)
196 statAvgDump(e, 0, 24);
197 else
198 storeAppendPrintf(e, "(no values recorded yet)\n");
199
200 storeAppendPrintf(e, "\n");
201
202 storeAppendPrintf(e, "Last 3 days:\n");
203
204 if (NCountHourHist >= 72)
205 statAvgDump(e, 0, 72);
206 else
207 storeAppendPrintf(e, "(no values recorded yet)\n");
208
209 storeAppendPrintf(e, "\n");
210
211 storeAppendPrintf(e, "Totals since cache startup:\n");
212
213 statCountersDump(e);
214 }
215
216 void
217 GetIoStats(Mgr::IoActionData& stats)
218 {
219 int i;
220
221 stats.http_reads = IOStats.Http.reads;
222
223 for (i = 0; i < _iostats::histSize; ++i) {
224 stats.http_read_hist[i] = IOStats.Http.read_hist[i];
225 }
226
227 stats.ftp_reads = IOStats.Ftp.reads;
228
229 for (i = 0; i < _iostats::histSize; ++i) {
230 stats.ftp_read_hist[i] = IOStats.Ftp.read_hist[i];
231 }
232
233 stats.gopher_reads = IOStats.Gopher.reads;
234
235 for (i = 0; i < _iostats::histSize; ++i) {
236 stats.gopher_read_hist[i] = IOStats.Gopher.read_hist[i];
237 }
238 }
239
240 void
241 DumpIoStats(Mgr::IoActionData& stats, StoreEntry* sentry)
242 {
243 int i;
244
245 storeAppendPrintf(sentry, "HTTP I/O\n");
246 storeAppendPrintf(sentry, "number of reads: %.0f\n", stats.http_reads);
247 storeAppendPrintf(sentry, "Read Histogram:\n");
248
249 for (i = 0; i < _iostats::histSize; ++i) {
250 storeAppendPrintf(sentry, "%5d-%5d: %9.0f %2.0f%%\n",
251 i ? (1 << (i - 1)) + 1 : 1,
252 1 << i,
253 stats.http_read_hist[i],
254 Math::doublePercent(stats.http_read_hist[i], stats.http_reads));
255 }
256
257 storeAppendPrintf(sentry, "\n");
258 storeAppendPrintf(sentry, "FTP I/O\n");
259 storeAppendPrintf(sentry, "number of reads: %.0f\n", stats.ftp_reads);
260 storeAppendPrintf(sentry, "Read Histogram:\n");
261
262 for (i = 0; i < _iostats::histSize; ++i) {
263 storeAppendPrintf(sentry, "%5d-%5d: %9.0f %2.0f%%\n",
264 i ? (1 << (i - 1)) + 1 : 1,
265 1 << i,
266 stats.ftp_read_hist[i],
267 Math::doublePercent(stats.ftp_read_hist[i], stats.ftp_reads));
268 }
269
270 storeAppendPrintf(sentry, "\n");
271 storeAppendPrintf(sentry, "Gopher I/O\n");
272 storeAppendPrintf(sentry, "number of reads: %.0f\n", stats.gopher_reads);
273 storeAppendPrintf(sentry, "Read Histogram:\n");
274
275 for (i = 0; i < _iostats::histSize; ++i) {
276 storeAppendPrintf(sentry, "%5d-%5d: %9.0f %2.0f%%\n",
277 i ? (1 << (i - 1)) + 1 : 1,
278 1 << i,
279 stats.gopher_read_hist[i],
280 Math::doublePercent(stats.gopher_read_hist[i], stats.gopher_reads));
281 }
282
283 storeAppendPrintf(sentry, "\n");
284 }
285
286 static const char *
287 describeStatuses(const StoreEntry * entry)
288 {
289 LOCAL_ARRAY(char, buf, 256);
290 snprintf(buf, 256, "%-13s %-13s %-12s %-12s",
291 storeStatusStr[entry->store_status],
292 memStatusStr[entry->mem_status],
293 swapStatusStr[entry->swap_status],
294 pingStatusStr[entry->ping_status]);
295 return buf;
296 }
297
298 const char *
299 storeEntryFlags(const StoreEntry * entry)
300 {
301 LOCAL_ARRAY(char, buf, 256);
302 int flags = (int) entry->flags;
303 char *t;
304 buf[0] = '\0';
305
306 if (EBIT_TEST(flags, ENTRY_SPECIAL))
307 strcat(buf, "SPECIAL,");
308
309 if (EBIT_TEST(flags, ENTRY_REVALIDATE))
310 strcat(buf, "REVALIDATE,");
311
312 if (EBIT_TEST(flags, DELAY_SENDING))
313 strcat(buf, "DELAY_SENDING,");
314
315 if (EBIT_TEST(flags, RELEASE_REQUEST))
316 strcat(buf, "RELEASE_REQUEST,");
317
318 if (EBIT_TEST(flags, REFRESH_REQUEST))
319 strcat(buf, "REFRESH_REQUEST,");
320
321 if (EBIT_TEST(flags, ENTRY_CACHABLE))
322 strcat(buf, "CACHABLE,");
323
324 if (EBIT_TEST(flags, ENTRY_DISPATCHED))
325 strcat(buf, "DISPATCHED,");
326
327 if (EBIT_TEST(flags, KEY_PRIVATE))
328 strcat(buf, "PRIVATE,");
329
330 if (EBIT_TEST(flags, ENTRY_FWD_HDR_WAIT))
331 strcat(buf, "FWD_HDR_WAIT,");
332
333 if (EBIT_TEST(flags, ENTRY_NEGCACHED))
334 strcat(buf, "NEGCACHED,");
335
336 if (EBIT_TEST(flags, ENTRY_VALIDATED))
337 strcat(buf, "VALIDATED,");
338
339 if (EBIT_TEST(flags, ENTRY_BAD_LENGTH))
340 strcat(buf, "BAD_LENGTH,");
341
342 if (EBIT_TEST(flags, ENTRY_ABORTED))
343 strcat(buf, "ABORTED,");
344
345 if ((t = strrchr(buf, ',')))
346 *t = '\0';
347
348 return buf;
349 }
350
351 static const char *
352 describeTimestamps(const StoreEntry * entry)
353 {
354 LOCAL_ARRAY(char, buf, 256);
355 snprintf(buf, 256, "LV:%-9d LU:%-9d LM:%-9d EX:%-9d",
356 (int) entry->timestamp,
357 (int) entry->lastref,
358 (int) entry->lastmod,
359 (int) entry->expires);
360 return buf;
361 }
362
363 static void
364 statStoreEntry(MemBuf * mb, StoreEntry * e)
365 {
366 MemObject *mem = e->mem_obj;
367 mb->Printf("KEY %s\n", e->getMD5Text());
368 mb->Printf("\t%s\n", describeStatuses(e));
369 mb->Printf("\t%s\n", storeEntryFlags(e));
370 mb->Printf("\t%s\n", describeTimestamps(e));
371 mb->Printf("\t%d locks, %d clients, %d refs\n",
372 (int) e->lock_count,
373 storePendingNClients(e),
374 (int) e->refcount);
375 mb->Printf("\tSwap Dir %d, File %#08X\n",
376 e->swap_dirn, e->swap_filen);
377
378 if (mem != NULL)
379 mem->stat (mb);
380
381 mb->Printf("\n");
382 }
383
384 /* process objects list */
385 static void
386 statObjects(void *data)
387 {
388 StatObjectsState *state = static_cast<StatObjectsState *>(data);
389 StoreEntry *e;
390
391 if (state->theSearch->isDone()) {
392 if (UsingSmp())
393 storeAppendPrintf(state->sentry, "} by kid%d\n\n", KidIdentifier);
394 state->sentry->complete();
395 state->sentry->unlock();
396 cbdataFree(state);
397 return;
398 } else if (EBIT_TEST(state->sentry->flags, ENTRY_ABORTED)) {
399 state->sentry->unlock();
400 cbdataFree(state);
401 return;
402 } else if (state->sentry->checkDeferRead(-1)) {
403 state->sentry->flush();
404 eventAdd("statObjects", statObjects, state, 0.1, 1);
405 return;
406 }
407
408 state->sentry->buffer();
409 size_t statCount = 0;
410 MemBuf mb;
411 mb.init();
412
413 while (statCount++ < static_cast<size_t>(Config.Store.objectsPerBucket) && state->
414 theSearch->next()) {
415 e = state->theSearch->currentItem();
416
417 if (state->filter && 0 == state->filter(e))
418 continue;
419
420 statStoreEntry(&mb, e);
421 }
422
423 if (mb.size)
424 state->sentry->append(mb.buf, mb.size);
425 mb.clean();
426
427 eventAdd("statObjects", statObjects, state, 0.0, 1);
428 }
429
430 static void
431 statObjectsStart(StoreEntry * sentry, STOBJFLT * filter)
432 {
433 StatObjectsState *state = new StatObjectsState;
434 state->sentry = sentry;
435 state->filter = filter;
436
437 sentry->lock();
438 state->theSearch = Store::Root().search(NULL, NULL);
439
440 eventAdd("statObjects", statObjects, state, 0.0, 1);
441 }
442
443 static void
444 stat_objects_get(StoreEntry * sentry)
445 {
446 statObjectsStart(sentry, NULL);
447 }
448
449 static int
450 statObjectsVmFilter(const StoreEntry * e)
451 {
452 return e->mem_obj ? 1 : 0;
453 }
454
455 static void
456 stat_vmobjects_get(StoreEntry * sentry)
457 {
458 statObjectsStart(sentry, statObjectsVmFilter);
459 }
460
461 #if DEBUG_OPENFD
462 static int
463 statObjectsOpenfdFilter(const StoreEntry * e)
464 {
465 if (e->mem_obj == NULL)
466 return 0;
467
468 if (e->mem_obj->swapout.sio == NULL)
469 return 0;
470
471 return 1;
472 }
473
474 static void
475 statOpenfdObj(StoreEntry * sentry)
476 {
477 statObjectsStart(sentry, statObjectsOpenfdFilter);
478 }
479
480 #endif
481
482 #if XMALLOC_STATISTICS
483 static void
484 info_get_mallstat(int size, int number, int oldnum, void *data)
485 {
486 StoreEntry *sentry = (StoreEntry *)data;
487
488 // format: "%12s %15s %6s %12s\n","Alloc Size","Count","Delta","Alloc/sec"
489 if (number > 0)
490 storeAppendPrintf(sentry, "%12d %15d %6d %.1f\n", size, number, number - oldnum, xdiv((number - oldnum), xm_deltat));
491 }
492
493 #endif
494
495 void
496 GetInfo(Mgr::InfoActionData& stats)
497 {
498
499 struct rusage rusage;
500 double cputime;
501 double runtime;
502 #if HAVE_MSTATS && HAVE_GNUMALLOC_H
503
504 struct mstats ms;
505 #elif HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
506
507 struct mallinfo mp;
508 #endif
509
510 runtime = tvSubDsec(squid_start, current_time);
511
512 if (runtime == 0.0)
513 runtime = 1.0;
514
515 stats.squid_start = squid_start;
516
517 stats.current_time = current_time;
518
519 stats.client_http_clients = statCounter.client_http.clients;
520
521 stats.client_http_requests = statCounter.client_http.requests;
522
523 stats.icp_pkts_recv = statCounter.icp.pkts_recv;
524
525 stats.icp_pkts_sent = statCounter.icp.pkts_sent;
526
527 stats.icp_replies_queued = statCounter.icp.replies_queued;
528
529 #if USE_HTCP
530
531 stats.htcp_pkts_recv = statCounter.htcp.pkts_recv;
532
533 stats.htcp_pkts_sent = statCounter.htcp.pkts_sent;
534
535 #endif
536
537 stats.request_failure_ratio = request_failure_ratio;
538
539 stats.avg_client_http_requests = statCounter.client_http.requests / (runtime / 60.0);
540
541 stats.avg_icp_messages = (statCounter.icp.pkts_sent + statCounter.icp.pkts_recv) / (runtime / 60.0);
542
543 stats.select_loops = statCounter.select_loops;
544 stats.avg_loop_time = 1000.0 * runtime / statCounter.select_loops;
545
546 stats.request_hit_ratio5 = statRequestHitRatio(5);
547 stats.request_hit_ratio60 = statRequestHitRatio(60);
548
549 stats.byte_hit_ratio5 = statByteHitRatio(5);
550 stats.byte_hit_ratio60 = statByteHitRatio(60);
551
552 stats.request_hit_mem_ratio5 = statRequestHitMemoryRatio(5);
553 stats.request_hit_mem_ratio60 = statRequestHitMemoryRatio(60);
554
555 stats.request_hit_disk_ratio5 = statRequestHitDiskRatio(5);
556 stats.request_hit_disk_ratio60 = statRequestHitDiskRatio(60);
557
558 Store::Root().getStats(stats.store);
559
560 stats.unlink_requests = statCounter.unlink.requests;
561
562 stats.http_requests5 = statPctileSvc(0.5, 5, PCTILE_HTTP);
563 stats.http_requests60 = statPctileSvc(0.5, 60, PCTILE_HTTP);
564
565 stats.cache_misses5 = statPctileSvc(0.5, 5, PCTILE_MISS);
566 stats.cache_misses60 = statPctileSvc(0.5, 60, PCTILE_MISS);
567
568 stats.cache_hits5 = statPctileSvc(0.5, 5, PCTILE_HIT);
569 stats.cache_hits60 = statPctileSvc(0.5, 60, PCTILE_HIT);
570
571 stats.near_hits5 = statPctileSvc(0.5, 5, PCTILE_NH);
572 stats.near_hits60 = statPctileSvc(0.5, 60, PCTILE_NH);
573
574 stats.not_modified_replies5 = statPctileSvc(0.5, 5, PCTILE_NM);
575 stats.not_modified_replies60 = statPctileSvc(0.5, 60, PCTILE_NM);
576
577 stats.dns_lookups5 = statPctileSvc(0.5, 5, PCTILE_DNS);
578 stats.dns_lookups60 = statPctileSvc(0.5, 60, PCTILE_DNS);
579
580 stats.icp_queries5 = statPctileSvc(0.5, 5, PCTILE_ICP_QUERY);
581 stats.icp_queries60 = statPctileSvc(0.5, 60, PCTILE_ICP_QUERY);
582
583 squid_getrusage(&rusage);
584 cputime = rusage_cputime(&rusage);
585
586 stats.up_time = runtime;
587 stats.cpu_time = cputime;
588 stats.cpu_usage = Math::doublePercent(cputime, runtime);
589 stats.cpu_usage5 = statCPUUsage(5);
590 stats.cpu_usage60 = statCPUUsage(60);
591
592 #if HAVE_SBRK
593
594 stats.proc_data_seg = ((char *) sbrk(0) - (char *) sbrk_start);
595
596 #endif
597
598 stats.maxrss = rusage_maxrss(&rusage);
599
600 stats.page_faults = rusage_pagefaults(&rusage);
601
602 #if HAVE_MSTATS && HAVE_GNUMALLOC_H
603
604 ms = mstats();
605
606 stats.ms_bytes_total = ms.bytes_total;
607
608 stats.ms_bytes_free = ms.bytes_free;
609
610 #elif HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
611
612 mp = mallinfo();
613
614 stats.mp_arena = mp.arena;
615
616 stats.mp_uordblks = mp.uordblks;
617 stats.mp_ordblks = mp.ordblks;
618
619 stats.mp_usmblks = mp.usmblks;
620 stats.mp_smblks = mp.smblks;
621
622 stats.mp_hblkhd = mp.hblkhd;
623 stats.mp_hblks = mp.hblks;
624
625 stats.mp_fsmblks = mp.fsmblks;
626
627 stats.mp_fordblks = mp.fordblks;
628
629 #if HAVE_STRUCT_MALLINFO_MXFAST
630
631 stats.mp_mxfast = mp.mxfast;
632
633 stats.mp_nlblks = mp.nlblks;
634
635 stats.mp_grain = mp.grain;
636
637 stats.mp_uordbytes = mp.uordbytes;
638
639 stats.mp_allocated = mp.allocated;
640
641 stats.mp_treeoverhead = mp.treeoverhead;
642
643 #endif /* HAVE_STRUCT_MALLINFO_MXFAST */
644 #endif /* HAVE_MALLINFO */
645
646 stats.total_accounted = statMemoryAccounted();
647
648 {
649 MemPoolGlobalStats mp_stats;
650 memPoolGetGlobalStats(&mp_stats);
651 #if !(HAVE_MSTATS && HAVE_GNUMALLOC_H) && HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
652
653 stats.mem_pool_allocated = mp_stats.TheMeter->alloc.level;
654 #endif
655
656 stats.gb_saved_count = mp_stats.TheMeter->gb_saved.count;
657 stats.gb_freed_count = mp_stats.TheMeter->gb_freed.count;
658 }
659
660 stats.max_fd = Squid_MaxFD;
661 stats.biggest_fd = Biggest_FD;
662 stats.number_fd = Number_FD;
663 stats.opening_fd = Opening_FD;
664 stats.num_fd_free = fdNFree();
665 stats.reserved_fd = RESERVED_FD;
666 }
667
668 void
669 DumpInfo(Mgr::InfoActionData& stats, StoreEntry* sentry)
670 {
671 storeAppendPrintf(sentry, "Squid Object Cache: Version %s\n",
672 version_string);
673
674 #if _SQUID_WINDOWS_
675 if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) {
676 storeAppendPrintf(sentry,"\nRunning as %s Windows System Service on %s\n",
677 WIN32_Service_name, WIN32_OS_string);
678 storeAppendPrintf(sentry,"Service command line is: %s\n", WIN32_Service_Command_Line);
679 } else
680 storeAppendPrintf(sentry,"Running on %s\n",WIN32_OS_string);
681 #endif
682
683 storeAppendPrintf(sentry, "Start Time:\t%s\n",
684 mkrfc1123(stats.squid_start.tv_sec));
685
686 storeAppendPrintf(sentry, "Current Time:\t%s\n",
687 mkrfc1123(stats.current_time.tv_sec));
688
689 storeAppendPrintf(sentry, "Connection information for %s:\n",APP_SHORTNAME);
690
691 storeAppendPrintf(sentry, "\tNumber of clients accessing cache:\t%.0f\n",
692 stats.client_http_clients);
693
694 storeAppendPrintf(sentry, "\tNumber of HTTP requests received:\t%.0f\n",
695 stats.client_http_requests);
696
697 storeAppendPrintf(sentry, "\tNumber of ICP messages received:\t%.0f\n",
698 stats.icp_pkts_recv);
699
700 storeAppendPrintf(sentry, "\tNumber of ICP messages sent:\t%.0f\n",
701 stats.icp_pkts_sent);
702
703 storeAppendPrintf(sentry, "\tNumber of queued ICP replies:\t%.0f\n",
704 stats.icp_replies_queued);
705
706 #if USE_HTCP
707
708 storeAppendPrintf(sentry, "\tNumber of HTCP messages received:\t%.0f\n",
709 stats.htcp_pkts_recv);
710
711 storeAppendPrintf(sentry, "\tNumber of HTCP messages sent:\t%.0f\n",
712 stats.htcp_pkts_sent);
713
714 #endif
715
716 double fct = stats.count > 1 ? stats.count : 1.0;
717 storeAppendPrintf(sentry, "\tRequest failure ratio:\t%5.2f\n",
718 stats.request_failure_ratio / fct);
719
720 storeAppendPrintf(sentry, "\tAverage HTTP requests per minute since start:\t%.1f\n",
721 stats.avg_client_http_requests);
722
723 storeAppendPrintf(sentry, "\tAverage ICP messages per minute since start:\t%.1f\n",
724 stats.avg_icp_messages);
725
726 storeAppendPrintf(sentry, "\tSelect loop called: %.0f times, %0.3f ms avg\n",
727 stats.select_loops, stats.avg_loop_time / fct);
728
729 storeAppendPrintf(sentry, "Cache information for %s:\n",APP_SHORTNAME);
730
731 storeAppendPrintf(sentry, "\tHits as %% of all requests:\t5min: %3.1f%%, 60min: %3.1f%%\n",
732 stats.request_hit_ratio5 / fct,
733 stats.request_hit_ratio60 / fct);
734
735 storeAppendPrintf(sentry, "\tHits as %% of bytes sent:\t5min: %3.1f%%, 60min: %3.1f%%\n",
736 stats.byte_hit_ratio5 / fct,
737 stats.byte_hit_ratio60 / fct);
738
739 storeAppendPrintf(sentry, "\tMemory hits as %% of hit requests:\t5min: %3.1f%%, 60min: %3.1f%%\n",
740 stats.request_hit_mem_ratio5 / fct,
741 stats.request_hit_mem_ratio60 / fct);
742
743 storeAppendPrintf(sentry, "\tDisk hits as %% of hit requests:\t5min: %3.1f%%, 60min: %3.1f%%\n",
744 stats.request_hit_disk_ratio5 / fct,
745 stats.request_hit_disk_ratio60 / fct);
746
747 storeAppendPrintf(sentry, "\tStorage Swap size:\t%.0f KB\n",
748 stats.store.swap.size / 1024);
749
750 storeAppendPrintf(sentry, "\tStorage Swap capacity:\t%4.1f%% used, %4.1f%% free\n",
751 Math::doublePercent(stats.store.swap.size, stats.store.swap.capacity),
752 Math::doublePercent(stats.store.swap.available(), stats.store.swap.capacity));
753
754 storeAppendPrintf(sentry, "\tStorage Mem size:\t%.0f KB\n",
755 stats.store.mem.size / 1024);
756
757 storeAppendPrintf(sentry, "\tStorage Mem capacity:\t%4.1f%% used, %4.1f%% free\n",
758 Math::doublePercent(stats.store.mem.size, stats.store.mem.capacity),
759 Math::doublePercent(stats.store.mem.available(), stats.store.mem.capacity));
760
761 storeAppendPrintf(sentry, "\tMean Object Size:\t%0.2f KB\n",
762 stats.store.swap.meanObjectSize() / 1024);
763
764 storeAppendPrintf(sentry, "\tRequests given to unlinkd:\t%.0f\n",
765 stats.unlink_requests);
766
767 storeAppendPrintf(sentry, "Median Service Times (seconds) 5 min 60 min:\n");
768
769 fct = stats.count > 1 ? stats.count * 1000.0 : 1000.0;
770 storeAppendPrintf(sentry, "\tHTTP Requests (All): %8.5f %8.5f\n",
771 stats.http_requests5 / fct,
772 stats.http_requests60 / fct);
773
774 storeAppendPrintf(sentry, "\tCache Misses: %8.5f %8.5f\n",
775 stats.cache_misses5 / fct,
776 stats.cache_misses60 / fct);
777
778 storeAppendPrintf(sentry, "\tCache Hits: %8.5f %8.5f\n",
779 stats.cache_hits5 / fct,
780 stats.cache_hits60 / fct);
781
782 storeAppendPrintf(sentry, "\tNear Hits: %8.5f %8.5f\n",
783 stats.near_hits5 / fct,
784 stats.near_hits60 / fct);
785
786 storeAppendPrintf(sentry, "\tNot-Modified Replies: %8.5f %8.5f\n",
787 stats.not_modified_replies5 / fct,
788 stats.not_modified_replies60 / fct);
789
790 storeAppendPrintf(sentry, "\tDNS Lookups: %8.5f %8.5f\n",
791 stats.dns_lookups5 / fct,
792 stats.dns_lookups60 / fct);
793
794 fct = stats.count > 1 ? stats.count * 1000000.0 : 1000000.0;
795 storeAppendPrintf(sentry, "\tICP Queries: %8.5f %8.5f\n",
796 stats.icp_queries5 / fct,
797 stats.icp_queries60 / fct);
798
799 storeAppendPrintf(sentry, "Resource usage for %s:\n", APP_SHORTNAME);
800
801 storeAppendPrintf(sentry, "\tUP Time:\t%.3f seconds\n", stats.up_time);
802
803 storeAppendPrintf(sentry, "\tCPU Time:\t%.3f seconds\n", stats.cpu_time);
804
805 storeAppendPrintf(sentry, "\tCPU Usage:\t%.2f%%\n",
806 stats.cpu_usage);
807
808 storeAppendPrintf(sentry, "\tCPU Usage, 5 minute avg:\t%.2f%%\n",
809 stats.cpu_usage5);
810
811 storeAppendPrintf(sentry, "\tCPU Usage, 60 minute avg:\t%.2f%%\n",
812 stats.cpu_usage60);
813
814 #if HAVE_SBRK
815
816 storeAppendPrintf(sentry, "\tProcess Data Segment Size via sbrk(): %.0f KB\n",
817 stats.proc_data_seg / 1024);
818
819 #endif
820
821 storeAppendPrintf(sentry, "\tMaximum Resident Size: %.0f KB\n",
822 stats.maxrss);
823
824 storeAppendPrintf(sentry, "\tPage faults with physical i/o: %.0f\n",
825 stats.page_faults);
826
827 #if HAVE_MSTATS && HAVE_GNUMALLOC_H
828
829 storeAppendPrintf(sentry, "Memory usage for %s via mstats():\n",APP_SHORTNAME);
830
831 storeAppendPrintf(sentry, "\tTotal space in arena: %6.0f KB\n",
832 stats.ms_bytes_total / 1024);
833
834 storeAppendPrintf(sentry, "\tTotal free: %6.0f KB %.0f%%\n",
835 stats.ms_bytes_free / 1024,
836 Math::doublePercent(stats.ms_bytes_free, stats.ms_bytes_total));
837
838 #elif HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
839
840 storeAppendPrintf(sentry, "Memory usage for %s via mallinfo():\n",APP_SHORTNAME);
841
842 storeAppendPrintf(sentry, "\tTotal space in arena: %6.0f KB\n",
843 stats.mp_arena / 1024);
844
845 storeAppendPrintf(sentry, "\tOrdinary blocks: %6.0f KB %6.0f blks\n",
846 stats.mp_uordblks / 1024, stats.mp_ordblks);
847
848 storeAppendPrintf(sentry, "\tSmall blocks: %6.0f KB %6.0f blks\n",
849 stats.mp_usmblks / 1024, stats.mp_smblks);
850
851 storeAppendPrintf(sentry, "\tHolding blocks: %6.0f KB %6.0f blks\n",
852 stats.mp_hblkhd / 1024, stats.mp_hblks);
853
854 storeAppendPrintf(sentry, "\tFree Small blocks: %6.0f KB\n",
855 stats.mp_fsmblks / 1024);
856
857 storeAppendPrintf(sentry, "\tFree Ordinary blocks: %6.0f KB\n",
858 stats.mp_fordblks / 1024);
859
860 double t = stats.mp_fsmblks + stats.mp_fordblks;
861
862 storeAppendPrintf(sentry, "\tTotal in use: %6.0f KB %.0f%%\n",
863 t / 1024, Math::doublePercent(t, stats.mp_arena + stats.mp_hblkhd));
864
865 t = stats.mp_fsmblks + stats.mp_fordblks;
866
867 storeAppendPrintf(sentry, "\tTotal free: %6.0f KB %.0f%%\n",
868 t / 1024, Math::doublePercent(t, stats.mp_arena + stats.mp_hblkhd));
869
870 t = stats.mp_arena + stats.mp_hblkhd;
871
872 storeAppendPrintf(sentry, "\tTotal size: %6.0f KB\n",
873 t / 1024);
874
875 #if HAVE_STRUCT_MALLINFO_MXFAST
876
877 storeAppendPrintf(sentry, "\tmax size of small blocks:\t%.0f\n", stats.mp_mxfast);
878
879 storeAppendPrintf(sentry, "\tnumber of small blocks in a holding block:\t%.0f\n",
880 stats.mp_nlblks);
881
882 storeAppendPrintf(sentry, "\tsmall block rounding factor:\t%.0f\n", stats.mp_grain);
883
884 storeAppendPrintf(sentry, "\tspace (including overhead) allocated in ord. blks:\t%.0f\n"
885 ,stats.mp_uordbytes);
886
887 storeAppendPrintf(sentry, "\tnumber of ordinary blocks allocated:\t%.0f\n",
888 stats.mp_allocated);
889
890 storeAppendPrintf(sentry, "\tbytes used in maintaining the free tree:\t%.0f\n",
891 stats.mp_treeoverhead);
892
893 #endif /* HAVE_STRUCT_MALLINFO_MXFAST */
894 #endif /* HAVE_MALLINFO */
895
896 storeAppendPrintf(sentry, "Memory accounted for:\n");
897
898 #if !(HAVE_MSTATS && HAVE_GNUMALLOC_H) && HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
899
900 storeAppendPrintf(sentry, "\tTotal accounted: %6.0f KB %3.0f%%\n",
901 stats.total_accounted / 1024, Math::doublePercent(stats.total_accounted, t));
902
903 #else
904
905 storeAppendPrintf(sentry, "\tTotal accounted: %6.0f KB\n",
906 stats.total_accounted / 1024);
907
908 #endif
909 {
910 MemPoolGlobalStats mp_stats;
911 memPoolGetGlobalStats(&mp_stats);
912 #if !(HAVE_MSTATS && HAVE_GNUMALLOC_H) && HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
913
914 storeAppendPrintf(sentry, "\tmemPool accounted: %6.0f KB %3.0f%%\n",
915 stats.mem_pool_allocated / 1024,
916 Math::doublePercent(stats.mem_pool_allocated, t));
917
918 const double iFree = max(0.0, t - stats.mem_pool_allocated);
919 storeAppendPrintf(sentry, "\tmemPool unaccounted: %6.0f KB %3.0f%%\n",
920 (t - stats.mem_pool_allocated) / 1024,
921 Math::doublePercent(iFree, t));
922 #endif
923
924 storeAppendPrintf(sentry, "\tmemPoolAlloc calls: %9.0f\n",
925 stats.gb_saved_count);
926 storeAppendPrintf(sentry, "\tmemPoolFree calls: %9.0f\n",
927 stats.gb_freed_count);
928 }
929
930 storeAppendPrintf(sentry, "File descriptor usage for %s:\n", APP_SHORTNAME);
931 storeAppendPrintf(sentry, "\tMaximum number of file descriptors: %4.0f\n",
932 stats.max_fd);
933 storeAppendPrintf(sentry, "\tLargest file desc currently in use: %4.0f\n",
934 stats.biggest_fd);
935 storeAppendPrintf(sentry, "\tNumber of file desc currently in use: %4.0f\n",
936 stats.number_fd);
937 storeAppendPrintf(sentry, "\tFiles queued for open: %4.0f\n",
938 stats.opening_fd);
939 storeAppendPrintf(sentry, "\tAvailable number of file descriptors: %4.0f\n",
940 stats.num_fd_free);
941 storeAppendPrintf(sentry, "\tReserved number of file descriptors: %4.0f\n",
942 stats.reserved_fd);
943 storeAppendPrintf(sentry, "\tStore Disk files open: %4.0f\n",
944 stats.store.swap.open_disk_fd);
945
946 storeAppendPrintf(sentry, "Internal Data Structures:\n");
947 storeAppendPrintf(sentry, "\t%6.0f StoreEntries\n",
948 stats.store.store_entry_count);
949 storeAppendPrintf(sentry, "\t%6.0f StoreEntries with MemObjects\n",
950 stats.store.mem_object_count);
951 storeAppendPrintf(sentry, "\t%6.0f Hot Object Cache Items\n",
952 stats.store.mem.count);
953 storeAppendPrintf(sentry, "\t%6.0f on-disk objects\n",
954 stats.store.swap.count);
955 }
956
957 void
958 DumpMallocStatistics(StoreEntry* sentry)
959 {
960 #if XMALLOC_STATISTICS
961
962 xm_deltat = current_dtime - xm_time;
963 xm_time = current_dtime;
964 storeAppendPrintf(sentry, "\nMemory allocation statistics\n");
965 storeAppendPrintf(sentry, "%12s %15s %6s %12s\n","Alloc Size","Count","Delta","Alloc/sec");
966 malloc_statistics(info_get_mallstat, sentry);
967 #endif
968 }
969
970 void
971 GetServiceTimesStats(Mgr::ServiceTimesActionData& stats)
972 {
973 for (int i = 0; i < Mgr::ServiceTimesActionData::seriesSize; ++i) {
974 double p = (i + 1) * 5 / 100.0;
975 stats.http_requests5[i] = statPctileSvc(p, 5, PCTILE_HTTP);
976 stats.http_requests60[i] = statPctileSvc(p, 60, PCTILE_HTTP);
977
978 stats.cache_misses5[i] = statPctileSvc(p, 5, PCTILE_MISS);
979 stats.cache_misses60[i] = statPctileSvc(p, 60, PCTILE_MISS);
980
981 stats.cache_hits5[i] = statPctileSvc(p, 5, PCTILE_HIT);
982 stats.cache_hits60[i] = statPctileSvc(p, 60, PCTILE_HIT);
983
984 stats.near_hits5[i] = statPctileSvc(p, 5, PCTILE_NH);
985 stats.near_hits60[i] = statPctileSvc(p, 60, PCTILE_NH);
986
987 stats.not_modified_replies5[i] = statPctileSvc(p, 5, PCTILE_NM);
988 stats.not_modified_replies60[i] = statPctileSvc(p, 60, PCTILE_NM);
989
990 stats.dns_lookups5[i] = statPctileSvc(p, 5, PCTILE_DNS);
991 stats.dns_lookups60[i] = statPctileSvc(p, 60, PCTILE_DNS);
992
993 stats.icp_queries5[i] = statPctileSvc(p, 5, PCTILE_ICP_QUERY);
994 stats.icp_queries60[i] = statPctileSvc(p, 60, PCTILE_ICP_QUERY);
995 }
996 }
997
998 void
999 DumpServiceTimesStats(Mgr::ServiceTimesActionData& stats, StoreEntry* sentry)
1000 {
1001 storeAppendPrintf(sentry, "Service Time Percentiles 5 min 60 min:\n");
1002 double fct = stats.count > 1 ? stats.count * 1000.0 : 1000.0;
1003 for (int i = 0; i < Mgr::ServiceTimesActionData::seriesSize; ++i) {
1004 storeAppendPrintf(sentry, "\tHTTP Requests (All): %2d%% %8.5f %8.5f\n",
1005 (i + 1) * 5,
1006 stats.http_requests5[i] / fct,
1007 stats.http_requests60[i] / fct);
1008 }
1009 for (int i = 0; i < Mgr::ServiceTimesActionData::seriesSize; ++i) {
1010 storeAppendPrintf(sentry, "\tCache Misses: %2d%% %8.5f %8.5f\n",
1011 (i + 1) * 5,
1012 stats.cache_misses5[i] / fct,
1013 stats.cache_misses60[i] / fct);
1014 }
1015 for (int i = 0; i < Mgr::ServiceTimesActionData::seriesSize; ++i) {
1016 storeAppendPrintf(sentry, "\tCache Hits: %2d%% %8.5f %8.5f\n",
1017 (i + 1) * 5,
1018 stats.cache_hits5[i] / fct,
1019 stats.cache_hits60[i] / fct);
1020 }
1021 for (int i = 0; i < Mgr::ServiceTimesActionData::seriesSize; ++i) {
1022 storeAppendPrintf(sentry, "\tNear Hits: %2d%% %8.5f %8.5f\n",
1023 (i + 1) * 5,
1024 stats.near_hits5[i] / fct,
1025 stats.near_hits60[i] / fct);
1026 }
1027 for (int i = 0; i < Mgr::ServiceTimesActionData::seriesSize; ++i) {
1028 storeAppendPrintf(sentry, "\tNot-Modified Replies: %2d%% %8.5f %8.5f\n",
1029 (i + 1) * 5,
1030 stats.not_modified_replies5[i] / fct,
1031 stats.not_modified_replies60[i] / fct);
1032 }
1033 for (int i = 0; i < Mgr::ServiceTimesActionData::seriesSize; ++i) {
1034 storeAppendPrintf(sentry, "\tDNS Lookups: %2d%% %8.5f %8.5f\n",
1035 (i + 1) * 5,
1036 stats.dns_lookups5[i] / fct,
1037 stats.dns_lookups60[i] / fct);
1038 }
1039 fct = stats.count > 1 ? stats.count * 1000000.0 : 1000000.0;
1040 for (int i = 0; i < Mgr::ServiceTimesActionData::seriesSize; ++i) {
1041 storeAppendPrintf(sentry, "\tICP Queries: %2d%% %8.5f %8.5f\n",
1042 (i + 1) * 5,
1043 stats.icp_queries5[i] / fct,
1044 stats.icp_queries60[i] / fct);
1045 }
1046 }
1047
1048 static void
1049 statAvgDump(StoreEntry * sentry, int minutes, int hours)
1050 {
1051 Mgr::IntervalActionData stats;
1052 GetAvgStat(stats, minutes, hours);
1053 DumpAvgStat(stats, sentry);
1054 }
1055
1056 #define XAVG(X) (dt ? (double) (f->X - l->X) / dt : 0.0)
1057 void
1058 GetAvgStat(Mgr::IntervalActionData& stats, int minutes, int hours)
1059 {
1060 StatCounters *f;
1061 StatCounters *l;
1062 double dt;
1063 double ct;
1064 assert(N_COUNT_HIST > 1);
1065 assert(minutes > 0 || hours > 0);
1066 f = &CountHist[0];
1067 l = f;
1068
1069 if (minutes > 0 && hours == 0) {
1070 /* checking minute readings ... */
1071
1072 if (minutes > N_COUNT_HIST - 1)
1073 minutes = N_COUNT_HIST - 1;
1074
1075 l = &CountHist[minutes];
1076 } else if (minutes == 0 && hours > 0) {
1077 /* checking hour readings ... */
1078
1079 if (hours > N_COUNT_HOUR_HIST - 1)
1080 hours = N_COUNT_HOUR_HIST - 1;
1081
1082 l = &CountHourHist[hours];
1083 } else {
1084 debugs(18, DBG_IMPORTANT, "statAvgDump: Invalid args, minutes=" << minutes << ", hours=" << hours);
1085 return;
1086 }
1087
1088 dt = tvSubDsec(l->timestamp, f->timestamp);
1089 ct = f->cputime - l->cputime;
1090
1091 stats.sample_start_time = l->timestamp;
1092 stats.sample_end_time = f->timestamp;
1093
1094 stats.client_http_requests = XAVG(client_http.requests);
1095 stats.client_http_hits = XAVG(client_http.hits);
1096 stats.client_http_errors = XAVG(client_http.errors);
1097 stats.client_http_kbytes_in = XAVG(client_http.kbytes_in.kb);
1098 stats.client_http_kbytes_out = XAVG(client_http.kbytes_out.kb);
1099
1100 stats.client_http_all_median_svc_time = statHistDeltaMedian(l->client_http.allSvcTime,
1101 f->client_http.allSvcTime) / 1000.0;
1102 stats.client_http_miss_median_svc_time = statHistDeltaMedian(l->client_http.missSvcTime,
1103 f->client_http.missSvcTime) / 1000.0;
1104 stats.client_http_nm_median_svc_time = statHistDeltaMedian(l->client_http.nearMissSvcTime,
1105 f->client_http.nearMissSvcTime) / 1000.0;
1106 stats.client_http_nh_median_svc_time = statHistDeltaMedian(l->client_http.nearHitSvcTime,
1107 f->client_http.nearHitSvcTime) / 1000.0;
1108 stats.client_http_hit_median_svc_time = statHistDeltaMedian(l->client_http.hitSvcTime,
1109 f->client_http.hitSvcTime) / 1000.0;
1110
1111 stats.server_all_requests = XAVG(server.all.requests);
1112 stats.server_all_errors = XAVG(server.all.errors);
1113 stats.server_all_kbytes_in = XAVG(server.all.kbytes_in.kb);
1114 stats.server_all_kbytes_out = XAVG(server.all.kbytes_out.kb);
1115
1116 stats.server_http_requests = XAVG(server.http.requests);
1117 stats.server_http_errors = XAVG(server.http.errors);
1118 stats.server_http_kbytes_in = XAVG(server.http.kbytes_in.kb);
1119 stats.server_http_kbytes_out = XAVG(server.http.kbytes_out.kb);
1120
1121 stats.server_ftp_requests = XAVG(server.ftp.requests);
1122 stats.server_ftp_errors = XAVG(server.ftp.errors);
1123 stats.server_ftp_kbytes_in = XAVG(server.ftp.kbytes_in.kb);
1124 stats.server_ftp_kbytes_out = XAVG(server.ftp.kbytes_out.kb);
1125
1126 stats.server_other_requests = XAVG(server.other.requests);
1127 stats.server_other_errors = XAVG(server.other.errors);
1128 stats.server_other_kbytes_in = XAVG(server.other.kbytes_in.kb);
1129 stats.server_other_kbytes_out = XAVG(server.other.kbytes_out.kb);
1130
1131 stats.icp_pkts_sent = XAVG(icp.pkts_sent);
1132 stats.icp_pkts_recv = XAVG(icp.pkts_recv);
1133 stats.icp_queries_sent = XAVG(icp.queries_sent);
1134 stats.icp_replies_sent = XAVG(icp.replies_sent);
1135 stats.icp_queries_recv = XAVG(icp.queries_recv);
1136 stats.icp_replies_recv = XAVG(icp.replies_recv);
1137 stats.icp_replies_queued = XAVG(icp.replies_queued);
1138 stats.icp_query_timeouts = XAVG(icp.query_timeouts);
1139 stats.icp_kbytes_sent = XAVG(icp.kbytes_sent.kb);
1140 stats.icp_kbytes_recv = XAVG(icp.kbytes_recv.kb);
1141 stats.icp_q_kbytes_sent = XAVG(icp.q_kbytes_sent.kb);
1142 stats.icp_r_kbytes_sent = XAVG(icp.r_kbytes_sent.kb);
1143 stats.icp_q_kbytes_recv = XAVG(icp.q_kbytes_recv.kb);
1144 stats.icp_r_kbytes_recv = XAVG(icp.r_kbytes_recv.kb);
1145
1146 stats.icp_query_median_svc_time = statHistDeltaMedian(l->icp.querySvcTime,
1147 f->icp.querySvcTime) / 1000000.0;
1148 stats.icp_reply_median_svc_time = statHistDeltaMedian(l->icp.replySvcTime,
1149 f->icp.replySvcTime) / 1000000.0;
1150 stats.dns_median_svc_time = statHistDeltaMedian(l->dns.svcTime,
1151 f->dns.svcTime) / 1000.0;
1152
1153 stats.unlink_requests = XAVG(unlink.requests);
1154 stats.page_faults = XAVG(page_faults);
1155 stats.select_loops = XAVG(select_loops);
1156 stats.select_fds = XAVG(select_fds);
1157 stats.average_select_fd_period = f->select_fds > l->select_fds ?
1158 (f->select_time - l->select_time) / (f->select_fds - l->select_fds) : 0.0;
1159
1160 stats.median_select_fds = statHistDeltaMedian(l->select_fds_hist, f->select_fds_hist);
1161 stats.swap_outs = XAVG(swap.outs);
1162 stats.swap_ins = XAVG(swap.ins);
1163 stats.swap_files_cleaned = XAVG(swap.files_cleaned);
1164 stats.aborted_requests = XAVG(aborted_requests);
1165
1166 stats.syscalls_disk_opens = XAVG(syscalls.disk.opens);
1167 stats.syscalls_disk_closes = XAVG(syscalls.disk.closes);
1168 stats.syscalls_disk_reads = XAVG(syscalls.disk.reads);
1169 stats.syscalls_disk_writes = XAVG(syscalls.disk.writes);
1170 stats.syscalls_disk_seeks = XAVG(syscalls.disk.seeks);
1171 stats.syscalls_disk_unlinks = XAVG(syscalls.disk.unlinks);
1172 stats.syscalls_sock_accepts = XAVG(syscalls.sock.accepts);
1173 stats.syscalls_sock_sockets = XAVG(syscalls.sock.sockets);
1174 stats.syscalls_sock_connects = XAVG(syscalls.sock.connects);
1175 stats.syscalls_sock_binds = XAVG(syscalls.sock.binds);
1176 stats.syscalls_sock_closes = XAVG(syscalls.sock.closes);
1177 stats.syscalls_sock_reads = XAVG(syscalls.sock.reads);
1178 stats.syscalls_sock_writes = XAVG(syscalls.sock.writes);
1179 stats.syscalls_sock_recvfroms = XAVG(syscalls.sock.recvfroms);
1180 stats.syscalls_sock_sendtos = XAVG(syscalls.sock.sendtos);
1181 stats.syscalls_selects = XAVG(syscalls.selects);
1182
1183 stats.cpu_time = ct;
1184 stats.wall_time = dt;
1185 }
1186
1187 void
1188 DumpAvgStat(Mgr::IntervalActionData& stats, StoreEntry* sentry)
1189 {
1190 storeAppendPrintf(sentry, "sample_start_time = %d.%d (%s)\n",
1191 (int)stats.sample_start_time.tv_sec,
1192 (int)stats.sample_start_time.tv_usec,
1193 mkrfc1123(stats.sample_start_time.tv_sec));
1194 storeAppendPrintf(sentry, "sample_end_time = %d.%d (%s)\n",
1195 (int)stats.sample_end_time.tv_sec,
1196 (int)stats.sample_end_time.tv_usec,
1197 mkrfc1123(stats.sample_end_time.tv_sec));
1198
1199 storeAppendPrintf(sentry, "client_http.requests = %f/sec\n",
1200 stats.client_http_requests);
1201 storeAppendPrintf(sentry, "client_http.hits = %f/sec\n",
1202 stats.client_http_hits);
1203 storeAppendPrintf(sentry, "client_http.errors = %f/sec\n",
1204 stats.client_http_errors);
1205 storeAppendPrintf(sentry, "client_http.kbytes_in = %f/sec\n",
1206 stats.client_http_kbytes_in);
1207 storeAppendPrintf(sentry, "client_http.kbytes_out = %f/sec\n",
1208 stats.client_http_kbytes_out);
1209
1210 double fct = stats.count > 1 ? stats.count : 1.0;
1211 storeAppendPrintf(sentry, "client_http.all_median_svc_time = %f seconds\n",
1212 stats.client_http_all_median_svc_time / fct);
1213 storeAppendPrintf(sentry, "client_http.miss_median_svc_time = %f seconds\n",
1214 stats.client_http_miss_median_svc_time / fct);
1215 storeAppendPrintf(sentry, "client_http.nm_median_svc_time = %f seconds\n",
1216 stats.client_http_nm_median_svc_time / fct);
1217 storeAppendPrintf(sentry, "client_http.nh_median_svc_time = %f seconds\n",
1218 stats.client_http_nh_median_svc_time / fct);
1219 storeAppendPrintf(sentry, "client_http.hit_median_svc_time = %f seconds\n",
1220 stats.client_http_hit_median_svc_time / fct);
1221
1222 storeAppendPrintf(sentry, "server.all.requests = %f/sec\n",
1223 stats.server_all_requests);
1224 storeAppendPrintf(sentry, "server.all.errors = %f/sec\n",
1225 stats.server_all_errors);
1226 storeAppendPrintf(sentry, "server.all.kbytes_in = %f/sec\n",
1227 stats.server_all_kbytes_in);
1228 storeAppendPrintf(sentry, "server.all.kbytes_out = %f/sec\n",
1229 stats.server_all_kbytes_out);
1230
1231 storeAppendPrintf(sentry, "server.http.requests = %f/sec\n",
1232 stats.server_http_requests);
1233 storeAppendPrintf(sentry, "server.http.errors = %f/sec\n",
1234 stats.server_http_errors);
1235 storeAppendPrintf(sentry, "server.http.kbytes_in = %f/sec\n",
1236 stats.server_http_kbytes_in);
1237 storeAppendPrintf(sentry, "server.http.kbytes_out = %f/sec\n",
1238 stats.server_http_kbytes_out);
1239
1240 storeAppendPrintf(sentry, "server.ftp.requests = %f/sec\n",
1241 stats.server_ftp_requests);
1242 storeAppendPrintf(sentry, "server.ftp.errors = %f/sec\n",
1243 stats.server_ftp_errors);
1244 storeAppendPrintf(sentry, "server.ftp.kbytes_in = %f/sec\n",
1245 stats.server_ftp_kbytes_in);
1246 storeAppendPrintf(sentry, "server.ftp.kbytes_out = %f/sec\n",
1247 stats.server_ftp_kbytes_out);
1248
1249 storeAppendPrintf(sentry, "server.other.requests = %f/sec\n",
1250 stats.server_other_requests);
1251 storeAppendPrintf(sentry, "server.other.errors = %f/sec\n",
1252 stats.server_other_errors);
1253 storeAppendPrintf(sentry, "server.other.kbytes_in = %f/sec\n",
1254 stats.server_other_kbytes_in);
1255 storeAppendPrintf(sentry, "server.other.kbytes_out = %f/sec\n",
1256 stats.server_other_kbytes_out);
1257
1258 storeAppendPrintf(sentry, "icp.pkts_sent = %f/sec\n",
1259 stats.icp_pkts_sent);
1260 storeAppendPrintf(sentry, "icp.pkts_recv = %f/sec\n",
1261 stats.icp_pkts_recv);
1262 storeAppendPrintf(sentry, "icp.queries_sent = %f/sec\n",
1263 stats.icp_queries_sent);
1264 storeAppendPrintf(sentry, "icp.replies_sent = %f/sec\n",
1265 stats.icp_replies_sent);
1266 storeAppendPrintf(sentry, "icp.queries_recv = %f/sec\n",
1267 stats.icp_queries_recv);
1268 storeAppendPrintf(sentry, "icp.replies_recv = %f/sec\n",
1269 stats.icp_replies_recv);
1270 storeAppendPrintf(sentry, "icp.replies_queued = %f/sec\n",
1271 stats.icp_replies_queued);
1272 storeAppendPrintf(sentry, "icp.query_timeouts = %f/sec\n",
1273 stats.icp_query_timeouts);
1274 storeAppendPrintf(sentry, "icp.kbytes_sent = %f/sec\n",
1275 stats.icp_kbytes_sent);
1276 storeAppendPrintf(sentry, "icp.kbytes_recv = %f/sec\n",
1277 stats.icp_kbytes_recv);
1278 storeAppendPrintf(sentry, "icp.q_kbytes_sent = %f/sec\n",
1279 stats.icp_q_kbytes_sent);
1280 storeAppendPrintf(sentry, "icp.r_kbytes_sent = %f/sec\n",
1281 stats.icp_r_kbytes_sent);
1282 storeAppendPrintf(sentry, "icp.q_kbytes_recv = %f/sec\n",
1283 stats.icp_q_kbytes_recv);
1284 storeAppendPrintf(sentry, "icp.r_kbytes_recv = %f/sec\n",
1285 stats.icp_r_kbytes_recv);
1286 storeAppendPrintf(sentry, "icp.query_median_svc_time = %f seconds\n",
1287 stats.icp_query_median_svc_time / fct);
1288 storeAppendPrintf(sentry, "icp.reply_median_svc_time = %f seconds\n",
1289 stats.icp_reply_median_svc_time / fct);
1290 storeAppendPrintf(sentry, "dns.median_svc_time = %f seconds\n",
1291 stats.dns_median_svc_time / fct);
1292 storeAppendPrintf(sentry, "unlink.requests = %f/sec\n",
1293 stats.unlink_requests);
1294 storeAppendPrintf(sentry, "page_faults = %f/sec\n",
1295 stats.page_faults);
1296 storeAppendPrintf(sentry, "select_loops = %f/sec\n",
1297 stats.select_loops);
1298 storeAppendPrintf(sentry, "select_fds = %f/sec\n",
1299 stats.select_fds);
1300 storeAppendPrintf(sentry, "average_select_fd_period = %f/fd\n",
1301 stats.average_select_fd_period / fct);
1302 storeAppendPrintf(sentry, "median_select_fds = %f\n",
1303 stats.median_select_fds / fct);
1304 storeAppendPrintf(sentry, "swap.outs = %f/sec\n",
1305 stats.swap_outs);
1306 storeAppendPrintf(sentry, "swap.ins = %f/sec\n",
1307 stats.swap_ins);
1308 storeAppendPrintf(sentry, "swap.files_cleaned = %f/sec\n",
1309 stats.swap_files_cleaned);
1310 storeAppendPrintf(sentry, "aborted_requests = %f/sec\n",
1311 stats.aborted_requests);
1312
1313 #if USE_POLL
1314 storeAppendPrintf(sentry, "syscalls.polls = %f/sec\n", stats.syscalls_selects);
1315 #elif defined(USE_SELECT) || defined(USE_SELECT_WIN32)
1316 storeAppendPrintf(sentry, "syscalls.selects = %f/sec\n", stats.syscalls_selects);
1317 #endif
1318
1319 storeAppendPrintf(sentry, "syscalls.disk.opens = %f/sec\n", stats.syscalls_disk_opens);
1320 storeAppendPrintf(sentry, "syscalls.disk.closes = %f/sec\n", stats.syscalls_disk_closes);
1321 storeAppendPrintf(sentry, "syscalls.disk.reads = %f/sec\n", stats.syscalls_disk_reads);
1322 storeAppendPrintf(sentry, "syscalls.disk.writes = %f/sec\n", stats.syscalls_disk_writes);
1323 storeAppendPrintf(sentry, "syscalls.disk.seeks = %f/sec\n", stats.syscalls_disk_seeks);
1324 storeAppendPrintf(sentry, "syscalls.disk.unlinks = %f/sec\n", stats.syscalls_disk_unlinks);
1325 storeAppendPrintf(sentry, "syscalls.sock.accepts = %f/sec\n", stats.syscalls_sock_accepts);
1326 storeAppendPrintf(sentry, "syscalls.sock.sockets = %f/sec\n", stats.syscalls_sock_sockets);
1327 storeAppendPrintf(sentry, "syscalls.sock.connects = %f/sec\n", stats.syscalls_sock_connects);
1328 storeAppendPrintf(sentry, "syscalls.sock.binds = %f/sec\n", stats.syscalls_sock_binds);
1329 storeAppendPrintf(sentry, "syscalls.sock.closes = %f/sec\n", stats.syscalls_sock_closes);
1330 storeAppendPrintf(sentry, "syscalls.sock.reads = %f/sec\n", stats.syscalls_sock_reads);
1331 storeAppendPrintf(sentry, "syscalls.sock.writes = %f/sec\n", stats.syscalls_sock_writes);
1332 storeAppendPrintf(sentry, "syscalls.sock.recvfroms = %f/sec\n", stats.syscalls_sock_recvfroms);
1333 storeAppendPrintf(sentry, "syscalls.sock.sendtos = %f/sec\n", stats.syscalls_sock_sendtos);
1334
1335 storeAppendPrintf(sentry, "cpu_time = %f seconds\n", stats.cpu_time);
1336 storeAppendPrintf(sentry, "wall_time = %f seconds\n", stats.wall_time);
1337 storeAppendPrintf(sentry, "cpu_usage = %f%%\n", Math::doublePercent(stats.cpu_time, stats.wall_time));
1338 }
1339
1340 static void
1341 statRegisterWithCacheManager(void)
1342 {
1343 Mgr::RegisterAction("info", "General Runtime Information",
1344 &Mgr::InfoAction::Create, 0, 1);
1345 Mgr::RegisterAction("service_times", "Service Times (Percentiles)",
1346 &Mgr::ServiceTimesAction::Create, 0, 1);
1347 Mgr::RegisterAction("filedescriptors", "Process Filedescriptor Allocation",
1348 fde::DumpStats, 0, 1);
1349 Mgr::RegisterAction("objects", "All Cache Objects", stat_objects_get, 0, 0);
1350 Mgr::RegisterAction("vm_objects", "In-Memory and In-Transit Objects",
1351 stat_vmobjects_get, 0, 0);
1352 Mgr::RegisterAction("io", "Server-side network read() size histograms",
1353 &Mgr::IoAction::Create, 0, 1);
1354 Mgr::RegisterAction("counters", "Traffic and Resource Counters",
1355 &Mgr::CountersAction::Create, 0, 1);
1356 Mgr::RegisterAction("peer_select", "Peer Selection Algorithms",
1357 statPeerSelect, 0, 1);
1358 Mgr::RegisterAction("digest_stats", "Cache Digest and ICP blob",
1359 statDigestBlob, 0, 1);
1360 Mgr::RegisterAction("5min", "5 Minute Average of Counters",
1361 &Mgr::IntervalAction::Create5min, 0, 1);
1362 Mgr::RegisterAction("60min", "60 Minute Average of Counters",
1363 &Mgr::IntervalAction::Create60min, 0, 1);
1364 Mgr::RegisterAction("utilization", "Cache Utilization",
1365 statUtilization, 0, 1);
1366 Mgr::RegisterAction("histograms", "Full Histogram Counts",
1367 statCountersHistograms, 0, 1);
1368 Mgr::RegisterAction("active_requests",
1369 "Client-side Active Requests",
1370 statClientRequests, 0, 1);
1371 #if USE_AUTH
1372 Mgr::RegisterAction("username_cache",
1373 "Active Cached Usernames",
1374 Auth::User::UsernameCacheStats, 0, 1);
1375 #endif
1376 #if DEBUG_OPENFD
1377 Mgr::RegisterAction("openfd_objects", "Objects with Swapout files open",
1378 statOpenfdObj, 0, 0);
1379 #endif
1380 #if STAT_GRAPHS
1381 Mgr::RegisterAction("graph_variables", "Display cache metrics graphically",
1382 statGraphDump, 0, 1);
1383 #endif
1384 }
1385
1386 void
1387 statInit(void)
1388 {
1389 int i;
1390 debugs(18, 5, "statInit: Initializing...");
1391
1392 for (i = 0; i < N_COUNT_HIST; ++i)
1393 statCountersInit(&CountHist[i]);
1394
1395 for (i = 0; i < N_COUNT_HOUR_HIST; ++i)
1396 statCountersInit(&CountHourHist[i]);
1397
1398 statCountersInit(&statCounter);
1399
1400 eventAdd("statAvgTick", statAvgTick, NULL, (double) COUNT_INTERVAL, 1);
1401
1402 ClientActiveRequests.head = NULL;
1403
1404 ClientActiveRequests.tail = NULL;
1405
1406 statRegisterWithCacheManager();
1407 }
1408
1409 static void
1410 statAvgTick(void *notused)
1411 {
1412 StatCounters *t = &CountHist[0];
1413 StatCounters *p = &CountHist[1];
1414 StatCounters *c = &statCounter;
1415
1416 struct rusage rusage;
1417 eventAdd("statAvgTick", statAvgTick, NULL, (double) COUNT_INTERVAL, 1);
1418 squid_getrusage(&rusage);
1419 c->page_faults = rusage_pagefaults(&rusage);
1420 c->cputime = rusage_cputime(&rusage);
1421 c->timestamp = current_time;
1422 /* even if NCountHist is small, we already Init()ed the tail */
1423 statCountersClean(CountHist + N_COUNT_HIST - 1);
1424 memmove(p, t, (N_COUNT_HIST - 1) * sizeof(StatCounters));
1425 statCountersCopy(t, c);
1426 ++NCountHist;
1427
1428 if ((NCountHist % COUNT_INTERVAL) == 0) {
1429 /* we have an hours worth of readings. store previous hour */
1430 StatCounters *t2 = &CountHourHist[0];
1431 StatCounters *p2 = &CountHourHist[1];
1432 StatCounters *c2 = &CountHist[N_COUNT_HIST - 1];
1433 statCountersClean(CountHourHist + N_COUNT_HOUR_HIST - 1);
1434 memmove(p2, t2, (N_COUNT_HOUR_HIST - 1) * sizeof(StatCounters));
1435 statCountersCopy(t2, c2);
1436 ++NCountHourHist;
1437 }
1438
1439 if (Config.warnings.high_rptm > 0) {
1440 int i = (int) statPctileSvc(0.5, 20, PCTILE_HTTP);
1441
1442 if (Config.warnings.high_rptm < i)
1443 debugs(18, DBG_CRITICAL, "WARNING: Median response time is " << i << " milliseconds");
1444 }
1445
1446 if (Config.warnings.high_pf) {
1447 int i = (CountHist[0].page_faults - CountHist[1].page_faults);
1448 double dt = tvSubDsec(CountHist[0].timestamp, CountHist[1].timestamp);
1449
1450 if (i > 0 && dt > 0.0) {
1451 i /= (int) dt;
1452
1453 if (Config.warnings.high_pf < i)
1454 debugs(18, DBG_CRITICAL, "WARNING: Page faults occuring at " << i << "/sec");
1455 }
1456 }
1457
1458 if (Config.warnings.high_memory) {
1459 size_t i = 0;
1460 #if HAVE_MSTATS && HAVE_GNUMALLOC_H
1461
1462 struct mstats ms = mstats();
1463 i = ms.bytes_total;
1464 #elif HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
1465
1466 struct mallinfo mp = mallinfo();
1467 i = mp.arena;
1468 #elif HAVE_SBRK
1469
1470 i = (size_t) ((char *) sbrk(0) - (char *) sbrk_start);
1471 #endif
1472
1473 if (Config.warnings.high_memory < i)
1474 debugs(18, DBG_CRITICAL, "WARNING: Memory usage at " << ((unsigned long int)(i >> 20)) << " MB");
1475 }
1476 }
1477
1478 static void
1479 statCountersInit(StatCounters * C)
1480 {
1481 assert(C);
1482 memset(C, 0, sizeof(*C));
1483 C->timestamp = current_time;
1484 statCountersInitSpecial(C);
1485 }
1486
1487 /* add special cases here as they arrive */
1488 static void
1489 statCountersInitSpecial(StatCounters * C)
1490 {
1491 /*
1492 * HTTP svc_time hist is kept in milli-seconds; max of 3 hours.
1493 */
1494 C->client_http.allSvcTime.logInit(300, 0.0, 3600000.0 * 3.0);
1495 C->client_http.missSvcTime.logInit(300, 0.0, 3600000.0 * 3.0);
1496 C->client_http.nearMissSvcTime.logInit(300, 0.0, 3600000.0 * 3.0);
1497 C->client_http.nearHitSvcTime.logInit(300, 0.0, 3600000.0 * 3.0);
1498 C->client_http.hitSvcTime.logInit(300, 0.0, 3600000.0 * 3.0);
1499 /*
1500 * ICP svc_time hist is kept in micro-seconds; max of 1 minute.
1501 */
1502 C->icp.querySvcTime.logInit(300, 0.0, 1000000.0 * 60.0);
1503 C->icp.replySvcTime.logInit(300, 0.0, 1000000.0 * 60.0);
1504 /*
1505 * DNS svc_time hist is kept in milli-seconds; max of 10 minutes.
1506 */
1507 C->dns.svcTime.logInit(300, 0.0, 60000.0 * 10.0);
1508 /*
1509 * Cache Digest Stuff
1510 */
1511 C->cd.on_xition_count.enumInit(CacheDigestHashFuncCount);
1512 C->comm_udp_incoming.enumInit(INCOMING_UDP_MAX);
1513 C->comm_dns_incoming.enumInit(INCOMING_DNS_MAX);
1514 C->comm_tcp_incoming.enumInit(INCOMING_TCP_MAX);
1515 C->select_fds_hist.enumInit(256); /* was SQUID_MAXFD, but it is way too much. It is OK to crop this statistics */
1516 }
1517
1518 /* add special cases here as they arrive */
1519 static void
1520 statCountersClean(StatCounters * C)
1521 {
1522 assert(C);
1523 C->client_http.allSvcTime.clear();
1524 C->client_http.missSvcTime.clear();
1525 C->client_http.nearMissSvcTime.clear();
1526 C->client_http.nearHitSvcTime.clear();
1527 C->client_http.hitSvcTime.clear();
1528 C->icp.querySvcTime.clear();
1529 C->icp.replySvcTime.clear();
1530 C->dns.svcTime.clear();
1531 C->cd.on_xition_count.clear();
1532 C->comm_udp_incoming.clear();
1533 C->comm_dns_incoming.clear();
1534 C->comm_tcp_incoming.clear();
1535 C->select_fds_hist.clear();
1536 }
1537
1538 /* add special cases here as they arrive */
1539 static void
1540 statCountersCopy(StatCounters * dest, const StatCounters * orig)
1541 {
1542 assert(dest && orig);
1543 /* this should take care of all the fields, but "special" ones */
1544 memcpy(dest, orig, sizeof(*dest));
1545 /* prepare space where to copy special entries */
1546 statCountersInitSpecial(dest);
1547 /* now handle special cases */
1548 /* note: we assert that histogram capacities do not change */
1549 dest->client_http.allSvcTime=orig->client_http.allSvcTime;
1550 dest->client_http.missSvcTime=orig->client_http.missSvcTime;
1551 dest->client_http.nearMissSvcTime=orig->client_http.nearMissSvcTime;
1552 dest->client_http.nearHitSvcTime=orig->client_http.nearHitSvcTime;
1553
1554 dest->client_http.hitSvcTime=orig->client_http.hitSvcTime;
1555 dest->icp.querySvcTime=orig->icp.querySvcTime;
1556 dest->icp.replySvcTime=orig->icp.replySvcTime;
1557 dest->dns.svcTime=orig->dns.svcTime;
1558 dest->cd.on_xition_count=orig->cd.on_xition_count;
1559 dest->comm_udp_incoming=orig->comm_udp_incoming;
1560 dest->comm_dns_incoming=orig->comm_dns_incoming;
1561 dest->comm_tcp_incoming=orig->comm_tcp_incoming;
1562 dest->select_fds_hist=orig->select_fds_hist;
1563 }
1564
1565 static void
1566 statCountersHistograms(StoreEntry * sentry)
1567 {
1568 storeAppendPrintf(sentry, "client_http.allSvcTime histogram:\n");
1569 statCounter.client_http.allSvcTime.dump(sentry, NULL);
1570 storeAppendPrintf(sentry, "client_http.missSvcTime histogram:\n");
1571 statCounter.client_http.missSvcTime.dump(sentry, NULL);
1572 storeAppendPrintf(sentry, "client_http.nearMissSvcTime histogram:\n");
1573 statCounter.client_http.nearMissSvcTime.dump(sentry, NULL);
1574 storeAppendPrintf(sentry, "client_http.nearHitSvcTime histogram:\n");
1575 statCounter.client_http.nearHitSvcTime.dump(sentry, NULL);
1576 storeAppendPrintf(sentry, "client_http.hitSvcTime histogram:\n");
1577 statCounter.client_http.hitSvcTime.dump(sentry, NULL);
1578 storeAppendPrintf(sentry, "icp.querySvcTime histogram:\n");
1579 statCounter.icp.querySvcTime.dump(sentry, NULL);
1580 storeAppendPrintf(sentry, "icp.replySvcTime histogram:\n");
1581 statCounter.icp.replySvcTime.dump(sentry, NULL);
1582 storeAppendPrintf(sentry, "dns.svc_time histogram:\n");
1583 statCounter.dns.svcTime.dump(sentry, NULL);
1584 storeAppendPrintf(sentry, "select_fds_hist histogram:\n");
1585 statCounter.select_fds_hist.dump(sentry, NULL);
1586 }
1587
1588 static void
1589 statCountersDump(StoreEntry * sentry)
1590 {
1591 Mgr::CountersActionData stats;
1592 GetCountersStats(stats);
1593 DumpCountersStats(stats, sentry);
1594 }
1595
1596 void
1597 GetCountersStats(Mgr::CountersActionData& stats)
1598 {
1599 StatCounters *f = &statCounter;
1600
1601 struct rusage rusage;
1602 squid_getrusage(&rusage);
1603 f->page_faults = rusage_pagefaults(&rusage);
1604 f->cputime = rusage_cputime(&rusage);
1605
1606 stats.sample_time = f->timestamp;
1607 stats.client_http_requests = f->client_http.requests;
1608 stats.client_http_hits = f->client_http.hits;
1609 stats.client_http_errors = f->client_http.errors;
1610 stats.client_http_kbytes_in = f->client_http.kbytes_in.kb;
1611 stats.client_http_kbytes_out = f->client_http.kbytes_out.kb;
1612 stats.client_http_hit_kbytes_out = f->client_http.hit_kbytes_out.kb;
1613
1614 stats.server_all_requests = f->server.all.requests;
1615 stats.server_all_errors = f->server.all.errors;
1616 stats.server_all_kbytes_in = f->server.all.kbytes_in.kb;
1617 stats.server_all_kbytes_out = f->server.all.kbytes_out.kb;
1618
1619 stats.server_http_requests = f->server.http.requests;
1620 stats.server_http_errors = f->server.http.errors;
1621 stats.server_http_kbytes_in = f->server.http.kbytes_in.kb;
1622 stats.server_http_kbytes_out = f->server.http.kbytes_out.kb;
1623
1624 stats.server_ftp_requests = f->server.ftp.requests;
1625 stats.server_ftp_errors = f->server.ftp.errors;
1626 stats.server_ftp_kbytes_in = f->server.ftp.kbytes_in.kb;
1627 stats.server_ftp_kbytes_out = f->server.ftp.kbytes_out.kb;
1628
1629 stats.server_other_requests = f->server.other.requests;
1630 stats.server_other_errors = f->server.other.errors;
1631 stats.server_other_kbytes_in = f->server.other.kbytes_in.kb;
1632 stats.server_other_kbytes_out = f->server.other.kbytes_out.kb;
1633
1634 stats.icp_pkts_sent = f->icp.pkts_sent;
1635 stats.icp_pkts_recv = f->icp.pkts_recv;
1636 stats.icp_queries_sent = f->icp.queries_sent;
1637 stats.icp_replies_sent = f->icp.replies_sent;
1638 stats.icp_queries_recv = f->icp.queries_recv;
1639 stats.icp_replies_recv = f->icp.replies_recv;
1640 stats.icp_query_timeouts = f->icp.query_timeouts;
1641 stats.icp_replies_queued = f->icp.replies_queued;
1642 stats.icp_kbytes_sent = f->icp.kbytes_sent.kb;
1643 stats.icp_kbytes_recv = f->icp.kbytes_recv.kb;
1644 stats.icp_q_kbytes_sent = f->icp.q_kbytes_sent.kb;
1645 stats.icp_r_kbytes_sent = f->icp.r_kbytes_sent.kb;
1646 stats.icp_q_kbytes_recv = f->icp.q_kbytes_recv.kb;
1647 stats.icp_r_kbytes_recv = f->icp.r_kbytes_recv.kb;
1648
1649 #if USE_CACHE_DIGESTS
1650
1651 stats.icp_times_used = f->icp.times_used;
1652 stats.cd_times_used = f->cd.times_used;
1653 stats.cd_msgs_sent = f->cd.msgs_sent;
1654 stats.cd_msgs_recv = f->cd.msgs_recv;
1655 stats.cd_memory = f->cd.memory.kb;
1656 stats.cd_local_memory = store_digest ? store_digest->mask_size / 1024 : 0;
1657 stats.cd_kbytes_sent = f->cd.kbytes_sent.kb;
1658 stats.cd_kbytes_recv = f->cd.kbytes_recv.kb;
1659 #endif
1660
1661 stats.unlink_requests = f->unlink.requests;
1662 stats.page_faults = f->page_faults;
1663 stats.select_loops = f->select_loops;
1664 stats.cpu_time = f->cputime;
1665 stats.wall_time = tvSubDsec(f->timestamp, current_time);
1666 stats.swap_outs = f->swap.outs;
1667 stats.swap_ins = f->swap.ins;
1668 stats.swap_files_cleaned = f->swap.files_cleaned;
1669 stats.aborted_requests = f->aborted_requests;
1670 }
1671
1672 void
1673 DumpCountersStats(Mgr::CountersActionData& stats, StoreEntry* sentry)
1674 {
1675 storeAppendPrintf(sentry, "sample_time = %d.%d (%s)\n",
1676 (int) stats.sample_time.tv_sec,
1677 (int) stats.sample_time.tv_usec,
1678 mkrfc1123(stats.sample_time.tv_sec));
1679 storeAppendPrintf(sentry, "client_http.requests = %.0f\n",
1680 stats.client_http_requests);
1681 storeAppendPrintf(sentry, "client_http.hits = %.0f\n",
1682 stats.client_http_hits);
1683 storeAppendPrintf(sentry, "client_http.errors = %.0f\n",
1684 stats.client_http_errors);
1685 storeAppendPrintf(sentry, "client_http.kbytes_in = %.0f\n",
1686 stats.client_http_kbytes_in);
1687 storeAppendPrintf(sentry, "client_http.kbytes_out = %.0f\n",
1688 stats.client_http_kbytes_out);
1689 storeAppendPrintf(sentry, "client_http.hit_kbytes_out = %.0f\n",
1690 stats.client_http_hit_kbytes_out);
1691
1692 storeAppendPrintf(sentry, "server.all.requests = %.0f\n",
1693 stats.server_all_requests);
1694 storeAppendPrintf(sentry, "server.all.errors = %.0f\n",
1695 stats.server_all_errors);
1696 storeAppendPrintf(sentry, "server.all.kbytes_in = %.0f\n",
1697 stats.server_all_kbytes_in);
1698 storeAppendPrintf(sentry, "server.all.kbytes_out = %.0f\n",
1699 stats.server_all_kbytes_out);
1700
1701 storeAppendPrintf(sentry, "server.http.requests = %.0f\n",
1702 stats.server_http_requests);
1703 storeAppendPrintf(sentry, "server.http.errors = %.0f\n",
1704 stats.server_http_errors);
1705 storeAppendPrintf(sentry, "server.http.kbytes_in = %.0f\n",
1706 stats.server_http_kbytes_in);
1707 storeAppendPrintf(sentry, "server.http.kbytes_out = %.0f\n",
1708 stats.server_http_kbytes_out);
1709
1710 storeAppendPrintf(sentry, "server.ftp.requests = %.0f\n",
1711 stats.server_ftp_requests);
1712 storeAppendPrintf(sentry, "server.ftp.errors = %.0f\n",
1713 stats.server_ftp_errors);
1714 storeAppendPrintf(sentry, "server.ftp.kbytes_in = %.0f\n",
1715 stats.server_ftp_kbytes_in);
1716 storeAppendPrintf(sentry, "server.ftp.kbytes_out = %.0f\n",
1717 stats.server_ftp_kbytes_out);
1718
1719 storeAppendPrintf(sentry, "server.other.requests = %.0f\n",
1720 stats.server_other_requests);
1721 storeAppendPrintf(sentry, "server.other.errors = %.0f\n",
1722 stats.server_other_errors);
1723 storeAppendPrintf(sentry, "server.other.kbytes_in = %.0f\n",
1724 stats.server_other_kbytes_in);
1725 storeAppendPrintf(sentry, "server.other.kbytes_out = %.0f\n",
1726 stats.server_other_kbytes_out);
1727
1728 storeAppendPrintf(sentry, "icp.pkts_sent = %.0f\n",
1729 stats.icp_pkts_sent);
1730 storeAppendPrintf(sentry, "icp.pkts_recv = %.0f\n",
1731 stats.icp_pkts_recv);
1732 storeAppendPrintf(sentry, "icp.queries_sent = %.0f\n",
1733 stats.icp_queries_sent);
1734 storeAppendPrintf(sentry, "icp.replies_sent = %.0f\n",
1735 stats.icp_replies_sent);
1736 storeAppendPrintf(sentry, "icp.queries_recv = %.0f\n",
1737 stats.icp_queries_recv);
1738 storeAppendPrintf(sentry, "icp.replies_recv = %.0f\n",
1739 stats.icp_replies_recv);
1740 storeAppendPrintf(sentry, "icp.query_timeouts = %.0f\n",
1741 stats.icp_query_timeouts);
1742 storeAppendPrintf(sentry, "icp.replies_queued = %.0f\n",
1743 stats.icp_replies_queued);
1744 storeAppendPrintf(sentry, "icp.kbytes_sent = %.0f\n",
1745 stats.icp_kbytes_sent);
1746 storeAppendPrintf(sentry, "icp.kbytes_recv = %.0f\n",
1747 stats.icp_kbytes_recv);
1748 storeAppendPrintf(sentry, "icp.q_kbytes_sent = %.0f\n",
1749 stats.icp_q_kbytes_sent);
1750 storeAppendPrintf(sentry, "icp.r_kbytes_sent = %.0f\n",
1751 stats.icp_r_kbytes_sent);
1752 storeAppendPrintf(sentry, "icp.q_kbytes_recv = %.0f\n",
1753 stats.icp_q_kbytes_recv);
1754 storeAppendPrintf(sentry, "icp.r_kbytes_recv = %.0f\n",
1755 stats.icp_r_kbytes_recv);
1756
1757 #if USE_CACHE_DIGESTS
1758
1759 storeAppendPrintf(sentry, "icp.times_used = %.0f\n",
1760 stats.icp_times_used);
1761 storeAppendPrintf(sentry, "cd.times_used = %.0f\n",
1762 stats.cd_times_used);
1763 storeAppendPrintf(sentry, "cd.msgs_sent = %.0f\n",
1764 stats.cd_msgs_sent);
1765 storeAppendPrintf(sentry, "cd.msgs_recv = %.0f\n",
1766 stats.cd_msgs_recv);
1767 storeAppendPrintf(sentry, "cd.memory = %.0f\n",
1768 stats.cd_memory);
1769 storeAppendPrintf(sentry, "cd.local_memory = %.0f\n",
1770 stats.cd_local_memory);
1771 storeAppendPrintf(sentry, "cd.kbytes_sent = %.0f\n",
1772 stats.cd_kbytes_sent);
1773 storeAppendPrintf(sentry, "cd.kbytes_recv = %.0f\n",
1774 stats.cd_kbytes_recv);
1775 #endif
1776
1777 storeAppendPrintf(sentry, "unlink.requests = %.0f\n",
1778 stats.unlink_requests);
1779 storeAppendPrintf(sentry, "page_faults = %.0f\n",
1780 stats.page_faults);
1781 storeAppendPrintf(sentry, "select_loops = %.0f\n",
1782 stats.select_loops);
1783 storeAppendPrintf(sentry, "cpu_time = %f\n",
1784 stats.cpu_time);
1785 storeAppendPrintf(sentry, "wall_time = %f\n",
1786 stats.wall_time);
1787 storeAppendPrintf(sentry, "swap.outs = %.0f\n",
1788 stats.swap_outs);
1789 storeAppendPrintf(sentry, "swap.ins = %.0f\n",
1790 stats.swap_ins);
1791 storeAppendPrintf(sentry, "swap.files_cleaned = %.0f\n",
1792 stats.swap_files_cleaned);
1793 storeAppendPrintf(sentry, "aborted_requests = %.0f\n",
1794 stats.aborted_requests);
1795 }
1796
1797 void
1798 statFreeMemory(void)
1799 {
1800 int i;
1801
1802 for (i = 0; i < N_COUNT_HIST; ++i)
1803 statCountersClean(&CountHist[i]);
1804
1805 for (i = 0; i < N_COUNT_HOUR_HIST; ++i)
1806 statCountersClean(&CountHourHist[i]);
1807 }
1808
1809 static void
1810 statPeerSelect(StoreEntry * sentry)
1811 {
1812 #if USE_CACHE_DIGESTS
1813 StatCounters *f = &statCounter;
1814 peer *peer;
1815 const int tot_used = f->cd.times_used + f->icp.times_used;
1816
1817 /* totals */
1818 cacheDigestGuessStatsReport(&f->cd.guess, sentry, "all peers");
1819 /* per-peer */
1820 storeAppendPrintf(sentry, "\nPer-peer statistics:\n");
1821
1822 for (peer = getFirstPeer(); peer; peer = getNextPeer(peer)) {
1823 if (peer->digest)
1824 peerDigestStatsReport(peer->digest, sentry);
1825 else
1826 storeAppendPrintf(sentry, "\nNo peer digest from %s\n", peer->host);
1827
1828 storeAppendPrintf(sentry, "\n");
1829 }
1830
1831 storeAppendPrintf(sentry, "\nAlgorithm usage:\n");
1832 storeAppendPrintf(sentry, "Cache Digest: %7d (%3d%%)\n",
1833 f->cd.times_used, xpercentInt(f->cd.times_used, tot_used));
1834 storeAppendPrintf(sentry, "Icp: %7d (%3d%%)\n",
1835 f->icp.times_used, xpercentInt(f->icp.times_used, tot_used));
1836 storeAppendPrintf(sentry, "Total: %7d (%3d%%)\n",
1837 tot_used, xpercentInt(tot_used, tot_used));
1838 #else
1839
1840 storeAppendPrintf(sentry, "peer digests are disabled; no stats is available.\n");
1841 #endif
1842 }
1843
1844 static void
1845 statDigestBlob(StoreEntry * sentry)
1846 {
1847 storeAppendPrintf(sentry, "\nCounters:\n");
1848 statCountersDump(sentry);
1849 storeAppendPrintf(sentry, "\n5 Min Averages:\n");
1850 statAvgDump(sentry, 5, 0);
1851 storeAppendPrintf(sentry, "\nHistograms:\n");
1852 statCountersHistograms(sentry);
1853 storeAppendPrintf(sentry, "\nPeer Digests:\n");
1854 statPeerSelect(sentry);
1855 storeAppendPrintf(sentry, "\nLocal Digest:\n");
1856 storeDigestReport(sentry);
1857 }
1858
1859 static double
1860 statPctileSvc(double pctile, int interval, int which)
1861 {
1862 StatCounters *f;
1863 StatCounters *l;
1864 double x;
1865 assert(interval > 0);
1866
1867 if (interval > N_COUNT_HIST - 1)
1868 interval = N_COUNT_HIST - 1;
1869
1870 f = &CountHist[0];
1871
1872 l = &CountHist[interval];
1873
1874 assert(f);
1875
1876 assert(l);
1877
1878 switch (which) {
1879
1880 case PCTILE_HTTP:
1881 x = statHistDeltaPctile(l->client_http.allSvcTime,f->client_http.allSvcTime, pctile);
1882 break;
1883
1884 case PCTILE_HIT:
1885 x = statHistDeltaPctile(l->client_http.hitSvcTime,f->client_http.hitSvcTime, pctile);
1886 break;
1887
1888 case PCTILE_MISS:
1889 x = statHistDeltaPctile(l->client_http.missSvcTime,f->client_http.missSvcTime, pctile);
1890 break;
1891
1892 case PCTILE_NM:
1893 x = statHistDeltaPctile(l->client_http.nearMissSvcTime,f->client_http.nearMissSvcTime, pctile);
1894 break;
1895
1896 case PCTILE_NH:
1897 x = statHistDeltaPctile(l->client_http.nearHitSvcTime,f->client_http.nearHitSvcTime, pctile);
1898 break;
1899
1900 case PCTILE_ICP_QUERY:
1901 x = statHistDeltaPctile(l->icp.querySvcTime,f->icp.querySvcTime, pctile);
1902 break;
1903
1904 case PCTILE_DNS:
1905 x = statHistDeltaPctile(l->dns.svcTime,f->dns.svcTime, pctile);
1906 break;
1907
1908 default:
1909 debugs(49, 5, "statPctileSvc: unknown type.");
1910 x = 0;
1911 }
1912
1913 return x;
1914 }
1915
1916 StatCounters *
1917 snmpStatGet(int minutes)
1918 {
1919 return &CountHist[minutes];
1920 }
1921
1922 int
1923 stat5minClientRequests(void)
1924 {
1925 assert(N_COUNT_HIST > 5);
1926 return statCounter.client_http.requests - CountHist[5].client_http.requests;
1927 }
1928
1929 static double
1930 statCPUUsage(int minutes)
1931 {
1932 assert(minutes < N_COUNT_HIST);
1933 return Math::doublePercent(CountHist[0].cputime - CountHist[minutes].cputime,
1934 tvSubDsec(CountHist[minutes].timestamp, CountHist[0].timestamp));
1935 }
1936
1937 extern double
1938 statRequestHitRatio(int minutes)
1939 {
1940 assert(minutes < N_COUNT_HIST);
1941 return Math::doublePercent(CountHist[0].client_http.hits -
1942 CountHist[minutes].client_http.hits,
1943 CountHist[0].client_http.requests -
1944 CountHist[minutes].client_http.requests);
1945 }
1946
1947 extern double
1948 statRequestHitMemoryRatio(int minutes)
1949 {
1950 assert(minutes < N_COUNT_HIST);
1951 return Math::doublePercent(CountHist[0].client_http.mem_hits -
1952 CountHist[minutes].client_http.mem_hits,
1953 CountHist[0].client_http.hits -
1954 CountHist[minutes].client_http.hits);
1955 }
1956
1957 extern double
1958 statRequestHitDiskRatio(int minutes)
1959 {
1960 assert(minutes < N_COUNT_HIST);
1961 return Math::doublePercent(CountHist[0].client_http.disk_hits -
1962 CountHist[minutes].client_http.disk_hits,
1963 CountHist[0].client_http.hits -
1964 CountHist[minutes].client_http.hits);
1965 }
1966
1967 extern double
1968 statByteHitRatio(int minutes)
1969 {
1970 size_t s;
1971 size_t c;
1972 #if USE_CACHE_DIGESTS
1973
1974 size_t cd;
1975 #endif
1976 /* size_t might be unsigned */
1977 assert(minutes < N_COUNT_HIST);
1978 c = CountHist[0].client_http.kbytes_out.kb - CountHist[minutes].client_http.kbytes_out.kb;
1979 s = CountHist[0].server.all.kbytes_in.kb - CountHist[minutes].server.all.kbytes_in.kb;
1980 #if USE_CACHE_DIGESTS
1981 /*
1982 * This ugly hack is here to prevent the user from seeing a
1983 * negative byte hit ratio. When we fetch a cache digest from
1984 * a neighbor, it gets treated like a cache miss because the
1985 * object is consumed internally. Thus, we subtract cache
1986 * digest bytes out before calculating the byte hit ratio.
1987 */
1988 cd = CountHist[0].cd.kbytes_recv.kb - CountHist[minutes].cd.kbytes_recv.kb;
1989
1990 if (s < cd)
1991 debugs(18, DBG_IMPORTANT, "STRANGE: srv_kbytes=" << s << ", cd_kbytes=" << cd);
1992
1993 s -= cd;
1994
1995 #endif
1996
1997 if (c > s)
1998 return Math::doublePercent(c - s, c);
1999 else
2000 return (-1.0 * Math::doublePercent(s - c, c));
2001 }
2002
2003 static void
2004 statClientRequests(StoreEntry * s)
2005 {
2006 dlink_node *i;
2007 ClientHttpRequest *http;
2008 StoreEntry *e;
2009 char buf[MAX_IPSTRLEN];
2010
2011 for (i = ClientActiveRequests.head; i; i = i->next) {
2012 const char *p = NULL;
2013 http = static_cast<ClientHttpRequest *>(i->data);
2014 assert(http);
2015 ConnStateData * conn = http->getConn();
2016 storeAppendPrintf(s, "Connection: %p\n", conn);
2017
2018 if (conn != NULL) {
2019 const int fd = conn->clientConnection->fd;
2020 storeAppendPrintf(s, "\tFD %d, read %" PRId64 ", wrote %" PRId64 "\n", fd,
2021 fd_table[fd].bytes_read, fd_table[fd].bytes_written);
2022 storeAppendPrintf(s, "\tFD desc: %s\n", fd_table[fd].desc);
2023 storeAppendPrintf(s, "\tin: buf %p, offset %ld, size %ld\n",
2024 conn->in.buf, (long int) conn->in.notYetUsed, (long int) conn->in.allocatedSize);
2025 storeAppendPrintf(s, "\tremote: %s\n",
2026 conn->clientConnection->remote.ToURL(buf,MAX_IPSTRLEN));
2027 storeAppendPrintf(s, "\tlocal: %s\n",
2028 conn->clientConnection->local.ToURL(buf,MAX_IPSTRLEN));
2029 storeAppendPrintf(s, "\tnrequests: %d\n",
2030 conn->nrequests);
2031 }
2032
2033 storeAppendPrintf(s, "uri %s\n", http->uri);
2034 storeAppendPrintf(s, "logType %s\n", Format::log_tags[http->logType]);
2035 storeAppendPrintf(s, "out.offset %ld, out.size %lu\n",
2036 (long int) http->out.offset, (unsigned long int) http->out.size);
2037 storeAppendPrintf(s, "req_sz %ld\n", (long int) http->req_sz);
2038 e = http->storeEntry();
2039 storeAppendPrintf(s, "entry %p/%s\n", e, e ? e->getMD5Text() : "N/A");
2040 #if 0
2041 /* Not a member anymore */
2042 e = http->old_entry;
2043 storeAppendPrintf(s, "old_entry %p/%s\n", e, e ? e->getMD5Text() : "N/A");
2044 #endif
2045
2046 storeAppendPrintf(s, "start %ld.%06d (%f seconds ago)\n",
2047 (long int) http->start_time.tv_sec,
2048 (int) http->start_time.tv_usec,
2049 tvSubDsec(http->start_time, current_time));
2050 #if USE_AUTH
2051 if (http->request->auth_user_request != NULL)
2052 p = http->request->auth_user_request->username();
2053 else
2054 #endif
2055 if (http->request->extacl_user.defined()) {
2056 p = http->request->extacl_user.termedBuf();
2057 }
2058
2059 if (!p && conn != NULL && conn->clientConnection->rfc931[0])
2060 p = conn->clientConnection->rfc931;
2061
2062 #if USE_SSL
2063
2064 if (!p && conn != NULL && Comm::IsConnOpen(conn->clientConnection))
2065 p = sslGetUserEmail(fd_table[conn->clientConnection->fd].ssl);
2066
2067 #endif
2068
2069 if (!p)
2070 p = dash_str;
2071
2072 storeAppendPrintf(s, "username %s\n", p);
2073
2074 #if USE_DELAY_POOLS
2075 storeAppendPrintf(s, "delay_pool %d\n", DelayId::DelayClient(http).pool());
2076 #endif
2077
2078 storeAppendPrintf(s, "\n");
2079 }
2080 }
2081
2082 #if STAT_GRAPHS
2083 /*
2084 * urgh, i don't like these, but they do cut the amount of code down immensely
2085 */
2086
2087 #define GRAPH_PER_MIN(Y) \
2088 for (i=0;i<(N_COUNT_HIST-2);++i) { \
2089 dt = tvSubDsec(CountHist[i+1].timestamp, CountHist[i].timestamp); \
2090 if (dt <= 0.0) \
2091 break; \
2092 storeAppendPrintf(e, "%lu,%0.2f:", \
2093 CountHist[i].timestamp.tv_sec, \
2094 ((CountHist[i].Y - CountHist[i+1].Y) / dt)); \
2095 }
2096
2097 #define GRAPH_PER_HOUR(Y) \
2098 for (i=0;i<(N_COUNT_HOUR_HIST-2);++i) { \
2099 dt = tvSubDsec(CountHourHist[i+1].timestamp, CountHourHist[i].timestamp); \
2100 if (dt <= 0.0) \
2101 break; \
2102 storeAppendPrintf(e, "%lu,%0.2f:", \
2103 CountHourHist[i].timestamp.tv_sec, \
2104 ((CountHourHist[i].Y - CountHourHist[i+1].Y) / dt)); \
2105 }
2106
2107 #define GRAPH_TITLE(X,Y) storeAppendPrintf(e,"%s\t%s\t",X,Y);
2108 #define GRAPH_END storeAppendPrintf(e,"\n");
2109
2110 #define GENGRAPH(X,Y,Z) \
2111 GRAPH_TITLE(Y,Z) \
2112 GRAPH_PER_MIN(X) \
2113 GRAPH_PER_HOUR(X) \
2114 GRAPH_END
2115
2116 static void
2117 statGraphDump(StoreEntry * e)
2118 {
2119 int i;
2120 double dt;
2121
2122 GENGRAPH(client_http.requests, "client_http.requests", "Client HTTP requests/sec");
2123 GENGRAPH(client_http.hits, "client_http.hits", "Client HTTP hits/sec");
2124 GENGRAPH(client_http.errors, "client_http.errors", "Client HTTP errors/sec");
2125 GENGRAPH(client_http.kbytes_in.kb, "client_http.kbytes_in", "Client HTTP kbytes_in/sec");
2126 GENGRAPH(client_http.kbytes_out.kb, "client_http.kbytes_out", "Client HTTP kbytes_out/sec");
2127
2128 /* XXX todo: http median service times */
2129
2130 GENGRAPH(server.all.requests, "server.all.requests", "Server requests/sec");
2131 GENGRAPH(server.all.errors, "server.all.errors", "Server errors/sec");
2132 GENGRAPH(server.all.kbytes_in.kb, "server.all.kbytes_in", "Server total kbytes_in/sec");
2133 GENGRAPH(server.all.kbytes_out.kb, "server.all.kbytes_out", "Server total kbytes_out/sec");
2134
2135 GENGRAPH(server.http.requests, "server.http.requests", "Server HTTP requests/sec");
2136 GENGRAPH(server.http.errors, "server.http.errors", "Server HTTP errors/sec");
2137 GENGRAPH(server.http.kbytes_in.kb, "server.http.kbytes_in", "Server HTTP kbytes_in/sec");
2138 GENGRAPH(server.http.kbytes_out.kb, "server.http.kbytes_out", "Server HTTP kbytes_out/sec");
2139
2140 GENGRAPH(server.ftp.requests, "server.ftp.requests", "Server FTP requests/sec");
2141 GENGRAPH(server.ftp.errors, "server.ftp.errors", "Server FTP errors/sec");
2142 GENGRAPH(server.ftp.kbytes_in.kb, "server.ftp.kbytes_in", "Server FTP kbytes_in/sec");
2143 GENGRAPH(server.ftp.kbytes_out.kb, "server.ftp.kbytes_out", "Server FTP kbytes_out/sec");
2144
2145 GENGRAPH(server.other.requests, "server.other.requests", "Server other requests/sec");
2146 GENGRAPH(server.other.errors, "server.other.errors", "Server other errors/sec");
2147 GENGRAPH(server.other.kbytes_in.kb, "server.other.kbytes_in", "Server other kbytes_in/sec");
2148 GENGRAPH(server.other.kbytes_out.kb, "server.other.kbytes_out", "Server other kbytes_out/sec");
2149
2150 GENGRAPH(icp.pkts_sent, "icp.pkts_sent", "ICP packets sent/sec");
2151 GENGRAPH(icp.pkts_recv, "icp.pkts_recv", "ICP packets received/sec");
2152 GENGRAPH(icp.kbytes_sent.kb, "icp.kbytes_sent", "ICP kbytes_sent/sec");
2153 GENGRAPH(icp.kbytes_recv.kb, "icp.kbytes_recv", "ICP kbytes_received/sec");
2154
2155 /* XXX todo: icp median service times */
2156 /* XXX todo: dns median service times */
2157
2158 GENGRAPH(unlink.requests, "unlink.requests", "Cache File unlink requests/sec");
2159 GENGRAPH(page_faults, "page_faults", "System Page Faults/sec");
2160 GENGRAPH(select_loops, "select_loops", "System Select Loop calls/sec");
2161 GENGRAPH(cputime, "cputime", "CPU utilisation");
2162 }
2163
2164 #endif /* STAT_GRAPHS */
2165
2166 int
2167 statMemoryAccounted(void)
2168 {
2169 return memPoolsTotalAllocated();
2170 }