projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ChangeLog: Add missing notes about _REENTRANT and the sensors plugin.
[collectd.git]
/
src
/
rrdtool.c
diff --git
a/src/rrdtool.c
b/src/rrdtool.c
index
06d9763
..
3bb5a9e
100644
(file)
--- a/
src/rrdtool.c
+++ b/
src/rrdtool.c
@@
-24,6
+24,8
@@
#include "common.h"
#include "utils_avltree.h"
#include "common.h"
#include "utils_avltree.h"
+#include <rrd.h>
+
#if HAVE_PTHREAD_H
# include <pthread.h>
#endif
#if HAVE_PTHREAD_H
# include <pthread.h>
#endif
@@
-103,7
+105,7
@@
static double xff = 0.1;
static int cache_timeout = 0;
static int cache_flush_timeout = 0;
static time_t cache_flush_last;
static int cache_timeout = 0;
static int cache_flush_timeout = 0;
static time_t cache_flush_last;
-static avl_tree_t *cache = NULL;
+static
c_
avl_tree_t *cache = NULL;
static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
static rrd_queue_t *queue_head = NULL;
static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
static rrd_queue_t *queue_head = NULL;
@@
-639,7
+641,7
@@
static void *rrd_queue_thread (void *data)
* we make a copy of it's values */
pthread_mutex_lock (&cache_lock);
* we make a copy of it's values */
pthread_mutex_lock (&cache_lock);
- avl_get (cache, queue_entry->filename, (void *) &cache_entry);
+
c_
avl_get (cache, queue_entry->filename, (void *) &cache_entry);
values = cache_entry->values;
values_num = cache_entry->values_num;
values = cache_entry->values;
values_num = cache_entry->values_num;
@@
-652,6
+654,8
@@
static void *rrd_queue_thread (void *data)
/* Write the values to the RRD-file */
srrd_update (queue_entry->filename, NULL, values_num, values);
/* Write the values to the RRD-file */
srrd_update (queue_entry->filename, NULL, values_num, values);
+ DEBUG ("rrdtool plugin: queue thread: Wrote %i values to %s",
+ values_num, queue_entry->filename);
for (i = 0; i < values_num; i++)
{
for (i = 0; i < values_num; i++)
{
@@
-663,7
+667,7
@@
static void *rrd_queue_thread (void *data)
} /* while (42) */
pthread_mutex_lock (&cache_lock);
} /* while (42) */
pthread_mutex_lock (&cache_lock);
- avl_destroy (cache);
+
c_
avl_destroy (cache);
cache = NULL;
pthread_mutex_unlock (&cache_lock);
cache = NULL;
pthread_mutex_unlock (&cache_lock);
@@
-711,19
+715,17
@@
static void rrd_cache_flush (int timeout)
int keys_num = 0;
char *key;
int keys_num = 0;
char *key;
- avl_iterator_t *iter;
+
c_
avl_iterator_t *iter;
int i;
int i;
- DEBUG ("Flushing cache, timeout = %i", timeout);
+ DEBUG ("
rrdtool plugin:
Flushing cache, timeout = %i", timeout);
now = time (NULL);
/* Build a list of entries to be flushed */
now = time (NULL);
/* Build a list of entries to be flushed */
- iter = avl_get_iterator (cache);
- while (avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0)
+ iter =
c_
avl_get_iterator (cache);
+ while (
c_
avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0)
{
{
- DEBUG ("key = %s; age = %i;", key, now - rc->first_value);
-
if (rc->flags == FLAG_QUEUED)
continue;
else if ((now - rc->first_value) < timeout)
if (rc->flags == FLAG_QUEUED)
continue;
else if ((now - rc->first_value) < timeout)
@@
-735,29
+737,31
@@
static void rrd_cache_flush (int timeout)
}
else /* ancient and no values -> waste of memory */
{
}
else /* ancient and no values -> waste of memory */
{
-
keys
= (char **) realloc ((void *) keys,
+
char **tmp
= (char **) realloc ((void *) keys,
(keys_num + 1) * sizeof (char *));
(keys_num + 1) * sizeof (char *));
- if (
keys
== NULL)
+ if (
tmp
== NULL)
{
char errbuf[1024];
ERROR ("rrdtool plugin: "
"realloc failed: %s",
sstrerror (errno, errbuf,
sizeof (errbuf)));
{
char errbuf[1024];
ERROR ("rrdtool plugin: "
"realloc failed: %s",
sstrerror (errno, errbuf,
sizeof (errbuf)));
- avl_iterator_destroy (iter);
+ c_avl_iterator_destroy (iter);
+ sfree (keys);
return;
}
return;
}
+ keys = tmp;
keys[keys_num] = key;
keys_num++;
}
keys[keys_num] = key;
keys_num++;
}
- } /* while (avl_iterator_next) */
- avl_iterator_destroy (iter);
+ } /* while (
c_
avl_iterator_next) */
+
c_
avl_iterator_destroy (iter);
for (i = 0; i < keys_num; i++)
{
for (i = 0; i < keys_num; i++)
{
- if (avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0)
+ if (
c_
avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0)
{
{
- DEBUG ("avl_remove (%s) failed.", keys[i]);
+ DEBUG ("
rrdtool plugin: c_
avl_remove (%s) failed.", keys[i]);
continue;
}
continue;
}
@@
-769,8
+773,7
@@
static void rrd_cache_flush (int timeout)
keys[i] = NULL;
} /* for (i = 0..keys_num) */
keys[i] = NULL;
} /* for (i = 0..keys_num) */
- free (keys);
- DEBUG ("Flushed %i value(s)", keys_num);
+ sfree (keys);
cache_flush_last = now;
} /* void rrd_cache_flush */
cache_flush_last = now;
} /* void rrd_cache_flush */
@@
-784,7
+787,7
@@
static int rrd_cache_insert (const char *filename,
pthread_mutex_lock (&cache_lock);
pthread_mutex_lock (&cache_lock);
- avl_get (cache, filename, (void *) &rc);
+
c_
avl_get (cache, filename, (void *) &rc);
if (rc == NULL)
{
if (rc == NULL)
{
@@
-817,7
+820,7
@@
static int rrd_cache_insert (const char *filename,
sstrerror (errno, errbuf, sizeof (errbuf));
sstrerror (errno, errbuf, sizeof (errbuf));
- avl_remove (cache, filename, &cache_key, NULL);
+
c_
avl_remove (cache, filename, &cache_key, NULL);
pthread_mutex_unlock (&cache_lock);
ERROR ("rrdtool plugin: realloc failed: %s", errbuf);
pthread_mutex_unlock (&cache_lock);
ERROR ("rrdtool plugin: realloc failed: %s", errbuf);
@@
-857,11
+860,13
@@
static int rrd_cache_insert (const char *filename,
return (-1);
}
return (-1);
}
- avl_insert (cache, cache_key, rc);
+
c_
avl_insert (cache, cache_key, rc);
}
}
- DEBUG ("rrd_cache_insert (%s, %s, %u) = %p", filename, value,
- (unsigned int) value_time, (void *) rc);
+ DEBUG ("rrdtool plugin: rrd_cache_insert: file = %s; "
+ "values_num = %i; age = %u;",
+ filename, rc->values_num,
+ rc->last_value - rc->first_value);
if ((rc->last_value - rc->first_value) >= cache_timeout)
{
if ((rc->last_value - rc->first_value) >= cache_timeout)
{
@@
-888,6
+893,19
@@
static int rrd_cache_insert (const char *filename,
return (0);
} /* int rrd_cache_insert */
return (0);
} /* int rrd_cache_insert */
+static int rrd_compare_numeric (const void *a_ptr, const void *b_ptr)
+{
+ int a = *((int *) a_ptr);
+ int b = *((int *) b_ptr);
+
+ if (a < b)
+ return (-1);
+ else if (a > b)
+ return (1);
+ else
+ return (0);
+} /* int rrd_compare_numeric */
+
static int rrd_write (const data_set_t *ds, const value_list_t *vl)
{
struct stat statbuf;
static int rrd_write (const data_set_t *ds, const value_list_t *vl)
{
struct stat statbuf;
@@
-1026,6
+1044,12
@@
static int rrd_config (const char *key, const char *value)
if (rra_timespans_custom[rra_timespans_custom_num] != 0)
rra_timespans_custom_num++;
} /* while (strtok_r) */
if (rra_timespans_custom[rra_timespans_custom_num] != 0)
rra_timespans_custom_num++;
} /* while (strtok_r) */
+
+ qsort (/* base = */ rra_timespans_custom,
+ /* nmemb = */ rra_timespans_custom_num,
+ /* size = */ sizeof (rra_timespans_custom[0]),
+ /* compar = */ rrd_compare_numeric);
+
free (value_copy);
}
else if (strcasecmp ("XFF", key) == 0)
free (value_copy);
}
else if (strcasecmp ("XFF", key) == 0)
@@
-1057,6
+1081,14
@@
static int rrd_shutdown (void)
pthread_cond_signal (&queue_cond);
pthread_mutex_unlock (&queue_lock);
pthread_cond_signal (&queue_cond);
pthread_mutex_unlock (&queue_lock);
+ /* Wait for all the values to be written to disk before returning. */
+ if (queue_thread != 0)
+ {
+ pthread_join (queue_thread, NULL);
+ queue_thread = 0;
+ DEBUG ("rrdtool plugin: queue_thread exited.");
+ }
+
return (0);
} /* int rrd_shutdown */
return (0);
} /* int rrd_shutdown */
@@
-1067,12
+1099,7
@@
static int rrd_init (void)
if (stepsize < 0)
stepsize = 0;
if (heartbeat <= 0)
if (stepsize < 0)
stepsize = 0;
if (heartbeat <= 0)
- {
- if (stepsize > 0)
- heartbeat = 2 * stepsize;
- else
- heartbeat = 0;
- }
+ heartbeat = 2 * stepsize;
if ((heartbeat > 0) && (heartbeat < interval_g))
WARNING ("rrdtool plugin: Your `heartbeat' is "
if ((heartbeat > 0) && (heartbeat < interval_g))
WARNING ("rrdtool plugin: Your `heartbeat' is "
@@
-1086,10
+1113,10
@@
static int rrd_init (void)
/* Set the cache up */
pthread_mutex_lock (&cache_lock);
/* Set the cache up */
pthread_mutex_lock (&cache_lock);
- cache = avl_create ((int (*) (const void *, const void *)) strcmp);
+ cache =
c_
avl_create ((int (*) (const void *, const void *)) strcmp);
if (cache == NULL)
{
if (cache == NULL)
{
- ERROR ("rrdtool plugin: avl_create failed.");
+ ERROR ("rrdtool plugin:
c_
avl_create failed.");
return (-1);
}
return (-1);
}