summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/impstats.html18
-rw-r--r--plugins/impstats/impstats.c11
-rw-r--r--runtime/statsobj.c22
-rw-r--r--runtime/statsobj.h7
4 files changed, 39 insertions, 19 deletions
diff --git a/doc/impstats.html b/doc/impstats.html
index 1da09ced..45208ef1 100644
--- a/doc/impstats.html
+++ b/doc/impstats.html
@@ -34,14 +34,28 @@ settings, this impact may be noticeable (for high-load environments).
interval is what is configured here plus the actual time required to generate messages.
In general, the difference should not really matter.
<br></li>
- <li><strong>facility </strong>[templateName]<br>
+ <li><strong>facility </strong>[facility number]<br>
The numerical syslog facility code to be used for generated messages. Default
is 5 (syslog). This is useful for filtering messages.
<br></li>
- <li><strong>severity </strong>[templateName]<br>
+ <li><strong>severity </strong>[severity number]<br>
The numerical syslog severity code to be used for generated messages. Default
is 6 (info).This is useful for filtering messages.
<br></li>
+ <li><strong>resetCounters </strong>[<b>off</b>/on]<br>
+ When set to "on", counters are automatically reset after they are emitted. In that
+ case, the contain only deltas to the last value emitted. When set
+ to "off", counters always accumulate their values.
+ Note that in auto-reset mode not all counters can be reset. Some counters (like queue size)
+ are directly obtained from internal object and cannot be modified. Also, auto-resetting
+ introduces some additional slight inaccuracies due to the multi-threaded nature of
+ rsyslog and the fact that for performance reasons it cannot serialize access
+ to counter variables.</br>
+ As an alternative to auto-reset mode, you can use rsyslog's statistics
+ manipulation scripts to create delta values from the regular statistic
+ logs. This is the suggested method if deltas are not necessarily needed in
+ real-time.
+ <br></li>
<li><strong>format </strong>[json/cee/<b>legacy</b>](rsyslog v6.3.8+ only)<br>
Specifies the format of emitted stats messages. The default of "legacy" is
compatible with pre v6-rsyslog. The other options provide support for
diff --git a/plugins/impstats/impstats.c b/plugins/impstats/impstats.c
index 521ba1bc..42d7c1c2 100644
--- a/plugins/impstats/impstats.c
+++ b/plugins/impstats/impstats.c
@@ -79,6 +79,7 @@ struct modConfData_s {
int logfd; /* fd if logging to file, or -1 if closed */
statsFmtType_t statsFmt;
sbool bLogToSyslog;
+ sbool bResetCtrs;
char *logfile;
sbool configSetViaV2Method;
};
@@ -95,6 +96,7 @@ static struct cnfparamdescr modpdescr[] = {
{ "facility", eCmdHdlrInt, 0 },
{ "severity", eCmdHdlrInt, 0 },
{ "log.syslog", eCmdHdlrBinary, 0 },
+ { "resetcounters", eCmdHdlrBinary, 0 },
{ "log.file", eCmdHdlrGetWord, 0 },
{ "format", eCmdHdlrGetWord, 0 }
};
@@ -254,7 +256,7 @@ generateStatsMsgs(void)
st_ru_oublock = ru.ru_oublock;
st_ru_nvcsw = ru.ru_nvcsw;
st_ru_nivcsw = ru.ru_nivcsw;
- statsobj.GetAllStatsLines(doStatsLine, NULL, runModConf->statsFmt);
+ statsobj.GetAllStatsLines(doStatsLine, NULL, runModConf->statsFmt, runModConf->bResetCtrs);
}
@@ -271,6 +273,7 @@ CODESTARTbeginCnfLoad
loadModConf->logfd = -1;
loadModConf->logfile = NULL;
loadModConf->bLogToSyslog = 1;
+ loadModConf->bResetCtrs = 0;
bLegacyCnfModGlobalsPermitted = 1;
/* init legacy config vars */
initConfigSettings();
@@ -305,6 +308,8 @@ CODESTARTsetModCnf
loadModConf->iSeverity = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "log.syslog")) {
loadModConf->bLogToSyslog = (sbool) pvals[i].val.d.n;
+ } else if(!strcmp(modpblk.descr[i].name, "resetcounters")) {
+ loadModConf->bResetCtrs = (sbool) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "log.file")) {
loadModConf->logfile = es_str2cstr(pvals[i].val.d.estr, NULL);
} else if(!strcmp(modpblk.descr[i].name, "format")) {
@@ -367,8 +372,8 @@ BEGINactivateCnf
rsRetVal localRet;
CODESTARTactivateCnf
runModConf = pModConf;
- DBGPRINTF("impstats: stats interval %d seconds, logToSyslog %d, logFile %s\n",
- runModConf->iStatsInterval, runModConf->bLogToSyslog,
+ DBGPRINTF("impstats: stats interval %d seconds, reset %d, logToSyslog %d, logFile %s\n",
+ runModConf->iStatsInterval, runModConf->bResetCtrs, runModConf->bLogToSyslog,
runModConf->logfile == NULL ? "deactivated" : (char*)runModConf->logfile);
localRet = statsobj.EnableStats();
if(localRet != RS_RET_OK) {
diff --git a/runtime/statsobj.c b/runtime/statsobj.c
index fd091f8d..edac7d48 100644
--- a/runtime/statsobj.c
+++ b/runtime/statsobj.c
@@ -168,9 +168,9 @@ finalize_it:
}
static inline void
-resetResettableCtr(ctr_t *pCtr)
+resetResettableCtr(ctr_t *pCtr, int8_t bResetCtrs)
{
- if(pCtr->flags & CTR_FLAG_RESETTABLE) {
+ if(bResetCtrs && (pCtr->flags & CTR_FLAG_RESETTABLE)) {
switch(pCtr->ctrType) {
case ctrType_IntCtr:
*(pCtr->val.pIntCtr) = 0;
@@ -184,7 +184,7 @@ resetResettableCtr(ctr_t *pCtr)
/* get all the object's countes together as CEE. */
static rsRetVal
-getStatsLineCEE(statsobj_t *pThis, cstr_t **ppcstr, int cee_cookie)
+getStatsLineCEE(statsobj_t *pThis, cstr_t **ppcstr, int cee_cookie, int8_t bResetCtrs)
{
cstr_t *pcstr;
ctr_t *pCtr;
@@ -225,7 +225,7 @@ getStatsLineCEE(statsobj_t *pThis, cstr_t **ppcstr, int cee_cookie)
} else {
cstrAppendChar(pcstr, '}');
}
- resetResettableCtr(pCtr);
+ resetResettableCtr(pCtr, bResetCtrs);
}
pthread_mutex_unlock(&pThis->mutCtr);
@@ -239,7 +239,7 @@ finalize_it:
/* get all the object's countes together with object name as one line.
*/
static rsRetVal
-getStatsLine(statsobj_t *pThis, cstr_t **ppcstr)
+getStatsLine(statsobj_t *pThis, cstr_t **ppcstr, int8_t bResetCtrs)
{
cstr_t *pcstr;
ctr_t *pCtr;
@@ -263,7 +263,7 @@ getStatsLine(statsobj_t *pThis, cstr_t **ppcstr)
break;
}
cstrAppendChar(pcstr, ' ');
- resetResettableCtr(pCtr);
+ resetResettableCtr(pCtr, bResetCtrs);
}
pthread_mutex_unlock(&pThis->mutCtr);
@@ -282,7 +282,7 @@ finalize_it:
* line. If the callback reports an error, processing is stopped.
*/
static rsRetVal
-getAllStatsLines(rsRetVal(*cb)(void*, cstr_t*), void *usrptr, statsFmtType_t fmt)
+getAllStatsLines(rsRetVal(*cb)(void*, cstr_t*), void *usrptr, statsFmtType_t fmt, int8_t bResetCtrs)
{
statsobj_t *o;
cstr_t *cstr;
@@ -291,13 +291,13 @@ getAllStatsLines(rsRetVal(*cb)(void*, cstr_t*), void *usrptr, statsFmtType_t fmt
for(o = objRoot ; o != NULL ; o = o->next) {
switch(fmt) {
case statsFmt_Legacy:
- CHKiRet(getStatsLine(o, &cstr));
+ CHKiRet(getStatsLine(o, &cstr, bResetCtrs));
break;
case statsFmt_CEE:
- CHKiRet(getStatsLineCEE(o, &cstr, 1));
+ CHKiRet(getStatsLineCEE(o, &cstr, 1, bResetCtrs));
break;
case statsFmt_JSON:
- CHKiRet(getStatsLineCEE(o, &cstr, 0));
+ CHKiRet(getStatsLineCEE(o, &cstr, 0, bResetCtrs));
break;
}
CHKiRet(cb(usrptr, cstr));
@@ -365,7 +365,7 @@ CODESTARTobjQueryInterface(statsobj)
pIf->Destruct = statsobjDestruct;
pIf->DebugPrint = statsobjDebugPrint;
pIf->SetName = setName;
- pIf->GetStatsLine = getStatsLine;
+ //pIf->GetStatsLine = getStatsLine;
pIf->GetAllStatsLines = getAllStatsLines;
pIf->AddCounter = addCounter;
pIf->EnableStats = enableStats;
diff --git a/runtime/statsobj.h b/runtime/statsobj.h
index ee120992..d56485de 100644
--- a/runtime/statsobj.h
+++ b/runtime/statsobj.h
@@ -86,8 +86,8 @@ BEGINinterface(statsobj) /* name must also be changed in ENDinterface macro! */
rsRetVal (*ConstructFinalize)(statsobj_t *pThis);
rsRetVal (*Destruct)(statsobj_t **ppThis);
rsRetVal (*SetName)(statsobj_t *pThis, uchar *name);
- rsRetVal (*GetStatsLine)(statsobj_t *pThis, cstr_t **ppcstr);
- rsRetVal (*GetAllStatsLines)(rsRetVal(*cb)(void*, cstr_t*), void *usrptr, statsFmtType_t fmt);
+ //rsRetVal (*GetStatsLine)(statsobj_t *pThis, cstr_t **ppcstr);
+ rsRetVal (*GetAllStatsLines)(rsRetVal(*cb)(void*, cstr_t*), void *usrptr, statsFmtType_t fmt, int8_t bResetCtr);
rsRetVal (*AddCounter)(statsobj_t *pThis, uchar *ctrName, statsCtrType_t ctrType, int8_t flags, void *pCtr);
rsRetVal (*EnableStats)(void);
ENDinterface(statsobj)
@@ -95,7 +95,8 @@ ENDinterface(statsobj)
/* Changes
* v2-v9 rserved for future use in "older" version branches
* v10, 2012-04-01: GetAllStatsLines got fmt parameter
- * v11, 2013-09-07: add "flags" to AddCounter API
+ * v11, 2013-09-07: - add "flags" to AddCounter API
+ * - GetAllStatsLines got parameter telling if ctrs shall be reset
*/