summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4e5f4b3)
raw | patch | inline | side by side (parent: 4e5f4b3)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 28 Mar 2007 06:38:02 +0000 (08:38 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 28 Mar 2007 06:38:02 +0000 (08:38 +0200) |
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/network.c | patch | blob | history |
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 2b3494689f4d9da70e3b8672b6c2a648569eab83..d1614b79a492d89c594af66dbf3c8dc32776fb26 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
# Listen "239.192.74.66" "25826"
# TimeToLive "128"
# Forward false
+# CacheFlush 1800
#</Plugin>
#<Plugin ntpd>
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 02e6def1f24b9cb386eff06fdb8bfc41441fc804..98612dce1ebf1cab45188ca1a1062c04c1863a75 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
neccessary it's not a huge problem since the plugin has a duplicate detection,
so the values will not loop.
+=item B<CacheFlush> I<Seconds>
+
+For each host/plugin/type combination the C<network plugin> caches the time of
+the last value being sent or received. Every I<Seconds> seconds the plugin
+searches and removes all entries that are older than I<Seconds> seconds, thus
+freeing the unused memory again. Since this process is somewhat expensive and
+normally doesn't do much, this value should not be too small. The default is
+1800 seconds, but setting this to 86400 seconds (one day) will not do much harm
+either.
+
=back
=head2 Plugin C<ntpd>
diff --git a/src/network.c b/src/network.c
index 96d48f8bbcf790b7bba7c5bd9713479c93c5a7eb..6d86c1d0dc8c0022272f5352480346066f5e12ce 100644 (file)
--- a/src/network.c
+++ b/src/network.c
*/
static const char *config_keys[] =
{
+ "CacheFlush",
"Listen",
"Server",
"TimeToLive",
static avl_tree_t *cache_tree = NULL;
static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
+static time_t cache_flush_last;
+static int cache_flush_interval = 1800;
/*
* Private functions
*/
+static int cache_flush (void)
+{
+ char **keys = NULL;
+ int keys_num = 0;
+
+ char **tmp;
+ int i;
+
+ char *key;
+ time_t *value;
+ avl_iterator_t *iter;
+
+ time_t curtime = time (NULL);
+
+ iter = avl_get_iterator (cache_tree);
+ while (avl_iterator_next (iter, (void *) &key, (void *) &value) == 0)
+ {
+ if ((curtime - *value) <= cache_flush_interval)
+ continue;
+ tmp = (char **) realloc (keys,
+ (keys_num + 1) * sizeof (char *));
+ if (tmp == NULL)
+ {
+ sfree (keys);
+ avl_iterator_destroy (iter);
+ ERROR ("network plugin: cache_flush: realloc"
+ " failed.");
+ return (-1);
+ }
+ keys = tmp;
+ keys[keys_num] = key;
+ keys_num++;
+ } /* while (avl_iterator_next) */
+ avl_iterator_destroy (iter);
+
+ for (i = 0; i < keys_num; i++)
+ {
+ if (avl_remove (cache_tree, keys[i], (void *) &key,
+ (void *) &value) != 0)
+ {
+ WARNING ("network plugin: cache_flush: avl_remove"
+ " (%s) failed.", keys[i]);
+ continue;
+ }
+
+ sfree (key);
+ sfree (value);
+ }
+
+ sfree (keys);
+
+ DEBUG ("network plugin: cache_flush: Removed %i %s",
+ keys_num, (keys_num == 1) ? "entry" : "entries");
+ cache_flush_last = curtime;
+ return (0);
+} /* int cache_flush */
+
static int cache_check (const char *type, const value_list_t *vl)
{
char key[1024];
}
}
- /* TODO: Flush cache */
+ if ((time (NULL) - cache_flush_last) > cache_flush_interval)
+ cache_flush ();
pthread_mutex_unlock (&cache_lock);
else
network_config_forward = 0;
}
+ else if (strcasecmp ("CacheFlush", key) == 0)
+ {
+ int tmp = atoi (val);
+ if (tmp > 0)
+ cache_flush_interval = tmp;
+ else return (1);
+ }
else
{
return (-1);
}
return (0);
-}
+} /* int network_config */
static int network_shutdown (void)
{
memset (send_buffer_type, '\0', sizeof (send_buffer_type));
cache_tree = avl_create ((int (*) (const void *, const void *)) strcmp);
+ cache_flush_last = time (NULL);
/* setup socket(s) and so on */
if (sending_sockets != NULL)