summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bab707f)
raw | patch | inline | side by side (parent: bab707f)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 13 May 2008 10:53:11 +0000 (12:53 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 13 May 2008 10:53:57 +0000 (12:53 +0200) |
The flush callbacks have been changed to expect an (optional)
`const char *instance'. If not NULL, *only* that value should be flushed.
The network and perl plugins don't follow this rule yet, but will in the
not so far future - hopefully ;)
`const char *instance'. If not NULL, *only* that value should be flushed.
The network and perl plugins don't follow this rule yet, but will in the
not so far future - hopefully ;)
src/network.c | patch | blob | history | |
src/perl.c | patch | blob | history | |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history | |
src/rrdtool.c | patch | blob | history |
diff --git a/src/network.c b/src/network.c
index 4e1504f51f1aabda5c410fbae018f9ed29e81200..cf01b719b026254a303b92afeca044d9130f589b 100644 (file)
--- a/src/network.c
+++ b/src/network.c
return (0);
} /* int network_init */
-static int network_flush (int timeout)
+/* TODO: Implement flushing of single items. */
+static int network_flush (int timeout, const char *itentifier)
{
pthread_mutex_lock (&send_buffer_lock);
diff --git a/src/perl.c b/src/perl.c
index 66cac7efa1aad3c8c1e1c66cb723713463d1de4a..43f919745cc0ce1ca5a4ef16dfe7668fc223de81 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
return pplugin_call_all (aTHX_ PLUGIN_NOTIF, notif);
} /* static int perl_notify (const notification_t *) */
-static int perl_flush (const int timeout)
+/* TODO: Implement flushing of single identifiers. */
+static int perl_flush (int timeout, const char *identifier)
{
dTHX;
diff --git a/src/plugin.c b/src/plugin.c
index dfab52c3e4fcb68f15eae50e55aa76095fe7d1f9..cbd5477509b6abfe677eb846273345ae7619a44d 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
return (register_callback (&list_write, name, (void *) callback));
} /* int plugin_register_write */
-int plugin_register_flush (const char *name, int (*callback) (const int))
+int plugin_register_flush (const char *name,
+ int (*callback) (const int timeout, const char *identifier))
{
return (register_callback (&list_flush, name, (void *) callback));
} /* int plugin_register_flush */
}
} /* void plugin_flush_all */
+int plugin_flush (const char *plugin, int timeout, const char *identifier)
+{
+ int (*callback) (int timeout, const char *identifier);
+ llentry_t *le;
+
+ if (list_flush == NULL)
+ return (0);
+
+ le = llist_head (list_flush);
+ while (le != NULL)
+ {
+ if ((plugin != NULL)
+ && (strcmp (plugin, le->key) != 0))
+ continue;
+
+ callback = (int (*) (int, const char *)) le->value;
+ le = le->next;
+
+ (*callback) (timeout, identifier);
+ }
+} /* int plugin_flush */
+
void plugin_shutdown_all (void)
{
int (*callback) (void);
diff --git a/src/plugin.h b/src/plugin.h
index 488e041ed44964de0260ee5ac0d7f1e2b27ae0f3..ac389c6a8d3fc0feac891da8b66b1b6b4b025498 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
void plugin_init_all (void);
void plugin_read_all (void);
-void plugin_flush_all (int timeout);
void plugin_shutdown_all (void);
+void plugin_flush_all (int timeout);
int plugin_flush_one (int timeout, const char *name);
+int plugin_flush (const char *plugin, int timeout, const char *identifier);
/*
* The `plugin_register_*' functions are used to make `config', `init',
int plugin_register_write (const char *name,
int (*callback) (const data_set_t *ds, const value_list_t *vl));
int plugin_register_flush (const char *name,
- int (*callback) (const int));
+ int (*callback) (const int timeout, const char *identifier));
int plugin_register_shutdown (char *name,
int (*callback) (void));
int plugin_register_data_set (const data_set_t *ds);
diff --git a/src/rrdtool.c b/src/rrdtool.c
index 29e8a7d30ba144f0f5ccaabd491b21cd422d7999..6b9c5404c736c3bb9561bb9ff7d4946acf709a1b 100644 (file)
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
cache_flush_last = now;
} /* void rrd_cache_flush */
+static int rrd_cache_flush_identifier (int timeout, const char *identifier)
+{
+ rrd_cache_t *rc;
+ time_t now;
+ int status;
+ char *key;
+ size_t key_size;
+
+ if (identifier == NULL)
+ {
+ rrd_cache_flush (timeout);
+ return (0);
+ }
+
+ now = time (NULL);
+
+ key_size = strlen (identifier + 5) * sizeof (char);
+ key = (char *) malloc (key_size);
+ if (key == NULL)
+ {
+ ERROR ("rrdtool plugin: rrd_cache_flush_identifier: malloc failed.");
+ return (-1);
+ }
+ snprintf (key, key_size, "%s.rrd", identifier);
+ key[key_size - 1] = 0;
+
+ status = c_avl_get (cache, key, (void *) &rc);
+ if (status != 0)
+ {
+ WARNING ("rrdtool plugin: rrd_cache_flush_identifier: "
+ "c_avl_get (%s) failed. Does that file really exist?",
+ key);
+ return (status);
+ }
+
+ if (rc->flags == FLAG_QUEUED)
+ status = 0;
+ else if ((now - rc->first_value) < timeout)
+ status = 0;
+ else if (rc->values_num > 0)
+ {
+ status = rrd_queue_cache_entry (key);
+ if (status == 0)
+ rc->flags = FLAG_QUEUED;
+ }
+
+ return (status);
+} /* int rrd_cache_flush_identifier */
+
static int rrd_cache_insert (const char *filename,
const char *value, time_t value_time)
{
return (status);
} /* int rrd_write */
-static int rrd_flush (const int timeout)
+static int rrd_flush (int timeout, const char *identifier)
{
pthread_mutex_lock (&cache_lock);
return (0);
}
- rrd_cache_flush (timeout);
+ rrd_cache_flush_identifier (timeout, identifier);
+
pthread_mutex_unlock (&cache_lock);
return (0);
} /* int rrd_flush */