summaryrefslogtreecommitdiffstats
path: root/plugins/impstats/impstats.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/impstats/impstats.c')
-rw-r--r--plugins/impstats/impstats.c71
1 files changed, 67 insertions, 4 deletions
diff --git a/plugins/impstats/impstats.c b/plugins/impstats/impstats.c
index 79749e21..42d7c1c2 100644
--- a/plugins/impstats/impstats.c
+++ b/plugins/impstats/impstats.c
@@ -1,7 +1,7 @@
/* impstats.c
* A module to periodically output statistics gathered by rsyslog.
*
- * Copyright 2010-2012 Adiscon GmbH.
+ * Copyright 2010-2013 Adiscon GmbH.
*
* This file is part of rsyslog.
*
@@ -32,6 +32,9 @@
#if defined(__FreeBSD__)
#include <sys/stat.h>
#endif
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/resource.h>
#include "dirty.h"
#include "cfsysline.h"
@@ -76,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;
};
@@ -92,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 }
};
@@ -101,6 +106,19 @@ static struct cnfparamblk modpblk =
modpdescr
};
+
+/* resource use stats counters */
+static intctr_t st_ru_utime;
+static intctr_t st_ru_stime;
+static int st_ru_maxrss;
+static int st_ru_minflt;
+static int st_ru_majflt;
+static int st_ru_inblock;
+static int st_ru_oublock;
+static int st_ru_nvcsw;
+static int st_ru_nivcsw;
+static statsobj_t *statsobj_resources;
+
BEGINmodExit
CODESTARTmodExit
prop.Destruct(&pInputName);
@@ -222,7 +240,23 @@ doStatsLine(void __attribute__((unused)) *usrptr, cstr_t *cstr)
static inline void
generateStatsMsgs(void)
{
- statsobj.GetAllStatsLines(doStatsLine, NULL, runModConf->statsFmt);
+ struct rusage ru;
+ int r;
+ r = getrusage(RUSAGE_SELF, &ru);
+ if(r != 0) {
+ dbgprintf("impstats: getrusage() failed with error %d, zeroing out\n", errno);
+ memset(&ru, 0, sizeof(ru));
+ }
+ st_ru_utime = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
+ st_ru_stime = ru.ru_stime.tv_sec * 1000000 + ru.ru_stime.tv_usec;
+ st_ru_maxrss = ru.ru_maxrss;
+ st_ru_minflt = ru.ru_minflt;
+ st_ru_majflt = ru.ru_majflt;
+ st_ru_inblock = ru.ru_inblock;
+ st_ru_oublock = ru.ru_oublock;
+ st_ru_nvcsw = ru.ru_nvcsw;
+ st_ru_nivcsw = ru.ru_nivcsw;
+ statsobj.GetAllStatsLines(doStatsLine, NULL, runModConf->statsFmt, runModConf->bResetCtrs);
}
@@ -239,6 +273,7 @@ CODESTARTbeginCnfLoad
loadModConf->logfd = -1;
loadModConf->logfile = NULL;
loadModConf->bLogToSyslog = 1;
+ loadModConf->bResetCtrs = 0;
bLegacyCnfModGlobalsPermitted = 1;
/* init legacy config vars */
initConfigSettings();
@@ -273,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")) {
@@ -335,15 +372,41 @@ 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) {
errmsg.LogError(0, localRet, "impstats: error enabling statistics gathering");
ABORT_FINALIZE(RS_RET_NO_RUN);
}
+ /* initialize our own counters */
+ CHKiRet(statsobj.Construct(&statsobj_resources));
+ CHKiRet(statsobj.SetName(statsobj_resources, (uchar*)"resource-usage"));
+ CHKiRet(statsobj.AddCounter(statsobj_resources, UCHAR_CONSTANT("utime"),
+ ctrType_IntCtr, CTR_FLAG_NONE, &st_ru_utime));
+ CHKiRet(statsobj.AddCounter(statsobj_resources, UCHAR_CONSTANT("stime"),
+ ctrType_IntCtr, CTR_FLAG_NONE, &st_ru_stime));
+ CHKiRet(statsobj.AddCounter(statsobj_resources, UCHAR_CONSTANT("maxrss"),
+ ctrType_Int, CTR_FLAG_NONE, &st_ru_maxrss));
+ CHKiRet(statsobj.AddCounter(statsobj_resources, UCHAR_CONSTANT("minflt"),
+ ctrType_Int, CTR_FLAG_NONE, &st_ru_minflt));
+ CHKiRet(statsobj.AddCounter(statsobj_resources, UCHAR_CONSTANT("majflt"),
+ ctrType_Int, CTR_FLAG_NONE, &st_ru_majflt));
+ CHKiRet(statsobj.AddCounter(statsobj_resources, UCHAR_CONSTANT("inblock"),
+ ctrType_Int, CTR_FLAG_NONE, &st_ru_inblock));
+ CHKiRet(statsobj.AddCounter(statsobj_resources, UCHAR_CONSTANT("oublock"),
+ ctrType_Int, CTR_FLAG_NONE, &st_ru_oublock));
+ CHKiRet(statsobj.AddCounter(statsobj_resources, UCHAR_CONSTANT("nvcsw"),
+ ctrType_Int, CTR_FLAG_NONE, &st_ru_nvcsw));
+ CHKiRet(statsobj.AddCounter(statsobj_resources, UCHAR_CONSTANT("nivcsw"),
+ ctrType_Int, CTR_FLAG_NONE, &st_ru_nivcsw));
+ CHKiRet(statsobj.ConstructFinalize(statsobj_resources));
finalize_it:
+ if(iRet != RS_RET_OK) {
+ errmsg.LogError(0, iRet, "impstats: error activating module");
+ iRet = RS_RET_NO_RUN;
+ }
ENDactivateCnf