summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-09-09 12:24:22 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2010-09-09 12:24:22 +0200
commit3cbd7300c47991aadca00db1b028fd3d5d551040 (patch)
tree37e4b9e72e22480b132e9e4425e1994231b2f377
parent947e5632039d1dd2ef3ae22ac45b17370bbac24d (diff)
downloadrsyslog-3cbd7300c47991aadca00db1b028fd3d5d551040.tar.gz
rsyslog-3cbd7300c47991aadca00db1b028fd3d5d551040.tar.xz
rsyslog-3cbd7300c47991aadca00db1b028fd3d5d551040.zip
added module impstat to emit periodic statistics on rsyslog counters
This is a *very first* and *very rough* and *very featureless* first shot at this functionality. It is assumed that we will enhance the stats system as a by-line while doing other development.
-rw-r--r--ChangeLog6
-rw-r--r--Makefile.am5
-rw-r--r--configure.ac15
-rw-r--r--doc/Makefile.am1
-rw-r--r--doc/impstats.html60
-rw-r--r--doc/rsyslog_conf_modules.html1
-rw-r--r--plugins/impstats/Makefile.am6
-rw-r--r--plugins/impstats/impstats.c211
8 files changed, 303 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index cfd1831d..0f8b625d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,10 @@
---------------------------------------------------------------------------
Version 5.7.0 [V5-DEVEL] (rgerhards), 2010-09-??
+- added module impstat to emit periodic statistics on rsyslog counters
- support for systemd officially added
-- acquire /dev/log socket optionally from systemd
- thanks to Lennart Poettering for this patch
+ * acquire /dev/log socket optionally from systemd
+ thanks to Lennart Poettering for this patch
+ * sd-systemd API added as part of rsyslog runtime library
---------------------------------------------------------------------------
Version 5.5.7 [V5-BETA] (rgerhards), 2010-08-09
- changed omudpspoof default spoof address to simplify typical use case
diff --git a/Makefile.am b/Makefile.am
index 76a38322..bc6d8dd0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -59,6 +59,10 @@ if ENABLE_IMKLOG
SUBDIRS += plugins/imklog
endif
+if ENABLE_IMPSTATS
+SUBDIRS += plugins/impstats
+endif
+
if ENABLE_IMSOLARIS
SUBDIRS += plugins/imsolaris
endif
@@ -191,5 +195,6 @@ DISTCHECK_CONFIGURE_FLAGS= --enable-gssapi_krb5 \
--enable-omuxsock \
--enable-shave \
--enable-extended-tests \
+ --enable-impstats \
--enable-memcheck
ACLOCAL_AMFLAGS = -I m4
diff --git a/configure.ac b/configure.ac
index 9c005a19..c52749c8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -792,6 +792,19 @@ AC_ARG_ENABLE(imptcp,
AM_CONDITIONAL(ENABLE_IMPTCP, test x$enable_imptcp = xyes)
+# settings for the pstats input module
+AC_ARG_ENABLE(impstats,
+ [AS_HELP_STRING([--enable-impstats],[periodic statistics module enabled @<:@default=no@:>@])],
+ [case "${enableval}" in
+ yes) enable_impstats="yes" ;;
+ no) enable_impstats="no" ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-impstats) ;;
+ esac],
+ [enable_impstats=no]
+)
+AM_CONDITIONAL(ENABLE_IMPSTATS, test x$enable_impstats = xyes)
+
+
# settings for the omprog output module
AC_ARG_ENABLE(omprog,
[AS_HELP_STRING([--enable-omprog],[Compiles omprog module @<:@default=no@:>@])],
@@ -1013,6 +1026,7 @@ AC_CONFIG_FILES([Makefile \
plugins/imfile/Makefile \
plugins/imsolaris/Makefile \
plugins/imptcp/Makefile \
+ plugins/impstats/Makefile \
plugins/imrelp/Makefile \
plugins/imdiag/Makefile \
plugins/omtesting/Makefile \
@@ -1049,6 +1063,7 @@ echo " plain tcp input module enabled: $enable_imptcp"
echo " imdiag enabled: $enable_imdiag"
echo " file input module enabled: $enable_imfile"
echo " Solaris input module enabled: $enable_imsolaris"
+echo " periodic statistics module enabled: $enable_impstats"
echo " input template module will be compiled: $enable_imtemplate"
echo
echo "---{ output plugins }---"
diff --git a/doc/Makefile.am b/doc/Makefile.am
index d4df740a..a5393cbe 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -41,6 +41,7 @@ html_files = \
imfile.html \
imtcp.html \
imptcp.html \
+ impstats.html \
imgssapi.html \
imrelp.html \
imsolaris.html \
diff --git a/doc/impstats.html b/doc/impstats.html
new file mode 100644
index 00000000..0f4096ab
--- /dev/null
+++ b/doc/impstats.html
@@ -0,0 +1,60 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head>
+<title>Periodic Statistics of Internal Counters (impstats)</title>
+</head>
+<body>
+<a href="rsyslog_conf_modules.html">back</a>
+
+<h1>Input Module to Generate Periodic Statistics of Internal Counters</h1>
+<p><b>Module Name:&nbsp;&nbsp;&nbsp; impstats</b></p>
+<p><b>Available since: </b>5.7.0+, 6.1.1+
+<p><b>Author: </b>Rainer Gerhards &lt;rgerhards@adiscon.com&gt;</p>
+<p><b>Description</b>:</p>
+<p>This module provides periodic output of rsyslog internal counters.
+Note that the whole statistics system is currently under development. So
+availabilty and format of counters may change and is not yet stable (so be
+prepared to change your trending scripts when you upgrade to a newer rsyslog version).
+<p>The set of available counters will be output as a set of syslog messages. This
+output is periodic, with the interval being configurable (default is 5 minutes).
+Be sure that your configuration records the counter messages (default is syslog.info).
+<p>Note that loading this module has impact on rsyslog performance. Depending on
+settings, this impact may be severe (for high-load environments).
+</p>
+<p><b>Configuration Directives</b>:</p>
+<ul>
+<li>$PStatsInterval &lt;Seconds&gt;<br>
+Sets the interval, in <b>seconds</b> at which messages are generated. Please note that the
+actual interval may be a bit longer. We do not try to be precise and so the interval is
+actually a sleep period which is entered after generating all messages. So the actual
+interval is what is configured here plus the actual time required to generate messages.
+In general, the difference should not really matter.
+<li>$PStatsFacility &lt;numerical facility&gt;<br>
+The numerical syslog facility code to be used for generated messages. Default
+is 5 (syslog).This is useful for filtering messages.</li>
+<li>$PStatsSeverity &lt;numerical severity&gt;<br>
+The numerical syslog severity code to be used for generated messages. Default
+is 6 (info).This is useful for filtering messages.</li>
+</ul>
+<b>Caveats/Known Bugs:</b>
+<ul>
+<li>experimental code</li>
+</ul>
+<p><b>Sample:</b></p>
+<p>This activates the module and records messages to /var/log/rsyslog-stats in 10 minute intervals:<br>
+</p>
+<textarea rows="8" cols="60">$ModLoad impstats
+$PStatsInterval 600
+$PStatsSeverity 7
+
+syslog.debug /var/log/rsyslog-stats
+</textarea>
+<p>[<a href="rsyslog_conf.html">rsyslog.conf overview</a>]
+[<a href="manual.html">manual index</a>] [<a href="http://www.rsyslog.com/">rsyslog site</a>]</p>
+<p><font size="2">This documentation is part of the
+<a href="http://www.rsyslog.com/">rsyslog</a>
+project.<br>
+Copyright &copy; 2010 by <a href="http://www.gerhards.net/rainer">Rainer
+Gerhards</a> and
+<a href="http://www.adiscon.com/">Adiscon</a>.
+Released under the GNU GPL version 3 or higher.</font></p>
+</body></html>
diff --git a/doc/rsyslog_conf_modules.html b/doc/rsyslog_conf_modules.html
index 2a64461d..85899954 100644
--- a/doc/rsyslog_conf_modules.html
+++ b/doc/rsyslog_conf_modules.html
@@ -44,6 +44,7 @@ to message generators.
<li><a href="imuxsock.html">imuxsock</a> - unix sockets, including the system log socket</li>
<li><a href="imsolaris.html">imsolaris</a> - input for the Sun Solaris system log source</li>
<li><a href="im3195.html">im3195</a> - accepts syslog messages via RFC 3195</li>
+<li><a href="impstats.html">impstats</a> - provides periodic statistics of rsyslog internal counters</li>
</ul>
<a name"om"></a><h2>Output Modules</h2>
diff --git a/plugins/impstats/Makefile.am b/plugins/impstats/Makefile.am
new file mode 100644
index 00000000..187bbca4
--- /dev/null
+++ b/plugins/impstats/Makefile.am
@@ -0,0 +1,6 @@
+pkglib_LTLIBRARIES = impstats.la
+
+impstats_la_SOURCES = impstats.c
+impstats_la_CPPFLAGS = $(RSRT_CFLAGS) -I$(top_srcdir) $(PTHREADS_CFLAGS)
+impstats_la_LDFLAGS = -module -avoid-version
+impstats_la_LIBADD =
diff --git a/plugins/impstats/impstats.c b/plugins/impstats/impstats.c
new file mode 100644
index 00000000..5f0d19eb
--- /dev/null
+++ b/plugins/impstats/impstats.c
@@ -0,0 +1,211 @@
+/* impstats.c
+ * A module to periodically output statistics gathered by rsyslog.
+ *
+ * NOTE: read comments in module-template.h to understand how this file
+ * works!
+ *
+ * File begun on 2007-07-20 by RGerhards (extracted from syslogd.c)
+ * This file is under development and has not yet arrived at being fully
+ * self-contained and a real object. So far, it is mostly an excerpt
+ * of the "old" message code without any modifications. However, it
+ * helps to have things at the right place one we go to the meat of it.
+ *
+ * Copyright 2010 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of rsyslog.
+ *
+ * Rsyslog is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Rsyslog is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ */
+#include "config.h"
+#include "rsyslog.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <signal.h>
+#include <string.h>
+#include <pthread.h>
+#include "dirty.h"
+#include "cfsysline.h"
+#include "module-template.h"
+#include "errmsg.h"
+#include "msg.h"
+#include "srUtils.h"
+#include "unicode-helper.h"
+#include "glbl.h"
+#include "prop.h"
+
+MODULE_TYPE_INPUT
+
+/* defines */
+#define DEFAULT_STATS_PERIOD (5 * 60)
+#define DEFAULT_FACILITY 5 /* syslog */
+#define DEFAULT_SEVERITY 6 /* info */
+
+/* Module static data */
+DEF_IMOD_STATIC_DATA
+DEFobjCurrIf(glbl)
+DEFobjCurrIf(prop)
+typedef struct configSettings_s {
+ int iStatsInterval;
+ int iFacility;
+ int iSeverity;
+} configSettings_t;
+
+static configSettings_t cs;
+
+static prop_t *pInputName = NULL;
+static prop_t *pLocalHostIP = NULL;
+
+BEGINisCompatibleWithFeature
+CODESTARTisCompatibleWithFeature
+ if(eFeat == sFEATURENonCancelInputTermination)
+ iRet = RS_RET_OK;
+ENDisCompatibleWithFeature
+
+static inline void
+initConfigSettings(void)
+{
+ cs.iStatsInterval = DEFAULT_STATS_PERIOD;
+ cs.iFacility = DEFAULT_FACILITY;
+ cs.iSeverity = DEFAULT_SEVERITY;
+}
+
+
+/* actually submit a message to the rsyslog core
+ */
+static inline rsRetVal
+doSubmitMsg(uchar *line)
+{
+ msg_t *pMsg;
+ DEFiRet;
+
+ CHKiRet(msgConstruct(&pMsg));
+ MsgSetInputName(pMsg, pInputName);
+ MsgSetRawMsgWOSize(pMsg, (char*)line);
+ MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName()));
+ MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp());
+ MsgSetRcvFromIP(pMsg, pLocalHostIP);
+ MsgSetMSGoffs(pMsg, 0);
+ MsgSetTAG(pMsg, UCHAR_CONSTANT("rsyslogd-pstats:"), sizeof("rsyslogd-pstats:") - 1);
+ pMsg->iFacility = cs.iFacility;
+ pMsg->iSeverity = cs.iSeverity;
+ pMsg->msgFlags = 0;
+
+ submitMsg(pMsg);
+
+finalize_it:
+ RETiRet;
+
+}
+
+
+/* the function to generate the actual statistics messages
+ * rgerhards, 2010-09-09
+ */
+static inline void
+generateStatsMsgs(void)
+{
+ int iMsgQueueSize;
+ uchar msg[1024];
+ rsRetVal iRet;
+
+ CHKiRet(diagGetMainMsgQSize(&iMsgQueueSize));
+ snprintf((char*)msg, sizeof(msg), "mainqueue size=%d", iMsgQueueSize);
+ doSubmitMsg(msg);
+
+finalize_it:
+ /*empty statement needed per C syntax*/;
+}
+
+
+BEGINrunInput
+CODESTARTrunInput
+ /* this is an endless loop - it is terminated when the thread is
+ * signalled to do so. This, however, is handled by the framework,
+ * right into the sleep below.
+ */
+ while(1) {
+dbgprintf("impstats: stats interval %d seconds - going to sleep\n", cs.iStatsInterval);
+ srSleep(cs.iStatsInterval, 0); /* seconds, micro seconds */
+dbgprintf("impstats: woke up\n");
+
+ if(glbl.GetGlobalInputTermState() == 1)
+ break; /* terminate input! */
+
+ generateStatsMsgs();
+ }
+ENDrunInput
+
+
+BEGINwillRun
+CODESTARTwillRun
+ DBGPRINTF("impstats: stats interval %d seconds\n", cs.iStatsInterval);
+ if(cs.iStatsInterval == 0)
+ ABORT_FINALIZE(RS_RET_NO_RUN);
+finalize_it:
+ENDwillRun
+
+
+BEGINafterRun
+CODESTARTafterRun
+ENDafterRun
+
+
+BEGINmodExit
+CODESTARTmodExit
+ /* release objects we used */
+ objRelease(glbl, CORE_COMPONENT);
+ objRelease(prop, CORE_COMPONENT);
+ENDmodExit
+
+
+
+BEGINqueryEtryPt
+CODESTARTqueryEtryPt
+CODEqueryEtryPt_STD_IMOD_QUERIES
+CODEqueryEtryPt_IsCompatibleWithFeature_IF_OMOD_QUERIES
+ENDqueryEtryPt
+
+static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
+{
+ initConfigSettings();
+ return RS_RET_OK;
+}
+
+
+BEGINmodInit()
+CODESTARTmodInit
+ *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
+CODEmodInit_QueryRegCFSLineHdlr
+ DBGPRINTF("impstats version %s loading\n", VERSION);
+ initConfigSettings();
+ CHKiRet(objUse(glbl, CORE_COMPONENT));
+ CHKiRet(objUse(prop, CORE_COMPONENT));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatsinterval", 0, eCmdHdlrInt, NULL, &cs.iStatsInterval, STD_LOADABLE_MODULE_ID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatfacility", 0, eCmdHdlrInt, NULL, &cs.iFacility, STD_LOADABLE_MODULE_ID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatseverity", 0, eCmdHdlrInt, NULL, &cs.iSeverity, STD_LOADABLE_MODULE_ID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
+
+ CHKiRet(prop.Construct(&pInputName));
+ CHKiRet(prop.SetString(pInputName, UCHAR_CONSTANT("rsyslogd-pstats"), sizeof("rsyslogd-pstats") - 1));
+ CHKiRet(prop.ConstructFinalize(pInputName));
+
+ CHKiRet(prop.Construct(&pLocalHostIP));
+ CHKiRet(prop.SetString(pLocalHostIP, UCHAR_CONSTANT("127.0.0.1"), sizeof("127.0.0.1") - 1));
+ CHKiRet(prop.ConstructFinalize(pLocalHostIP));
+ENDmodInit
+/* vi:set ai:
+ */