Commit 31eef7e2 authored by Michael Sawyer's avatar Michael Sawyer
Browse files

Use lowercase names for stats

statistic printing code cleanup
move some of the statistics stufdf to the server object
parent 964c3f4a
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: globals.h,v 1.48 2000/11/07 23:49:20 mws Exp $ */
/* $Id: globals.h,v 1.49 2000/11/09 19:55:19 mws Exp $ */
#ifndef NAMED_GLOBALS_H
#define NAMED_GLOBALS_H 1
......@@ -35,11 +35,9 @@
#ifdef NS_MAIN
#define EXTERN
#define INIT(v) = (v)
#define ARRAYINIT = {0,}
#else
#define EXTERN extern
#define INIT(v)
#define ARRAYINIT
#endif
EXTERN isc_mem_t * ns_g_mctx INIT(NULL);
......@@ -97,12 +95,6 @@ EXTERN const char * lwresd_g_defaultpidfile INIT(NS_LOCALSTATEDIR
"/run/lwresd.pid");
EXTERN const char * ns_g_username INIT(NULL);
/*
* Statistical counters.
*/
EXTERN isc_uint64_t ns_globalcount[DNS_ZONE_COUNTSIZE]
ARRAYINIT;
/*
* XXX Temporary.
*/
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: server.h,v 1.43 2000/11/07 23:49:23 mws Exp $ */
/* $Id: server.h,v 1.44 2000/11/09 19:55:20 mws Exp $ */
#ifndef NAMED_SERVER_H
#define NAMED_SERVER_H 1
......@@ -67,6 +67,10 @@ struct ns_server {
isc_event_t * reload_event;
isc_boolean_t flushonshutdown;
char * statsfile;
FILE * statsfp;
isc_uint64_t globalcount[DNS_ZONE_COUNTSIZE];
};
#define NS_SERVER_MAGIC 0x53564552 /* SVER */
......@@ -111,4 +115,8 @@ ns_server_refreshzone(ns_server_t *server, char *args);
isc_result_t
ns_server_dumpstats(ns_server_t *server);
void
ns_server_querycount(dns_zone_t *zone, isc_boolean_t is_zone,
dns_zonecount_t counter);
#endif /* NAMED_SERVER_H */
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: query.c,v 1.142 2000/11/07 23:49:17 mws Exp $ */
/* $Id: query.c,v 1.143 2000/11/09 19:55:16 mws Exp $ */
#include <config.h>
......@@ -101,28 +101,6 @@ query_maybeputqname(ns_client_t *client) {
}
}
static void
query_count(dns_zone_t *zone, isc_boolean_t is_zone,
dns_zonecount_t counter)
{
REQUIRE(counter < DNS_ZONE_COUNTSIZE);
ns_globalcount[counter]++;
if (!is_zone || zone == NULL || !dns_zone_hascounts(zone)) {
isc_log_write(dns_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_QUERY,
1, "global counter %s set to %ld",
dns_zonecount_names[counter],
(long)ns_globalcount[counter]);
return;
}
dns_zone_count(zone, counter);
isc_log_write(dns_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_QUERY,
1, "zone counter %s set to %ld, global %ld",
dns_zonecount_names[counter],
(long)dns_zone_getcounts(zone, counter),
(long)ns_globalcount[counter]);
}
static inline void
query_reset(ns_client_t *client, isc_boolean_t everything) {
isc_buffer_t *dbuf, *dbuf_next;
......@@ -793,7 +771,8 @@ query_simplefind(void *arg, dns_name_t *name, dns_rdatatype_t type,
if (dns_rdataset_isassociated(sigrdataset))
dns_rdataset_disassociate(sigrdataset);
if (is_zone) {
query_count(zone, is_zone, dns_zonecount_delegate);
ns_server_querycount(zone, is_zone,
dns_zonecount_delegate);
if (USECACHE(client)) {
/*
* Either the answer is in the cache, or we
......@@ -858,7 +837,7 @@ query_simplefind(void *arg, dns_name_t *name, dns_rdatatype_t type,
* query counter.
*/
if (result == ISC_R_SUCCESS)
query_count(zone, is_zone, dns_zonecount_success);
ns_server_querycount(zone, is_zone, dns_zonecount_success);
cleanup:
if (dns_rdataset_isassociated(&zrdataset)) {
......@@ -2188,20 +2167,23 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
*/
dbuf = query_getnamebuf(client);
if (dbuf == NULL) {
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
fname = query_newname(client, dbuf, &b);
if (fname == NULL) {
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
tname = dns_fixedname_name(&event->foundname);
result = dns_name_concatenate(tname, NULL, fname, NULL);
if (result != ISC_R_SUCCESS) {
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
......@@ -2224,7 +2206,8 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
result = query_getdb(client, client->query.qname, 0, &zone, &db,
&version, &is_zone);
if (result != ISC_R_SUCCESS) {
query_count(NULL, ISC_FALSE, dns_zonecount_failure);
ns_server_querycount(NULL, ISC_FALSE,
dns_zonecount_failure);
if (result == DNS_R_REFUSED)
QUERY_ERROR(DNS_R_REFUSED);
else
......@@ -2266,7 +2249,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
type = qtype;
else {
CTRACE("find_query: REFUSED: qcount != 1");
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone, dns_zonecount_failure);
QUERY_ERROR(DNS_R_REFUSED);
goto cleanup;
}
......@@ -2277,7 +2260,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
result = query_checktype(qtype);
if (result != ISC_R_SUCCESS) {
CTRACE("find_query: non supported query type");
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone, dns_zonecount_failure);
QUERY_ERROR(result);
goto cleanup;
}
......@@ -2295,7 +2278,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
*/
dbuf = query_getnamebuf(client);
if (dbuf == NULL) {
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone, dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
......@@ -2303,7 +2286,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
rdataset = query_newrdataset(client);
sigrdataset = query_newrdataset(client);
if (fname == NULL || rdataset == NULL || sigrdataset == NULL) {
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone, dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
......@@ -2359,7 +2342,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
result = dns_name_concatenate(client->query.qname,
NULL, fname, NULL);
if (result != ISC_R_SUCCESS) {
query_count(zone, is_zone,
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
......@@ -2378,7 +2361,8 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
CTRACE("query_find: resume");
switch (result) {
case ISC_R_SUCCESS:
query_count(zone, is_zone, dns_zonecount_success);
ns_server_querycount(zone, is_zone,
dns_zonecount_success);
/*
* This case is handled in the main line below.
*/
......@@ -2410,7 +2394,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
*/
INSIST(!is_zone);
INSIST(client->view->hints != NULL);
query_count(zone, is_zone, dns_zonecount_delegate);
ns_server_querycount(zone, is_zone, dns_zonecount_delegate);
if (db != NULL)
dns_db_detach(&db);
dns_db_attach(client->view->hints, &db);
......@@ -2422,7 +2406,8 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
* We can't even find the hints for the root
* nameservers!
*/
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
......@@ -2522,7 +2507,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
/*
* Recurse!
*/
query_count(zone, is_zone,
ns_server_querycount(zone, is_zone,
dns_zonecount_recurse);
if (type == dns_rdatatype_key)
result = query_recurse(client, qtype,
......@@ -2534,7 +2519,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
client->query.attributes |=
NS_QUERYATTR_RECURSING;
else {
query_count(zone, is_zone,
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
}
......@@ -2542,7 +2527,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
/*
* This is the best answer.
*/
query_count(zone, is_zone,
ns_server_querycount(zone, is_zone,
dns_zonecount_delegate);
client->query.gluedb = zdb;
client->query.attributes |=
......@@ -2558,7 +2543,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
goto cleanup;
case DNS_R_NXRRSET:
INSIST(is_zone);
query_count(zone, is_zone, dns_zonecount_nxrrset);
ns_server_querycount(zone, is_zone, dns_zonecount_nxrrset);
if (dns_rdataset_isassociated(rdataset)) {
/*
* If we've got a NXT record, we need to save the
......@@ -2585,7 +2570,8 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
*/
result = query_addsoa(client, db, ISC_FALSE);
if (result != ISC_R_SUCCESS) {
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
QUERY_ERROR(result);
goto cleanup;
}
......@@ -2602,7 +2588,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
goto cleanup;
case DNS_R_NXDOMAIN:
INSIST(is_zone);
query_count(zone, is_zone, dns_zonecount_nxdomain);
ns_server_querycount(zone, is_zone, dns_zonecount_nxdomain);
if (client->query.restarts > 0) {
/*
* We hit a dead end following a CNAME or DNAME.
......@@ -2641,7 +2627,8 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
else
result = query_addsoa(client, db, ISC_FALSE);
if (result != ISC_R_SUCCESS) {
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
QUERY_ERROR(result);
goto cleanup;
}
......@@ -2662,11 +2649,11 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
goto cleanup;
case DNS_R_NCACHENXDOMAIN:
INSIST(!is_zone);
query_count(NULL, is_zone, dns_zonecount_nxdomain);
ns_server_querycount(NULL, is_zone, dns_zonecount_nxdomain);
goto ncachenxrrset;
case DNS_R_NCACHENXRRSET:
INSIST(!is_zone);
query_count(NULL, is_zone, dns_zonecount_nxrrset);
ns_server_querycount(NULL, is_zone, dns_zonecount_nxrrset);
ncachenxrrset:
authoritative = ISC_FALSE;
/*
......@@ -2828,7 +2815,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
/*
* Something has gone wrong.
*/
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone, dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
......@@ -2842,7 +2829,8 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
rdsiter = NULL;
result = dns_db_allrdatasets(db, node, version, 0, &rdsiter);
if (result != ISC_R_SUCCESS) {
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
......@@ -2916,14 +2904,15 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
/*
* Something went wrong.
*/
query_count(zone, is_zone,
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
result = DNS_R_SERVFAIL;
}
}
dns_rdatasetiter_destroy(&rdsiter);
if (result != ISC_R_NOMORE) {
query_count(zone, is_zone, dns_zonecount_failure);
ns_server_querycount(zone, is_zone,
dns_zonecount_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: server.c,v 1.242 2000/11/08 18:57:59 mws Exp $ */
/* $Id: server.c,v 1.243 2000/11/09 19:55:17 mws Exp $ */
#include <config.h>
......@@ -98,9 +98,6 @@ typedef struct {
dns_aclconfctx_t *aclconf;
} ns_load_t;
static char *statsfile = NULL;
FILE *statsfp = NULL;
static void
fatal(const char *msg, isc_result_t result);
......@@ -1301,66 +1298,56 @@ heartbeat_timer_tick(isc_task_t *task, isc_event_t *event) {
}
static void
ns_server_freestatsfile(isc_mem_t *mctx) {
if (statsfile != NULL)
isc_mem_free(mctx,statsfile);
statsfile = NULL;
ns_server_freestatsfile(ns_server_t *serv) {
if (serv->statsfile != NULL)
isc_mem_free(serv->mctx, serv->statsfile);
serv->statsfile = NULL;
}
static void
ns_server_setstatsfile(const char *name, isc_mem_t *mctx) {
ns_server_setstatsfile(const char *name, ns_server_t *serv) {
int len;
ns_server_freestatsfile(mctx);
ns_server_freestatsfile(serv);
len = strlen(name);
statsfile = isc_mem_allocate(mctx, len + 1);
if (statsfile == NULL)
serv->statsfile = isc_mem_allocate(serv->mctx, len + 1);
if (serv->statsfile == NULL)
fatal("allocate memory for server stats", ISC_R_NOMEMORY);
strcpy(statsfile, name);
strcpy(serv->statsfile, name);
}
static isc_result_t
ns_server_openstatsfile(void) {
ns_server_openstatsfile(ns_server_t *serv) {
isc_result_t result;
const char *defname = "named.stats";
union { char *nc;
const char *cc; } deconst;
if (statsfile == NULL)
if (serv->statsfile == NULL)
deconst.cc = defname;
else
deconst.nc = statsfile;
result = isc_stdio_open(deconst.nc, "a", &statsfp);
deconst.nc = serv->statsfile;
result = isc_stdio_open(deconst.nc, "a", &serv->statsfp);
return (result);
}
static isc_result_t
ns_server_closestatsfile(void) {
ns_server_closestatsfile(ns_server_t *serv) {
isc_result_t result = ISC_R_SUCCESS;
if (statsfp != NULL)
result = isc_stdio_close(statsfp);
statsfp = NULL;
if (serv->statsfp != NULL)
result = isc_stdio_close(serv->statsfp);
serv->statsfp = NULL;
return (result);
}
static isc_result_t
ns_server_statsprintf(const char *format, ...) {
char outputbuf[DNS_NAME_MAXTEXT + 64];
/* 64 is a safe estimate for the extra text */
va_list args;
if (statsfp == NULL)
return (ISC_R_FAILURE);
/* XXXMWS Better failure case needed */
va_start(args, format);
vsnprintf(outputbuf, sizeof(outputbuf), format, args);
va_end(args);
isc_stdio_write(outputbuf, strlen(outputbuf), 1, statsfp,
NULL);
return (ISC_R_SUCCESS);
static void
ns_server_zeroglobal(ns_server_t *serv) {
int i;
for (i=0; i<DNS_ZONE_COUNTSIZE; i++)
serv->globalcount[i]=0;
}
static isc_result_t
......@@ -1721,8 +1708,12 @@ load_configuration(const char *filename, ns_server_t *server,
else
ns_os_writepidfile(ns_g_defaultpidfile);
server->statsfile = NULL;
server->statsfp = NULL;
ns_server_zeroglobal(server);
if (dns_c_ctx_getstatsfilename(cctx, &statsfilename) != ISC_R_NOTFOUND)
ns_server_setstatsfile(statsfilename, server->mctx);
ns_server_setstatsfile(statsfilename, server);
dns_aclconfctx_destroy(&aclconfctx);
......@@ -1973,7 +1964,7 @@ ns_server_destroy(ns_server_t **serverp) {
ns_server_t *server = *serverp;
REQUIRE(NS_SERVER_VALID(server));
ns_server_freestatsfile(server->mctx);
ns_server_freestatsfile(server);
dns_loadmgr_detach(&server->loadmgr);
dns_zonemgr_detach(&server->zonemgr);
......@@ -2198,6 +2189,28 @@ ns_listenelt_fromconfig(dns_c_lstnon_t *celt, dns_c_ctx_t *cctx,
return (ISC_R_SUCCESS);
}
void
ns_server_querycount(dns_zone_t *zone, isc_boolean_t is_zone,
dns_zonecount_t counter)
{
REQUIRE(counter < DNS_ZONE_COUNTSIZE);
ns_g_server->globalcount[counter]++;
if (!is_zone || zone == NULL || !dns_zone_hascounts(zone)) {
isc_log_write(dns_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_QUERY,
1, "global counter %s set to %ld",
dns_zonecount_names[counter],
(long)ns_g_server->globalcount[counter]);
return;
}
dns_zone_count(zone, counter);
isc_log_write(dns_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_QUERY,
1, "zone counter %s set to %ld, global %ld",
dns_zonecount_names[counter],
(long)dns_zone_getcounts(zone, counter),
(long)ns_g_server->globalcount[counter]);
}
/*
* Dump the current statistics to a file
*
......@@ -2213,29 +2226,25 @@ ns_server_dumpstats(ns_server_t *server) {
dns_view_t *zoneview = NULL;
char *viewname;
isc_stdtime_t now;
FILE *fp;
int i;
int numbercounters;
isc_stdtime_get(&now);
result = ns_server_openstatsfile();
result = ns_server_openstatsfile(server);
if (result != ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
"Failed to open statistics dump file");
return (result);
}
ns_server_statsprintf("+++ Statistics Dump +++ (%ld)\n",
numbercounters = dns_zone_numbercounters();
fp = server->statsfp;
fprintf(fp,"+++ Statistics Dump +++ (%ld)\n",
(long)now);
ns_server_statsprintf("SUCCESS %ld\n",
ns_globalcount[dns_zonecount_success]);
ns_server_statsprintf("DELEGATED %ld\n",
ns_globalcount[dns_zonecount_delegate]);
ns_server_statsprintf("NXRRSET %ld\n",
ns_globalcount[dns_zonecount_nxrrset]);
ns_server_statsprintf("NXDOMAIN %ld\n",
ns_globalcount[dns_zonecount_nxdomain]);
ns_server_statsprintf("RECURSIVE %ld\n",
ns_globalcount[dns_zonecount_recurse]);
ns_server_statsprintf("FAILED %ld\n",
ns_globalcount[dns_zonecount_failure]);
for (i=0; i<numbercounters; i++)
fprintf(fp,"%s %ld\n",dns_zonecount_names[i],
(long)server->globalcount[i]);
dns_zonemgr_lockconf(server->zonemgr, isc_rwlocktype_read);
dns_zone_first(server->zonemgr, &zone);
while (zone != NULL) {
......@@ -2249,32 +2258,13 @@ ns_server_dumpstats(ns_server_t *server) {
zoneview = dns_zone_getview(zone);
viewname = zoneview->name;
if (dns_zone_hascounts(zone)) {
ns_server_statsprintf("SUCCESS %ld %s:%s\n",
(long)dns_zone_getcounts(zone,
dns_zonecount_success),
viewname, zonestore);
ns_server_statsprintf("DELEGATED %ld %s:%s\n",
(long)dns_zone_getcounts(zone,
dns_zonecount_delegate),
viewname, zonestore);
ns_server_statsprintf("NXRRSET %ld %s:%s\n",
(long)dns_zone_getcounts(zone,
dns_zonecount_nxrrset),
viewname, zonestore);
ns_server_statsprintf("NXDOMAIN %ld %s:%s\n",
(long)dns_zone_getcounts(zone,
dns_zonecount_nxdomain),
viewname, zonestore);
ns_server_statsprintf("RECURSIVE %ld %s:%s\n",
(long)dns_zone_getcounts(zone,
dns_zonecount_recurse),
viewname, zonestore);
ns_server_statsprintf("FAILED %ld %s:%s\n",
(long)dns_zone_getcounts(zone,
dns_zonecount_failure),
viewname, zonestore);
for (i=0; i<numbercounters; i++)
fprintf(fp,"%s %ld %s:%s\n",
dns_zonecount_names[i],
(long)dns_zone_getcounts(zone, i),
viewname, zonestore);
} else {
ns_server_statsprintf("NOSTATISTICS 0 %s:%s\n",
fprintf(fp,"nostatistics 0 %s:%s\n",
viewname, zonestore);
}
isc_buffer_invalidate(&zonebuf);
......@@ -2282,9 +2272,9 @@ ns_server_dumpstats(ns_server_t *server) {
zone = next;
next = NULL;
}
ns_server_statsprintf("--- Statistics Dump --- (%ld)\n",
fprintf(fp,"--- Statistics Dump --- (%ld)\n",
(long)now);
dns_zonemgr_unlockconf(server->zonemgr, isc_rwlocktype_read);
ns_server_closestatsfile();
ns_server_closestatsfile(server);
return (ISC_R_SUCCESS);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment