diff --git a/smmapdfw/libsmmapdfw/stats.c b/smmapdfw/libsmmapdfw/stats.c index a50b25e..56195b7 100644 --- a/smmapdfw/libsmmapdfw/stats.c +++ b/smmapdfw/libsmmapdfw/stats.c @@ -73,9 +73,9 @@ void outputStats(int nice) { if (nice) printf("---------------------------------------------------------\n"); - for (i=0; iclientSock, 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; diff --git a/smmapdfw/smmapd/smmapd.ini b/smmapdfw/smmapd/smmapd.ini index 2427ff5..87f124d 100644 --- a/smmapdfw/smmapd/smmapd.ini +++ b/smmapdfw/smmapd/smmapd.ini @@ -13,7 +13,7 @@ enable_stats = 1 [stats] nice = 1 -period = 5 +period = 1 [test_worker1] diff --git a/smmapdfw/verify_worker/verify_worker.c b/smmapdfw/verify_worker/verify_worker.c index 869191c..492139f 100644 --- a/smmapdfw/verify_worker/verify_worker.c +++ b/smmapdfw/verify_worker/verify_worker.c @@ -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, "<%s>", wt->output); + incStatCounter(STAT_CNT_VERIFIER_RETURNED_TNOK); result = SMM_OK; break; case SMM_LOCAL_PERM_NOK: sprintf(wt->result->output, "<%s>", wt->output); + incStatCounter(STAT_CNT_VERIFIER_RETURNED_NOK); result = SMM_OK; break; case SMM_LOCAL_OK: sprintf(wt->result->output, "<%s>", wt->output); + incStatCounter(STAT_CNT_VERIFIER_RETURNED_OK); result = SMM_OK; break; default: