Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions plugins/in_tail/tail.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static int in_tail_collect_pending(struct flb_input_instance *ins,
if (file->watch_fd == -1 ||
(file->offset >= file->size)) {
/* Gather current file size */
ret = fstat(file->fd, &st);
ret = flb_tail_file_stat(file, &st);
if (ret == -1) {
flb_errno();
flb_tail_file_remove(file);
Expand Down Expand Up @@ -343,7 +343,7 @@ int in_tail_collect_event(void *file, struct flb_config *config)
struct stat st;
struct flb_tail_file *f = file;

ret = fstat(f->fd, &st);
ret = flb_tail_file_stat(f, &st);
if (ret == -1) {
flb_tail_file_remove(f);
return 0;
Expand Down Expand Up @@ -619,6 +619,13 @@ static struct flb_config_map config_map[] = {
FLB_CONFIG_MAP_INT, "progress_check_interval_nsec", "0",
0, FLB_TRUE, offsetof(struct flb_tail_config, progress_check_interval_nsec),
},
{
FLB_CONFIG_MAP_STR, "fstat_interval", "250ms",
0, FLB_FALSE, 0,
"interval for fstat mode event polling. Controls how often files are checked "
"for changes when using stat-based file watching (instead of inotify). "
"Default is 250ms. Supports time suffixes: s, ms, us, ns."
},
{
FLB_CONFIG_MAP_TIME, "rotate_wait", FLB_TAIL_ROTATE_WAIT,
0, FLB_TRUE, offsetof(struct flb_tail_config, rotate_wait),
Expand Down Expand Up @@ -719,7 +726,14 @@ static struct flb_config_map config_map[] = {
0, FLB_TRUE, offsetof(struct flb_tail_config, skip_empty_lines),
"Allows to skip empty lines."
},

{
FLB_CONFIG_MAP_BOOL, "keep_file_handle", "true",
0, FLB_TRUE, offsetof(struct flb_tail_config, keep_file_handle),
"When set to false, the file handle will be reopened every time we read "
"from the source tailed file and closed when done, to avoid keeping it open. "
"Useful for SMB shares and network filesystems where keeping handles open "
"can cause issues."
},
{
FLB_CONFIG_MAP_BOOL, "truncate_long_lines", "false",
0, FLB_TRUE, offsetof(struct flb_tail_config, truncate_long_lines),
Expand Down
43 changes: 43 additions & 0 deletions plugins/in_tail/tail_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *ins,
ctx->ins = ins;
ctx->ignore_older = 0;
ctx->skip_long_lines = FLB_FALSE;
ctx->keep_file_handle = FLB_TRUE; /* default: keep file handle open */
ctx->fstat_interval_nsec = 250000000; /* default: 250ms */
#ifdef FLB_HAVE_SQLDB
ctx->db_sync = 1; /* sqlite sync 'normal' */
#endif
Expand Down Expand Up @@ -189,6 +191,47 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *ins,
}
}

/* Config: fstat mode event polling interval */
tmp = flb_input_get_property("fstat_interval", ins);
if (tmp) {
/* Support suffixes: s, ms, us, ns; also allow plain seconds and fractional seconds */
char *end = NULL;
double val = strtod(tmp, &end);
uint64_t mult = 1000000000ULL; /* default: seconds */

if (end != NULL && *end != '\0') {
if (strcasecmp(end, "s") == 0) mult = 1000000000ULL;
else if (strcasecmp(end, "ms") == 0) mult = 1000000ULL;
else if (strcasecmp(end, "us") == 0) mult = 1000ULL;
else if (strcasecmp(end, "ns") == 0) mult = 1ULL;
else {
flb_plg_error(ctx->ins, "invalid 'fstat_interval' unit in value (%s)", tmp);
flb_tail_config_destroy(ctx);
return NULL;
}
}

if (val <= 0) {
flb_plg_error(ctx->ins, "invalid 'fstat_interval' value (%s)", tmp);
flb_tail_config_destroy(ctx);
return NULL;
}

/* Convert to nanoseconds with clamping to reasonable bounds */
double nsec_d = val * (double) mult;
if (nsec_d < 1.0) {
flb_plg_error(ctx->ins, "'fstat_interval' too small (%s)", tmp);
flb_tail_config_destroy(ctx);
return NULL;
}
ctx->fstat_interval_nsec = (uint64_t) nsec_d;

if (ctx->fstat_interval_nsec <= 1000000ULL) {
flb_plg_warn(ctx->ins, "very low fstat_interval (%" PRIu64 " ns) may cause high CPU usage",
ctx->fstat_interval_nsec);
}
}

/* Config: seconds interval to monitor file after rotation */
if (ctx->rotate_wait <= 0) {
flb_plg_error(ctx->ins, "invalid 'rotate_wait' config value");
Expand Down
4 changes: 4 additions & 0 deletions plugins/in_tail/tail_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ struct flb_tail_config {
int progress_check_interval; /* watcher interval */
int progress_check_interval_nsec; /* watcher interval */

uint64_t fstat_interval_nsec; /* fstat mode event polling interval (nanoseconds) */

int keep_file_handle; /* keep file handle open during tail (default: true) */

#ifdef FLB_HAVE_INOTIFY
int inotify_watcher; /* enable/disable inotify monitor */
#endif
Expand Down
Loading
Loading