You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2017/05/14 19:25:16 UTC
[trafficserver] branch master updated: Add options to the tcpinfo
plugin to allow better control over custum logfile rolling.
This is an automated email from the ASF dual-hosted git repository.
jpeach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new a1aad8d Add options to the tcpinfo plugin to allow better control over custum logfile rolling.
a1aad8d is described below
commit a1aad8d9381ecc9125a578b835dfaf5ed7419e10
Author: jrushf1239k <Jo...@cable.comcast.com>
AuthorDate: Wed May 10 19:59:53 2017 +0000
Add options to the tcpinfo plugin to allow better control over custum logfile rolling.
clang-format
Incorporate changes requested in code review.
---
doc/admin-guide/plugins/tcpinfo.en.rst | 28 +++++++++++++
plugins/tcpinfo/tcpinfo.cc | 72 +++++++++++++++++++++++++++++-----
2 files changed, 90 insertions(+), 10 deletions(-)
diff --git a/doc/admin-guide/plugins/tcpinfo.en.rst b/doc/admin-guide/plugins/tcpinfo.en.rst
index 260ac84..a051f1e 100644
--- a/doc/admin-guide/plugins/tcpinfo.en.rst
+++ b/doc/admin-guide/plugins/tcpinfo.en.rst
@@ -103,6 +103,34 @@ The following options may be specified in :file:`plugin.config`:
not required to be in the configuration file. To achieve a log rate
of 1% you would set this value to 10.
+--rolling-enabled=VALUE
+ This logfile option allows you to set logfile rolling behaviour of
+ the output log file without making any changes to the global
+ logging configurations. This option overrides the
+ :ts:cv:`proxy.config.output.logfile.rolling_enabled` setting in records.config
+ for the ``tcpinfo`` plugin. The setting may range from ``0`` to ``3``.
+ ``0`` disables logfile rolling. ``1`` is the ``default`` and enables logfile
+ rolling at specfic intervals set by ``--rolling-interval-sec`` discussed
+ below. ``2`` enables logfile rolling by logfile size, see
+ ``--rolling-size-mb`` below. Finally a value of ``3`` enables logfile rolling
+ at specfic intervals or size, whichever occurs first using the interval or size
+ settings discussed below.
+
+--rolling-offset-hr=VALUE
+ Set the hour ``0`` to ``23`` at which the output log file will roll when
+ using interval rolling. Default value is ``0``.
+
+--rolling-interval-sec=VALUE
+ Set the rolling interval in seconds for the output log file. May be set
+ from ``60`` to ``86400`` seconds, Defaults to ``86400``.
+
+--rolling-size=VALUE
+ Set the size in MB at which the output log file will roll when using log size
+ rolling. Minimum value is ``10``, defaults to ``1024``. In your config file,
+ you may use the K, M, or G suffix as in::
+
+ --rolling-size=10M
+
Examples:
---------
diff --git a/plugins/tcpinfo/tcpinfo.cc b/plugins/tcpinfo/tcpinfo.cc
index b5e0a12..c0e451a 100644
--- a/plugins/tcpinfo/tcpinfo.cc
+++ b/plugins/tcpinfo/tcpinfo.cc
@@ -23,6 +23,7 @@
#include <cstdio>
#include <cstdlib>
+#include <memory>
#include <ts/ts.h>
#include <unistd.h>
#include <netinet/in.h>
@@ -38,6 +39,7 @@
#include <arpa/inet.h>
#include "ts/ink_defs.h"
+#include "ts/ParseRules.h"
#if defined(TCP_INFO) && defined(HAVE_STRUCT_TCP_INFO)
#define TCPI_PLUGIN_SUPPORTED 1
@@ -58,11 +60,10 @@ static const char *tcpi_headers[] = {
};
struct Config {
- int sample;
- unsigned log_level;
- TSTextLogObject log;
+ int sample = 1000;
+ unsigned int log_level = 1;
+ TSTextLogObject log = nullptr;
- Config() : sample(1000), log_level(1), log(nullptr) {}
~Config()
{
if (log) {
@@ -298,20 +299,32 @@ parse_hook_list(const char *hook_list)
void
TSPluginInit(int argc, const char *argv[])
{
- static const char usage[] = "tcpinfo.so [--log-file=PATH] [--log-level=LEVEL] [--hooks=LIST] [--sample-rate=COUNT]";
+ static const char usage[] = "tcpinfo.so [--log-file=PATH] [--log-level=LEVEL] [--hooks=LIST] [--sample-rate=COUNT] "
+ "[--rolling-enabled=VALUE] [--rolling-offset-hr=HOUR] [--rolling-interval-sec=SECONDS] "
+ "[--rolling-size=MB]";
static const struct option longopts[] = {
{const_cast<char *>("sample-rate"), required_argument, nullptr, 'r'},
{const_cast<char *>("log-file"), required_argument, nullptr, 'f'},
{const_cast<char *>("log-level"), required_argument, nullptr, 'l'},
{const_cast<char *>("hooks"), required_argument, nullptr, 'h'},
+ {const_cast<char *>("rolling-enabled"), required_argument, nullptr, 'e'},
+ {const_cast<char *>("rolling-offset-hr"), required_argument, nullptr, 'H'},
+ {const_cast<char *>("rolling-interval-sec"), required_argument, nullptr, 'S'},
+ {const_cast<char *>("rolling-size"), required_argument, nullptr, 'M'},
{nullptr, 0, nullptr, 0},
};
TSPluginRegistrationInfo info;
- Config *config = new Config();
+ std::unique_ptr<Config> config;
const char *filename = "tcpinfo";
TSCont cont;
- unsigned hooks = 0;
+ unsigned int hooks = 0;
+ unsigned int rolling_enabled = 1;
+ unsigned int rolling_interval_sec = 86400;
+ unsigned int rolling_offset_hr = 0;
+ unsigned int rolling_size = 1024;
+ unsigned int i = 0;
+ char *endptr;
info.plugin_name = (char *)"tcpinfo";
info.vendor_name = (char *)"Apache Software Foundation";
@@ -324,7 +337,7 @@ TSPluginInit(int argc, const char *argv[])
for (;;) {
unsigned long lval;
- switch (getopt_long(argc, (char *const *)argv, "r:f:l:h:", longopts, nullptr)) {
+ switch (getopt_long(argc, (char *const *)argv, "r:f:l:h:e:H:S:M:", longopts, NULL)) {
case 'r':
if (parse_unsigned(optarg, lval)) {
config->sample = atoi(optarg);
@@ -345,6 +358,38 @@ TSPluginInit(int argc, const char *argv[])
case 'h':
hooks = parse_hook_list(optarg);
break;
+ case 'e':
+ i = strtoul(optarg, &endptr, 10);
+ if (*endptr != '\0' || i > 3) {
+ TSError("[tcpinfo] invalid rolling-enabled argument, '%s', using default of %d.", optarg, rolling_enabled);
+ } else {
+ rolling_enabled = i;
+ }
+ break;
+ case 'H':
+ i = strtoul(optarg, &endptr, 10);
+ if (*endptr != '\0' || i > 23) {
+ TSError("[tcpinfo] invalid rolling-offset-hr argument, '%s', using default of %d.", optarg, rolling_offset_hr);
+ } else {
+ rolling_offset_hr = i;
+ }
+ break;
+ case 'S':
+ i = strtoul(optarg, &endptr, 10);
+ if (*endptr != '\0' || i < 60 || i > 86400) {
+ TSError("[tcpinfo] invalid rolling-interval-sec argument, '%s', using default of %d.", optarg, rolling_interval_sec);
+ } else {
+ rolling_interval_sec = i;
+ }
+ break;
+ case 'M':
+ i = ink_atoui(optarg);
+ if (i < 10) {
+ TSError("[tcpinfo] invalid rolling-size argument, '%s', using default of %d.", optarg, rolling_size);
+ } else {
+ rolling_size = i;
+ }
+ break;
case -1:
goto init;
default:
@@ -365,14 +410,21 @@ init:
if (TSTextLogObjectCreate(filename, TS_LOG_MODE_ADD_TIMESTAMP, &config->log) != TS_SUCCESS) {
TSError("[tcpinfo] failed to create log file '%s'", filename);
- delete config;
return;
}
+ if (TSTextLogObjectRollingEnabledSet(config->log, rolling_enabled) != TS_SUCCESS) {
+ TSError("[tcpinfo] failed to enable log file rolling to: '%d'", rolling_enabled);
+ return;
+ } else {
+ TSTextLogObjectRollingIntervalSecSet(config->log, rolling_interval_sec);
+ TSTextLogObjectRollingOffsetHrSet(config->log, rolling_offset_hr);
+ TSTextLogObjectRollingSizeMbSet(config->log, rolling_size);
+ }
TSTextLogObjectHeaderSet(config->log, tcpi_headers[config->log_level - 1]);
cont = TSContCreate(tcp_info_hook, nullptr);
- TSContDataSet(cont, config);
+ TSContDataSet(cont, config.release());
if (hooks & TCPI_HOOK_SSN_START) {
TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, cont);
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].