From ea78b1cbf46034df20ab3cfb3dabf255e5755264 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Thu, 30 Oct 2008 19:15:41 +0100 Subject: [PATCH] filecount plugin: Added the "Recursive" config option. This option controls whether or not to recurse into subdirectories. It's enabled by default, so backward-compatibility is retained. --- src/collectd.conf.in | 1 + src/collectd.conf.pod | 4 ++++ src/filecount.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 4963a060..ae4cde6b 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -168,6 +168,7 @@ FQDNLookup true # Name "*.conf" # MTime "-5m" # Size "+10k" +# Recursive true # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 624f74d3..d2656eea 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -646,6 +646,10 @@ description see above. Valid multipliers here are C (byte), C (kilobyte), C (megabyte), C (gigabyte), C (terabyte), and C

(petabyte). Please note that there are 1000 bytes in a kilobyte, not 1024. +=item B I|I + +Controls whether or not to recurse into subdirectories. Enabled by default. + =back =head2 Plugin C diff --git a/src/filecount.c b/src/filecount.c index 55b3655e..3e6e6465 100644 --- a/src/filecount.c +++ b/src/filecount.c @@ -31,11 +31,15 @@ #include #include +#define FC_RECURSIVE 1 + struct fc_directory_conf_s { char *path; char *instance; + int options; + /* Data counters */ uint64_t files_num; uint64_t files_size; @@ -307,6 +311,25 @@ static int fc_config_add_dir_size (fc_directory_conf_t *dir, return (0); } /* int fc_config_add_dir_size */ +static int fc_config_add_dir_recursive (fc_directory_conf_t *dir, + oconfig_item_t *ci) +{ + if ((ci->values_num != 1) + || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) + { + WARNING ("filecount plugin: The `Recursive' config options needs exactly " + "one boolean argument."); + return (-1); + } + + if (ci->values[0].value.boolean) + dir->options |= FC_RECURSIVE; + else + dir->options &= ~FC_RECURSIVE; + + return (0); +} /* int fc_config_add_dir_recursive */ + static int fc_config_add_dir (oconfig_item_t *ci) { fc_directory_conf_t *dir; @@ -338,6 +361,8 @@ static int fc_config_add_dir (oconfig_item_t *ci) fc_config_set_instance (dir, dir->path); + dir->options = FC_RECURSIVE; + dir->name = NULL; dir->mtime = 0; dir->size = 0; @@ -355,6 +380,8 @@ static int fc_config_add_dir (oconfig_item_t *ci) status = fc_config_add_dir_mtime (dir, option); else if (strcasecmp ("Size", option->key) == 0) status = fc_config_add_dir_size (dir, option); + else if (strcasecmp ("Recursive", option->key) == 0) + status = fc_config_add_dir_recursive (dir, option); else { WARNING ("filecount plugin: fc_config_add_dir: " @@ -447,7 +474,7 @@ static int fc_read_dir_callback (const char *dirname, const char *filename, return (-1); } - if (S_ISDIR (statbuf.st_mode)) + if (S_ISDIR (statbuf.st_mode) && (dir->options & FC_RECURSIVE)) { status = walk_directory (abs_path, fc_read_dir_callback, dir); return (status); -- 2.30.2