2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

Merge statistics code (ATT SoW, rt24117)

This includes the following changes:

3326.	[func]		Added task list statistics: task model, worker
			threads, quantum, tasks running, tasks ready.
			[RT #27678]

3325.	[func]		Report cache statistics: memory use, number of
			nodes, number of hash buckets, hit and miss counts.
			[RT #27056]

3324.	[test]		Add better tests for ADB stats [RT #27057]

3323.	[func]		Report the number of buckets the resolver is using.
			[RT #27020]

3322.	[func]		Monitor the number of active TCP and UDP dispatches.
			[RT #27055]

3321.	[func]		Monitor the number of recursive fetches and the
			number of open sockets, and report these values in
			the statistics channel. [RT #27054]

3320.	[func]		Added support for monitoring of recursing client
			count. [RT #27009]

3319.	[func]		Added support for monitoring of ADB entry count and
			hash size. [RT #27057]
This commit is contained in:
Evan Hunt
2012-05-14 10:06:05 -07:00
parent 4dd8c4517e
commit dd2a0a6d2d
49 changed files with 1576 additions and 91 deletions

View File

@@ -22,7 +22,9 @@
#include <config.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/string.h>
#include <isc/stats.h>
#include <isc/task.h>
#include <isc/time.h>
#include <isc/timer.h>
@@ -39,6 +41,7 @@
#include <dns/rdataset.h>
#include <dns/rdatasetiter.h>
#include <dns/result.h>
#include <dns/stats.h>
#include "rbtdb.h"
@@ -137,6 +140,7 @@ struct dns_cache {
int db_argc;
char **db_argv;
isc_uint32_t size;
isc_stats_t *stats;
/* Locked by 'filelock'. */
char *filename;
@@ -237,10 +241,16 @@ dns_cache_create3(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
cache->live_tasks = 0;
cache->rdclass = rdclass;
cache->stats = NULL;
result = isc_stats_create(cmctx, &cache->stats,
dns_cachestatscounter_max);
if (result != ISC_R_SUCCESS)
goto cleanup_filelock;
cache->db_type = isc_mem_strdup(cmctx, db_type);
if (cache->db_type == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup_filelock;
goto cleanup_stats;
}
/*
@@ -309,6 +319,11 @@ dns_cache_create3(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
if (result != ISC_R_SUCCESS)
goto cleanup_db;
result = dns_db_setcachestats(cache->db, cache->stats);
if (result != ISC_R_SUCCESS)
goto cleanup_db;
*cachep = cache;
return (ISC_R_SUCCESS);
@@ -325,6 +340,8 @@ dns_cache_create3(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
isc_mem_free(cmctx, cache->db_type);
cleanup_filelock:
DESTROYLOCK(&cache->filelock);
cleanup_stats:
isc_stats_detach(&cache->stats);
cleanup_lock:
DESTROYLOCK(&cache->lock);
cleanup_mem:
@@ -387,6 +404,9 @@ cache_free(dns_cache_t *cache) {
if (cache->name != NULL)
isc_mem_free(cache->mctx, cache->name);
if (cache->stats != NULL)
isc_stats_detach(&cache->stats);
DESTROYLOCK(&cache->lock);
DESTROYLOCK(&cache->filelock);
@@ -1279,3 +1299,145 @@ dns_cache_flushnode(dns_cache_t *cache, dns_name_t *name,
dns_db_detach(&db);
return (result);
}
isc_stats_t *
dns_cache_getstats(dns_cache_t *cache) {
REQUIRE(VALID_CACHE(cache));
return (cache->stats);
}
/*
* XXX: Much of the following code has been copied in from statschannel.c.
* We should refactor this into a generic function in stats.c that can be
* called from both places.
*/
typedef struct
cache_dumparg {
isc_statsformat_t type;
void *arg; /* type dependent argument */
int ncounters; /* for general statistics */
int *counterindices; /* for general statistics */
isc_uint64_t *countervalues; /* for general statistics */
isc_result_t result;
} cache_dumparg_t;
static void
getcounter(isc_statscounter_t counter, isc_uint64_t val, void *arg) {
cache_dumparg_t *dumparg = arg;
REQUIRE(counter < dumparg->ncounters);
dumparg->countervalues[counter] = val;
}
static void
getcounters(isc_stats_t *stats, isc_statsformat_t type, int ncounters,
int *indices, isc_uint64_t *values)
{
cache_dumparg_t dumparg;
memset(values, 0, sizeof(values[0]) * ncounters);
dumparg.type = type;
dumparg.ncounters = ncounters;
dumparg.counterindices = indices;
dumparg.countervalues = values;
isc_stats_dump(stats, getcounter, &dumparg, ISC_STATSDUMP_VERBOSE);
}
void
dns_cache_dumpstats(dns_cache_t *cache, FILE *fp) {
int indices[dns_cachestatscounter_max];
isc_uint64_t values[dns_cachestatscounter_max];
REQUIRE(VALID_CACHE(cache));
getcounters(cache->stats, isc_statsformat_file,
dns_cachestatscounter_max, indices, values);
fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n",
values[dns_cachestatscounter_hits],
"cache hits");
fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n",
values[dns_cachestatscounter_misses],
"cache misses");
fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n",
values[dns_cachestatscounter_queryhits],
"cache hits (from query)");
fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n",
values[dns_cachestatscounter_querymisses],
"cache misses (from query)");
fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n",
values[dns_cachestatscounter_deletelru],
"cache records deleted due to memory exhaustion");
fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n",
values[dns_cachestatscounter_deletettl],
"cache records deleted due to TTL expiration");
fprintf(fp, "%20u %s\n", dns_db_nodecount(cache->db),
"cache database nodes");
fprintf(fp, "%20u %s\n", dns_db_hashsize(cache->db),
"cache database hash buckets");
fprintf(fp, "%20u %s\n", (unsigned int) isc_mem_total(cache->mctx),
"cache tree memory total");
fprintf(fp, "%20u %s\n", (unsigned int) isc_mem_inuse(cache->mctx),
"cache tree memory in use");
fprintf(fp, "%20u %s\n", (unsigned int) isc_mem_maxinuse(cache->mctx),
"cache tree highest memory in use");
fprintf(fp, "%20u %s\n", (unsigned int) isc_mem_total(cache->hmctx),
"cache heap memory total");
fprintf(fp, "%20u %s\n", (unsigned int) isc_mem_inuse(cache->hmctx),
"cache heap memory in use");
fprintf(fp, "%20u %s\n", (unsigned int) isc_mem_maxinuse(cache->hmctx),
"cache heap highest memory in use");
}
#ifdef HAVE_LIBXML2
static void
renderstat(const char *name, isc_uint64_t value, xmlTextWriterPtr writer) {
xmlTextWriterStartElement(writer, ISC_XMLCHAR "cachestat");
xmlTextWriterStartElement(writer, ISC_XMLCHAR "name");
xmlTextWriterWriteString(writer, ISC_XMLCHAR name);
xmlTextWriterEndElement(writer); /* name */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "value");
xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u", value);
xmlTextWriterEndElement(writer); /* value */
xmlTextWriterEndElement(writer); /* cachestat */
}
void
dns_cache_renderxml(dns_cache_t *cache, xmlTextWriterPtr writer) {
int indices[dns_cachestatscounter_max];
isc_uint64_t values[dns_cachestatscounter_max];
REQUIRE(VALID_CACHE(cache));
getcounters(cache->stats, isc_statsformat_file,
dns_cachestatscounter_max, indices, values);
renderstat("CacheHits",
values[dns_cachestatscounter_hits], writer);
renderstat("CacheMisses",
values[dns_cachestatscounter_misses], writer);
renderstat("QueryHits",
values[dns_cachestatscounter_queryhits], writer);
renderstat("QueryMisses",
values[dns_cachestatscounter_querymisses], writer);
renderstat("DeleteLRU",
values[dns_cachestatscounter_deletelru], writer);
renderstat("DeleteTTL",
values[dns_cachestatscounter_deletettl], writer);
renderstat("CacheNodes", dns_db_nodecount(cache->db), writer);
renderstat("CacheBuckets", dns_db_hashsize(cache->db), writer);
renderstat("TreeMemTotal", isc_mem_total(cache->mctx), writer);
renderstat("TreeMemInUse", isc_mem_inuse(cache->mctx), writer);
renderstat("TreeMemMax", isc_mem_maxinuse(cache->mctx), writer);
renderstat("HeapMemTotal", isc_mem_total(cache->hmctx), writer);
renderstat("HeapMemInUse", isc_mem_inuse(cache->hmctx), writer);
renderstat("HeapMemMax", isc_mem_maxinuse(cache->hmctx), writer);
}
#endif