changes for stats in verifier

This commit is contained in:
whottgen 2004-11-04 22:46:22 +00:00
parent cafbf37771
commit 7e2b1365b4
5 changed files with 71 additions and 21 deletions

View File

@ -73,9 +73,9 @@ void outputStats(int nice) {
if (nice)
printf("---------------------------------------------------------\n");
for (i=0; i<STAT_CNT_MAXNUM; i++) {
for (i=1; i<STAT_CNT_MAXNUM; i++) {
if (nice)
printf("%40s = %5d\n", stat_cnt_names[i], getStatCounter(i));
printf("%44s = %5d\n", stat_cnt_names[i], getStatCounter(i));
else
printf("%d ", getStatCounter(i));
}

View File

@ -26,28 +26,58 @@
#ifdef _STATS_C_
char *stat_cnt_names[] = {
"accepted",
"failed",
"Running networker threads",
"Failed to start, networker threads",
"returned OK",
"returned TEMP_NOK",
"returned PERM_NOK",
"returned NOT_FOUND_NOK",
"returned illegal input",
"returned unknown class",
"returned TIMEOUT_NOK",
"returned netstring unparsable",
"",
"Server: accepted",
"Server: failed",
"Server: running networker threads",
"Server: networker threads",
"Server: failed to start, networker threads",
"Verifier: entries in cache",
"Verifier: running worker threads",
"Verifier: worker threads",
"Verifier: failed to start, worker threads",
"Verifier: timed out worker threads",
"Verifier: running checker threads",
"Verifier: checker threads",
"Verifier: failed to start, checker threads",
"Verifier: answered from cache",
"Verifier: returned OK",
"Verifier: returned NOK",
"Verifier: returned TNOK",
"Server: returned OK",
"Server: returned TEMP_NOK",
"Server: returned PERM_NOK",
"Server: returned NOT_FOUND_NOK",
"Server: returned illegal input",
"Server: returned unknown class",
"Server: returned TIMEOUT_NOK",
"Server: returned netstring unparsable",
};
#endif /* _STATS_C_ */
#define STAT_CNT_ACCEPTED 1
#define STAT_CNT_FAILED 2
#define STAT_CNT_NETWORKER_THREADS 3
#define STAT_CNT_NETWORKER_THREADS_FAILED 4
#define STAT_CNT_NETWORKER_R_THREADS 3
#define STAT_CNT_NETWORKER_THREADS 4
#define STAT_CNT_NETWORKER_THREADS_FAILED 5
#define STAT_CNT_VERIFIER_CACHE 6
#define STAT_CNT_VERIFIER_WORKER_R_THREADS 7
#define STAT_CNT_VERIFIER_WORKER_THREADS 8
#define STAT_CNT_VERIFIER_WORKER_THREADS_FAILED 9
#define STAT_CNT_VERIFIER_WORKER_THREADS_TIMEOUT 10
#define STAT_CNT_VERIFIER_CHECKER_R_THREADS 11
#define STAT_CNT_VERIFIER_CHECKER_THREADS 12
#define STAT_CNT_VERIFIER_CHECKER_THREADS_FAILED 13
#define STAT_CNT_VERIFIER_ANSWERED_FROM_CACHE 14
#define STAT_CNT_VERIFIER_RETURNED_OK 15
#define STAT_CNT_VERIFIER_RETURNED_NOK 16
#define STAT_CNT_VERIFIER_RETURNED_TNOK 17
#define STAT_CNT_OFFSET 4
#define STAT_CNT_OFFSET 17
#define STAT_CNT_MAXNUM STAT_CNT_OFFSET + SMM_MAX_NUM

View File

@ -137,7 +137,7 @@ void * cleaner(void * arg) {
count_get(&thread_counter));
t = (networkerThread_t*) queue_get_wait(&terminated_networker_queue);
count_dec(&thread_counter);
decStatCounter(STAT_CNT_NETWORKER_THREADS);
decStatCounter(STAT_CNT_NETWORKER_R_THREADS);
syslog(LOG_DEBUG, "cleaner: Networker serving %d (address: %s, port: %d), result %d",
t->clientSock, inet_ntoa(t->clientAddr.sin_addr),
@ -172,6 +172,8 @@ void * networker(void * arg) {
networkerThread_t * thread = (networkerThread_t *) arg;
thread->pthread = pthread_self();
incStatCounter(STAT_CNT_NETWORKER_THREADS);
syslog(LOG_DEBUG, "networker: serving %d (address: %s, port: %d) started",
thread->clientSock, inet_ntoa(thread->clientAddr.sin_addr),
ntohs(thread->clientAddr.sin_port));
@ -341,12 +343,12 @@ int server() {
thread->clientAddrLen = clientAddrLen;
count_inc(&thread_counter);
incStatCounter(STAT_CNT_NETWORKER_THREADS);
incStatCounter(STAT_CNT_NETWORKER_R_THREADS);
res = pthread_create(&tid, NULL, &networker, thread);
if (0 != res) {
syslog(LOG_ERR, "server: unable to start networker thread");
free(thread);
decStatCounter(STAT_CNT_NETWORKER_THREADS);
decStatCounter(STAT_CNT_NETWORKER_R_THREADS);
incStatCounter(STAT_CNT_NETWORKER_THREADS_FAILED);
count_dec(&thread_counter);
continue;

View File

@ -13,7 +13,7 @@ enable_stats = 1
[stats]
nice = 1
period = 5
period = 1
[test_worker1]

View File

@ -48,6 +48,7 @@
#include "smtp.h"
#include "htmalloc.h"
#include "stats.h"
#define SMM_LOCAL_PERM_NOK 101
#define SMM_LOCAL_TEMP_NOK 102
@ -241,6 +242,7 @@ int verify_work_destroy(void *handle, void *work_handle) {
/* clean up the checker stuff */
pthread_join(ct->thread, NULL);
decStatCounter(STAT_CNT_VERIFIER_CHECKER_R_THREADS);
syslog(LOG_DEBUG, "verify (%p) verify_work_destroy, checker_thread (id=%d) joined",
work_handle, ct->id);
@ -251,6 +253,7 @@ int verify_work_destroy(void *handle, void *work_handle) {
}
err = pthread_join(wt->thread, NULL);
decStatCounter(STAT_CNT_VERIFIER_WORKER_R_THREADS);
syslog(LOG_DEBUG, "verify (%p) verify_work_destroy, worker_thread (id=%d) joined",
work_handle, wt->id);
free(wt->input);
@ -307,6 +310,7 @@ void cache_insert(verify_container_handle_t *vch, const char *address, int resul
if (ret != 0) {
syslog(LOG_DEBUG, "cache_insert: couldn't insert record");
} else {
incStatCounter(STAT_CNT_VERIFIER_CACHE);
syslog(LOG_DEBUG, "cache_insert: record inserted");
}
dbm_close(cache);
@ -363,6 +367,7 @@ int cache_lookup(verify_container_handle_t *vch, const char* address, int *resul
if (ret != 0) {
syslog(LOG_DEBUG, "cache_insert: couldn't delete record");
} else {
decStatCounter(STAT_CNT_VERIFIER_CACHE);
syslog(LOG_DEBUG, "cache_insert: record deleted");
}
dbm_close(cache);
@ -448,6 +453,7 @@ int verify_work(void *handle, void *work_handle, char *input, char *output) {
pthread_mutex_lock(vwh->result_mutex);
err = pthread_create(&tid, NULL, &worker_thread, wt);
if (-1 == err) {
incStatCounter(STAT_CNT_VERIFIER_WORKER_THREADS_FAILED);
free(wt->input);
free(wt);
PERM_NOK_RETURN("unable to create worker thread");
@ -459,6 +465,7 @@ int verify_work(void *handle, void *work_handle, char *input, char *output) {
err = pthread_cond_timedwait(vwh->result_cond, vwh->result_mutex, &ts);
pthread_mutex_unlock(vwh->result_mutex);
if (ETIMEDOUT == err) {
incStatCounter(STAT_CNT_VERIFIER_WORKER_THREADS_TIMEOUT);
TEMP_NOK_RETURN("worker thread timed out");
}
@ -533,6 +540,9 @@ static void *checker_thread(void *arg) {
ct->thread = pthread_self();
incStatCounter(STAT_CNT_VERIFIER_CHECKER_THREADS);
incStatCounter(STAT_CNT_VERIFIER_CHECKER_R_THREADS);
/*
Connect to ct->ip_address using ct->email_address,
put the result text in ct->output, TBD: by copy or pointer,
@ -656,6 +666,8 @@ static void *worker_thread(void *arg) {
wt->thread = pthread_self();
incStatCounter(STAT_CNT_VERIFIER_WORKER_R_THREADS);
incStatCounter(STAT_CNT_VERIFIER_WORKER_THREADS);
@ -668,6 +680,7 @@ static void *worker_thread(void *arg) {
if (0 == cache_lookup(wt->vwh->vch, wt->input, &result, &cached_output)) {
syslog(LOG_DEBUG, "verify (%p) worker_thread: got a cached result for %s -> %d, %s",
wt->vwh, wt->input, result, cached_output);
incStatCounter(STAT_CNT_VERIFIER_ANSWERED_FROM_CACHE);
wt->output = cached_output;
} else {
domain_part += 1;
@ -699,6 +712,7 @@ static void *worker_thread(void *arg) {
err = pthread_create(&tid, NULL, &checker_thread, ct);
if (-1 == err) {
incStatCounter(STAT_CNT_VERIFIER_CHECKER_THREADS_FAILED);
syslog(LOG_ERR, "verify (%p) worker_thread: unable to create checker thread", wt->vwh);
free(ct);
} else {
@ -718,6 +732,7 @@ static void *worker_thread(void *arg) {
wt->input, ct->result, ct->output);
pthread_join(ct->thread, NULL);
decStatCounter(STAT_CNT_VERIFIER_CHECKER_R_THREADS);
syslog(LOG_DEBUG, "verify (%p) worker_thread: checker thread joined", wt->vwh);
if ((SMM_LOCAL_TEMP_NOK != ct->result) &&
@ -757,14 +772,17 @@ static void *worker_thread(void *arg) {
switch (result) {
case SMM_LOCAL_TEMP_NOK:
sprintf(wt->result->output, "<TNOK><%s>", wt->output);
incStatCounter(STAT_CNT_VERIFIER_RETURNED_TNOK);
result = SMM_OK;
break;
case SMM_LOCAL_PERM_NOK:
sprintf(wt->result->output, "<NOK><%s>", wt->output);
incStatCounter(STAT_CNT_VERIFIER_RETURNED_NOK);
result = SMM_OK;
break;
case SMM_LOCAL_OK:
sprintf(wt->result->output, "<OK><%s>", wt->output);
incStatCounter(STAT_CNT_VERIFIER_RETURNED_OK);
result = SMM_OK;
break;
default: