* pcp/src/pmdas/logger/logger.h: New file.
* pcp/src/pmdas/logger/loggerMain.c: New custom main loop.
* pcp/src/pmdas/logger/logger.c (main): Added option for logfile to
monitor and calls new custom main loop.
* pcp/src/pmdas/logger/Install: Asks for logfile name to monitor.
* pcp/src/pmdas/logger/GNUmakefile: Added loggerMain.c and logger.h.
TARGETS = $(CMDTARGET) $(LIBTARGET)
DFILES = README
-CFILES = logger.c percontext.c
-HFILES = percontext.h
+CFILES = logger.c percontext.c loggerMain.c
+HFILES = percontext.h logger.h
LLDLIBS = -lpcp -lpcp_pmda
LCFLAGS = -I.
LSRCFILES = Install Remove pmns help $(DFILES) root GNUmakefile.install
default_pcp default: domain.h $(TARGETS)
logger.o percontext.o: percontext.h
+logger.o loggerMain.o: logger.h
include $(BUILDRULES)
# Do it
#
pmdaSetup
+
+# Get logfile to monitor
+if $do_pmda
+then
+ args=""
+
+ $PCP_ECHO_PROG $PCP_ECHO_N "Logfile path to monintor? ""$PCP_ECHO_C"
+ read value
+
+ if [ -z "$value" ]
+ then
+ echo "Error: logfile path must be specifed." >&2
+ exit 1
+ else
+ if [ ! -e $value ]
+ then
+ echo "Warning: logfile $value doesn't exist! Reinstall to change."
+ fi
+ args="$args -m $value"
+ fi
+fi
+
pmdaInstall
exit 0
#include <pcp/impl.h>
#include <pcp/pmda.h>
#include "domain.h"
+#include "logger.h"
#include "percontext.h"
/*
static char mypath[MAXPATHLEN];
static int isDSO = 1; /* ==0 if I am a daemon */
+char *monitor_path = NULL;
void
logger_end_contextCallBack(int ctx)
fprintf(stderr, "Usage: %s [options]\n\n", pmProgname);
fputs("Options:\n"
" -d domain use domain (numeric) for metrics domain of PMDA\n"
- " -l logfile write log into logfile rather than using default log name\n",
+ " -l logfile write log into logfile rather than using default log name\n"
+ " -m logfile logfile to monitor (required)\n",
stderr);
exit(1);
}
int
main(int argc, char **argv)
{
+ int c;
int err = 0;
int sep = __pmPathSeparator();
pmdaInterface desc;
pmdaDaemon(&desc, PMDA_INTERFACE_5, pmProgname, LOGGER,
"logger.log", mypath);
- if (pmdaGetOpt(argc, argv, "D:d:l:?", &desc, &err) != EOF)
- err++;
- if (err)
+ while ((c = pmdaGetOpt(argc, argv, "D:d:l:m:?", &desc, &err)) != EOF) {
+ switch (c) {
+ case 'm':
+ monitor_path = optarg;
+ break;
+ default:
+ err++;
+ break;
+ }
+ }
+ if (err || monitor_path == NULL)
usage();
pmdaOpenLog(&desc);
signal(SIGHUP, SIG_IGN);
#endif
- pmdaMain(&desc);
+ // We use our custom main.
+ loggerMain(&desc);
exit(0);
}
--- /dev/null
+extern char *monitor_path;
+
+extern void loggerMain(pmdaInterface *dispatch);
--- /dev/null
+#include <pcp/pmapi.h>
+#include <pcp/impl.h>
+#include <pcp/pmda.h>
+#include <sys/select.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "logger.h"
+
+void
+loggerMain(pmdaInterface *dispatch)
+{
+ int pmcdfd = __pmdaInFd(dispatch);
+ int maxfd;
+ fd_set fds;
+ fd_set readyfds;
+ int nready;
+ int monitorfd;
+
+ /* Try to open logfile to monitor */
+ monitorfd = open(monitor_path, O_RDONLY);
+ if (monitorfd < 0) {
+ __pmNotifyErr(LOG_ERR, "open failure on %s", monitor_path);
+ exit(1);
+ }
+
+ FD_ZERO(&fds);
+ FD_SET(monitorfd, &fds);
+ FD_SET(pmcdfd, &fds);
+ maxfd = (monitorfd > pmcdfd) ? monitorfd : pmcdfd;
+
+ for (;;) {
+ memcpy(&readyfds, &fds, sizeof(readyfds));
+ nready = select(maxfd+1, &readyfds, NULL, NULL, NULL);
+
+ if (nready == 0)
+ continue;
+ else if (nready < 0) {
+ if (errno != EINTR) {
+ __pmNotifyErr(LOG_ERR, "select failure");
+ exit(1);
+ }
+ continue;
+ }
+
+ if (FD_ISSET(pmcdfd, &readyfds)) {
+#ifdef PCP_DEBUG
+ if (pmDebug & DBG_TRACE_APPL0)
+ __pmNotifyErr(LOG_DEBUG, "processing pmcd request [fd=%d]", pmcdfd);
+#endif
+ if (__pmdaMainPDU(dispatch) < 0) {
+ exit(1); /* fatal if we lose pmcd */
+ }
+ }
+ if (FD_ISSET(monitorfd, &readyfds)) {
+ /* do something with logfile input */
+ }
+ }
+}