2
* A module to periodically output statistics gathered by rsyslog.
4
* NOTE: read comments in module-template.h to understand how this file
7
* File begun on 2007-07-20 by RGerhards (extracted from syslogd.c)
8
* This file is under development and has not yet arrived at being fully
9
* self-contained and a real object. So far, it is mostly an excerpt
10
* of the "old" message code without any modifications. However, it
11
* helps to have things at the right place one we go to the meat of it.
13
* Copyright 2010 Rainer Gerhards and Adiscon GmbH.
15
* This file is part of rsyslog.
17
* Rsyslog is free software: you can redistribute it and/or modify
18
* it under the terms of the GNU General Public License as published by
19
* the Free Software Foundation, either version 3 of the License, or
20
* (at your option) any later version.
22
* Rsyslog is distributed in the hope that it will be useful,
23
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
* GNU General Public License for more details.
27
* You should have received a copy of the GNU General Public License
28
* along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
30
* A copy of the GPL can be found in the file "COPYING" in this distribution.
41
#include "cfsysline.h"
42
#include "module-template.h"
46
#include "unicode-helper.h"
55
#define DEFAULT_STATS_PERIOD (5 * 60)
56
#define DEFAULT_FACILITY 5 /* syslog */
57
#define DEFAULT_SEVERITY 6 /* info */
59
/* Module static data */
63
DEFobjCurrIf(statsobj)
66
typedef struct configSettings_s {
72
static configSettings_t cs;
74
static prop_t *pInputName = NULL;
75
static prop_t *pLocalHostIP = NULL;
77
BEGINisCompatibleWithFeature
78
CODESTARTisCompatibleWithFeature
79
if(eFeat == sFEATURENonCancelInputTermination)
81
ENDisCompatibleWithFeature
84
initConfigSettings(void)
86
cs.iStatsInterval = DEFAULT_STATS_PERIOD;
87
cs.iFacility = DEFAULT_FACILITY;
88
cs.iSeverity = DEFAULT_SEVERITY;
92
/* actually submit a message to the rsyslog core
94
static inline rsRetVal
95
doSubmitMsg(uchar *line)
100
CHKiRet(msgConstruct(&pMsg));
101
MsgSetInputName(pMsg, pInputName);
102
MsgSetRawMsgWOSize(pMsg, (char*)line);
103
MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName()));
104
MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp());
105
MsgSetRcvFromIP(pMsg, pLocalHostIP);
106
MsgSetMSGoffs(pMsg, 0);
107
MsgSetTAG(pMsg, UCHAR_CONSTANT("rsyslogd-pstats:"), sizeof("rsyslogd-pstats:") - 1);
108
pMsg->iFacility = cs.iFacility;
109
pMsg->iSeverity = cs.iSeverity;
120
/* callback for statsobj
121
* Note: usrptr exists only to satisfy requirements of statsobj callback interface!
124
doStatsLine(void __attribute__((unused)) *usrptr, cstr_t *cstr)
127
doSubmitMsg(rsCStrGetSzStrNoNULL(cstr));
132
/* the function to generate the actual statistics messages
133
* rgerhards, 2010-09-09
136
generateStatsMsgs(void)
138
statsobj.GetAllStatsLines(doStatsLine, NULL);
144
/* this is an endless loop - it is terminated when the thread is
145
* signalled to do so. This, however, is handled by the framework,
146
* right into the sleep below.
149
srSleep(cs.iStatsInterval, 0); /* seconds, micro seconds */
151
if(glbl.GetGlobalInputTermState() == 1)
152
break; /* terminate input! */
162
DBGPRINTF("impstats: stats interval %d seconds\n", cs.iStatsInterval);
163
if(cs.iStatsInterval == 0)
164
ABORT_FINALIZE(RS_RET_NO_RUN);
165
localRet = statsobj.EnableStats();
166
if(localRet != RS_RET_OK) {
167
errmsg.LogError(0, localRet, "impstat: error enabling statistics gathering");
168
ABORT_FINALIZE(RS_RET_NO_RUN);
181
prop.Destruct(&pInputName);
182
prop.Destruct(&pLocalHostIP);
183
/* release objects we used */
184
objRelease(glbl, CORE_COMPONENT);
185
objRelease(prop, CORE_COMPONENT);
186
objRelease(errmsg, CORE_COMPONENT);
187
objRelease(statsobj, CORE_COMPONENT);
194
CODEqueryEtryPt_STD_IMOD_QUERIES
195
CODEqueryEtryPt_IsCompatibleWithFeature_IF_OMOD_QUERIES
198
static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
200
initConfigSettings();
207
*ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
208
CODEmodInit_QueryRegCFSLineHdlr
209
DBGPRINTF("impstats version %s loading\n", VERSION);
210
initConfigSettings();
211
CHKiRet(objUse(glbl, CORE_COMPONENT));
212
CHKiRet(objUse(prop, CORE_COMPONENT));
213
CHKiRet(objUse(errmsg, CORE_COMPONENT));
214
CHKiRet(objUse(statsobj, CORE_COMPONENT));
215
/* the pstatsinverval is an alias to support a previous screwed-up syntax... */
216
CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatsinterval", 0, eCmdHdlrInt, NULL, &cs.iStatsInterval, STD_LOADABLE_MODULE_ID));
217
CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatinterval", 0, eCmdHdlrInt, NULL, &cs.iStatsInterval, STD_LOADABLE_MODULE_ID));
218
CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatfacility", 0, eCmdHdlrInt, NULL, &cs.iFacility, STD_LOADABLE_MODULE_ID));
219
CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatseverity", 0, eCmdHdlrInt, NULL, &cs.iSeverity, STD_LOADABLE_MODULE_ID));
220
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
222
CHKiRet(prop.Construct(&pInputName));
223
CHKiRet(prop.SetString(pInputName, UCHAR_CONSTANT("impstats"), sizeof("impstats") - 1));
224
CHKiRet(prop.ConstructFinalize(pInputName));
226
CHKiRet(prop.Construct(&pLocalHostIP));
227
CHKiRet(prop.SetString(pLocalHostIP, UCHAR_CONSTANT("127.0.0.1"), sizeof("127.0.0.1") - 1));
228
CHKiRet(prop.ConstructFinalize(pLocalHostIP));