From b9e19dc79b25f891f880ccc60f0e5b02d12a0375 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 16 Oct 2013 17:32:27 +0200 Subject: bugfix omelasticsearch: failed.http stats counter had incorrect count --- plugins/omelasticsearch/omelasticsearch.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/omelasticsearch/omelasticsearch.c b/plugins/omelasticsearch/omelasticsearch.c index d49667f9..c1b2abd0 100644 --- a/plugins/omelasticsearch/omelasticsearch.c +++ b/plugins/omelasticsearch/omelasticsearch.c @@ -4,7 +4,7 @@ * NOTE: read comments in module-template.h for more specifics! * * Copyright 2011 Nathan Scott. - * Copyright 2009-2012 Rainer Gerhards and Adiscon GmbH. + * Copyright 2009-2013 Rainer Gerhards and Adiscon GmbH. * * This file is part of rsyslog. * @@ -90,6 +90,7 @@ typedef struct _instanceData { sbool asyncRepl; struct { es_str_t *data; + int nmemb; /* number of messages in batch (for statistics counting) */ uchar *currTpl1; uchar *currTpl2; } batch; @@ -431,6 +432,7 @@ buildBatch(instanceData *pData, uchar *message, uchar **tpls) DBGPRINTF("omelasticsearch: growing batch failed with code %d\n", r); ABORT_FINALIZE(RS_RET_ERR); } + ++pData->batch.nmemb; iRet = RS_RET_DEFER_COMMIT; finalize_it: @@ -584,7 +586,7 @@ finalize_it: static rsRetVal -curlPost(instanceData *pData, uchar *message, int msglen, uchar **tpls) +curlPost(instanceData *pData, uchar *message, int msglen, uchar **tpls, int nmsgs) { CURLcode code; CURL *curl = pData->curlHandle; @@ -605,7 +607,7 @@ curlPost(instanceData *pData, uchar *message, int msglen, uchar **tpls) case CURLE_COULDNT_RESOLVE_PROXY: case CURLE_COULDNT_CONNECT: case CURLE_WRITE_ERROR: - STATSCOUNTER_INC(indexHTTPFail, mutIndexHTTPFail); + indexHTTPFail += nmsgs; DBGPRINTF("omelasticsearch: we are suspending ourselfs due " "to failure %lld of curl_easy_perform()\n", (long long) code); @@ -634,6 +636,7 @@ dbgprintf("omelasticsearch: beginTransaction\n"); } es_emptyStr(pData->batch.data); + pData->batch.nmemb = 0; finalize_it: ENDbeginTransaction @@ -645,7 +648,7 @@ CODESTARTdoAction CHKiRet(buildBatch(pData, ppString[0], ppString)); } else { CHKiRet(curlPost(pData, ppString[0], strlen((char*)ppString[0]), - ppString)); + ppString, 1)); } finalize_it: dbgprintf("omelasticsearch: result doAction: %d (bulkmode %d)\n", iRet, pData->bulkmode); @@ -660,7 +663,7 @@ dbgprintf("omelasticsearch: endTransaction init\n"); if (pData->batch.data != NULL ) { cstr = es_str2cstr(pData->batch.data, NULL); dbgprintf("omelasticsearch: endTransaction, batch: '%s'\n", cstr); - CHKiRet(curlPost(pData, (uchar*) cstr, strlen(cstr), NULL)); + CHKiRet(curlPost(pData, (uchar*) cstr, strlen(cstr), NULL, pData->batch.nmemb)); } else dbgprintf("omelasticsearch: endTransaction, pData->batch.data is NULL, nothing to send. \n"); -- cgit v1.2.3 From 75187bc1839bd5ba9d0ef652ee9e9037f0e2a95e Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 16 Oct 2013 17:41:01 +0200 Subject: omelasticsearch: add failed.httprequests stats counter --- ChangeLog | 2 ++ plugins/omelasticsearch/omelasticsearch.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index da6dcc9a..b3632fe3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,8 @@ Version 7.4.5 [v7.4-stable] 2013-09-?? Thanks to Muri Cicanor for initiating the discussion - now requires libestr 0.1.8 as early versions had a nasty bug in string comparisons +- omelasticsearch: add failed.httprequests stats counter +- bugfix omelasticsearch: correct failed.http stats counter - bugfix: mmanon did not detect all IP addresses in rewrite mode The problem occured if two IPs were close to each other and the first one was shrunk. diff --git a/plugins/omelasticsearch/omelasticsearch.c b/plugins/omelasticsearch/omelasticsearch.c index c1b2abd0..5d4c97c3 100644 --- a/plugins/omelasticsearch/omelasticsearch.c +++ b/plugins/omelasticsearch/omelasticsearch.c @@ -60,6 +60,7 @@ DEFobjCurrIf(statsobj) statsobj_t *indexStats; STATSCOUNTER_DEF(indexSubmit, mutIndexSubmit) STATSCOUNTER_DEF(indexHTTPFail, mutIndexHTTPFail) +STATSCOUNTER_DEF(indexHTTPReqFail, mutIndexHTTPReqFail) STATSCOUNTER_DEF(indexESFail, mutIndexESFail) /* REST API for elasticsearch hits this URL: @@ -607,6 +608,7 @@ curlPost(instanceData *pData, uchar *message, int msglen, uchar **tpls, int nmsg case CURLE_COULDNT_RESOLVE_PROXY: case CURLE_COULDNT_CONNECT: case CURLE_WRITE_ERROR: + STATSCOUNTER_INC(indexHTTPReqFail, mutHTTPReqFail); indexHTTPFail += nmsgs; DBGPRINTF("omelasticsearch: we are suspending ourselfs due " "to failure %lld of curl_easy_perform()\n", @@ -1003,6 +1005,9 @@ CODEmodInit_QueryRegCFSLineHdlr ctrType_IntCtr, &indexSubmit)); CHKiRet(statsobj.AddCounter(indexStats, (uchar *)"failed.http", ctrType_IntCtr, &indexHTTPFail)); + STATSCOUNTER_INIT(indexHTTPReqFail, mutCtrIndexHTTPReqFail); + CHKiRet(statsobj.AddCounter(indexStats, (uchar *)"failed.httprequests", + ctrType_IntCtr, &indexHTTPReqFail)); CHKiRet(statsobj.AddCounter(indexStats, (uchar *)"failed.es", ctrType_IntCtr, &indexESFail)); CHKiRet(statsobj.ConstructFinalize(indexStats)); -- cgit v1.2.3 From 10dcb23ae5828c239a1d8518e90c7d6d9e2ea1a8 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 16 Oct 2013 17:44:01 +0200 Subject: bugfix: omelasticsearch: did not correctly initialize stats counters This usually did not lead to any problems, because they are in static memory, which is initialized to zero by the OS when the plugin is loaded. But it may cause problems especially on systems that do not support atomic instructions - in this case the associated mutexes also did not get properly initialized. --- ChangeLog | 8 +++++++- plugins/omelasticsearch/omelasticsearch.c | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b3632fe3..e3c25cb8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,7 +11,13 @@ Version 7.4.5 [v7.4-stable] 2013-09-?? - now requires libestr 0.1.8 as early versions had a nasty bug in string comparisons - omelasticsearch: add failed.httprequests stats counter -- bugfix omelasticsearch: correct failed.http stats counter +- bugfix: omelasticsearch: correct failed.http stats counter +- bugfix: omelasticsearch: did not correctly initialize stats counters + This usually did not lead to any problems, because they are in static + memory, which is initialized to zero by the OS when the plugin is + loaded. But it may cause problems especially on systems that do not + support atomic instructions - in this case the associated mutexes also + did not get properly initialized. - bugfix: mmanon did not detect all IP addresses in rewrite mode The problem occured if two IPs were close to each other and the first one was shrunk. diff --git a/plugins/omelasticsearch/omelasticsearch.c b/plugins/omelasticsearch/omelasticsearch.c index 5d4c97c3..240d19e6 100644 --- a/plugins/omelasticsearch/omelasticsearch.c +++ b/plugins/omelasticsearch/omelasticsearch.c @@ -1001,13 +1001,16 @@ CODEmodInit_QueryRegCFSLineHdlr /* support statistics gathering */ CHKiRet(statsobj.Construct(&indexStats)); CHKiRet(statsobj.SetName(indexStats, (uchar *)"omelasticsearch")); + STATSCOUNTER_INIT(indexSubmit, mutCtrIndexSubmit); CHKiRet(statsobj.AddCounter(indexStats, (uchar *)"submitted", ctrType_IntCtr, &indexSubmit)); + STATSCOUNTER_INIT(indexHTTPFail, mutCtrIndexHTTPFail); CHKiRet(statsobj.AddCounter(indexStats, (uchar *)"failed.http", ctrType_IntCtr, &indexHTTPFail)); STATSCOUNTER_INIT(indexHTTPReqFail, mutCtrIndexHTTPReqFail); CHKiRet(statsobj.AddCounter(indexStats, (uchar *)"failed.httprequests", ctrType_IntCtr, &indexHTTPReqFail)); + STATSCOUNTER_INIT(indexESFail, mutCtrIndexESFail); CHKiRet(statsobj.AddCounter(indexStats, (uchar *)"failed.es", ctrType_IntCtr, &indexESFail)); CHKiRet(statsobj.ConstructFinalize(indexStats)); -- cgit v1.2.3