Commit 12e66557 authored by Geoff Simmons's avatar Geoff Simmons

trackrdrd: added usage and README

parent 6d02058b
.. _ref-varnishd:
==========
trackrdrd
==========
-------------------------
Tracking Log Reader demon
-------------------------
:Author: Geoffrey Simmons
:Date: 2012-09-23
:Version: 0.1
:Manual section: 3
SYNOPSIS
========
.. include:: synopsis.txt
DESCRIPTION
===========
The trackrdrd demon reads from the shared memory log of a running
instance of Varnish and collects data relevant to tracking for the
Lhotse project.
OPTIONS
=======
.. include:: options.txt
-n varnish_logfile
The 'varnish name' indicating the mmap'd log file used by
varnishd. By default, the host name is assumed (as with
varnishd).
-l log_file
Log file for status, warning, debug and error messages. If '-'
is specified, then log messages are written to stdout. By
default, syslog(3) is used for logging. Log levels correspond
to the 'priorities' defined by syslog(3).
-f varnishlog_bindump
A binary dump of the Varnish SHM log produced by 'varnishlog
-w'. If this option is specified, trackrdrd reads from the
dump instead of a live SHM log (useful for debugging and
replaying traffic). The options -f and -n are mutually
exclusive; -n is the default.
-d
Sets the log level to LOG_DEBUG. The default log level is
LOG_INFO.
-V
Print version and exit
-h
Print usage and exit
......@@ -2,7 +2,7 @@ INCLUDES = -I$(VARNISHSRC)/include -I$(VARNISHSRC)
bin_PROGRAMS = trackrdrd
nodist_trackrdrd_SOURCES = revision.h
nodist_trackrdrd_SOURCES = revision.h usage.h
trackrdrd_SOURCES = \
trackrdrd.h \
......@@ -20,10 +20,11 @@ check:
test/regress.sh
BUILT_SOURCES = revision.h usage.h
MAINTAINERCLEANFILES = revision.h usage.h
# Derive a revision name from the git commit
# Adopted from Varnish include/Makefile.am
BUILT_SOURCES = revision.h
MAINTAINERCLEANFILES = revision.h
revision.h: FORCE
@if [ -d "$(top_srcdir)/../.git" ]; then \
V="$$(git show -s --pretty=format:%h)" \
......@@ -51,4 +52,24 @@ revision.h: FORCE
) > revision.h ; \
fi \
fi
usage.h: $(top_srcdir)/synopsis.txt $(top_srcdir)/options.txt
( \
echo '/*' ;\
echo ' * NB: This file is machine generated, DO NOT EDIT!' ;\
echo ' *' ;\
echo ' * Run make to regenerate' ;\
echo ' *' ;\
echo ' */' ;\
echo '' ;\
echo 'const char *synopsis = ' \
) > usage.h
sed -e 's/.*/\"&\\n\"/' $(top_srcdir)/synopsis.txt >> usage.h
( \
echo ';' ;\
echo 'const char *options = ' \
) >> usage.h
sed -e 's/.*/\"&\\n\"/' $(top_srcdir)/options.txt >> usage.h
echo ';' >> usage.h
FORCE:
\ No newline at end of file
......@@ -56,6 +56,7 @@
#include "trackrdrd.h"
#include "revision.h"
#include "usage.h"
#define TRACK_TAGS "ReqStart,VCL_log,ReqEnd"
#define TRACKLOG_PREFIX "track "
......@@ -179,11 +180,10 @@ OSL_Track(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
/*--------------------------------------------------------------------*/
static void
usage(void)
usage(int status)
{
fprintf(stderr, "usage: varnishlog "
"%s [-aDV] [-o [tag regex]] [-n varnish_name] [-P file] [-w file]\n", VSL_USAGE);
exit(1);
fprintf(stderr, "Usage:\n%s\n%s\n", synopsis, options);
exit(status);
}
int
......@@ -191,7 +191,7 @@ main(int argc, char * const *argv)
{
int c;
int D_flag = 0, d_flag = 0;
const char *P_arg = NULL, *l_arg = NULL;
const char *P_arg = NULL, *l_arg = NULL, *n_arg = NULL, *f_arg = NULL;
struct vpf_fh *pfh = NULL;
struct VSM_data *vd;
......@@ -208,10 +208,10 @@ main(int argc, char * const *argv)
break;
case 'V':
printf(PACKAGE_STRING " revision " REVISION "\n");
exit(0);
exit(EXIT_SUCCESS);
case 'n':
if (VSL_Arg(vd, c, optarg) <= 0)
exit(1);
n_arg = optarg;
break;
case 'l':
l_arg = optarg;
break;
......@@ -219,21 +219,29 @@ main(int argc, char * const *argv)
d_flag = 1;
break;
case 'f':
if (VSL_Arg(vd, 'r', optarg) <= 0)
exit(1);
f_arg = optarg;
break;
case 'h':
usage(EXIT_SUCCESS);
default:
usage();
usage(EXIT_FAILURE);
}
}
if ((argc - optind) > 0)
usage();
usage(EXIT_FAILURE);
if (f_arg && n_arg)
usage(EXIT_FAILURE);
if (f_arg && VSL_Arg(vd, 'r', f_arg) <= 0)
exit(EXIT_FAILURE);
else if (n_arg && VSL_Arg(vd, 'n', n_arg) <= 0)
exit(EXIT_FAILURE);
if (LOG_Open(PACKAGE_NAME, l_arg) != 0) {
perror(l_arg);
exit(1);
exit(EXIT_FAILURE);
}
if (d_flag)
LOG_SetLevel(LOG_DEBUG);
......@@ -253,14 +261,14 @@ main(int argc, char * const *argv)
*/
if (P_arg && (pfh = VPF_Open(P_arg, 0644, NULL)) == NULL) {
perror(P_arg);
exit(1);
exit(EXIT_FAILURE);
}
if (pfh != NULL)
VPF_Write(pfh);
/* XXX: child opens and reads VSL */
if (VSL_Open(vd, 1))
exit(1);
exit(EXIT_FAILURE);
/* Only read the VSL tags relevant to tracking */
assert(VSL_Arg(vd, 'i', TRACK_TAGS) > 0);
......@@ -277,5 +285,5 @@ main(int argc, char * const *argv)
VPF_Remove(pfh);
LOG_Log0(LOG_INFO, "exiting");
exit(0);
exit(EXIT_SUCCESS);
}
trackrdrd [-n varnish_name] [-l log_file] [-f varnishlog_bindump]
[-d] [-V] [-h]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment