2 * collectd - src/rrdtool.c
3 * Copyright (C) 2006-2008 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
25 #include "utils_avltree.h"
26 #include "utils_rrdcreate.h"
51 typedef struct rrd_cache_s rrd_cache_t;
58 typedef enum rrd_queue_dir_e rrd_queue_dir_t;
63 struct rrd_queue_s *next;
65 typedef struct rrd_queue_s rrd_queue_t;
70 static const char *config_keys[] =
83 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
85 /* If datadir is zero, the daemon's basedir is used. If stepsize or heartbeat
86 * is zero a default, depending on the `interval' member of the value list is
88 static char *datadir = NULL;
89 static double write_rate = 0.0;
90 static rrdcreate_config_t rrdcreate_config =
97 /* timespans = */ NULL,
98 /* timespans_num = */ 0,
100 /* consolidation_functions = */ NULL,
101 /* consolidation_functions_num = */ 0
104 /* XXX: If you need to lock both, cache_lock and queue_lock, at the same time,
105 * ALWAYS lock `cache_lock' first! */
106 static int cache_timeout = 0;
107 static int cache_flush_timeout = 0;
108 static int random_timeout = 1;
109 static int random_timeout_mod = 1;
110 static time_t cache_flush_last;
111 static c_avl_tree_t *cache = NULL;
112 static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
114 static rrd_queue_t *queue_head = NULL;
115 static rrd_queue_t *queue_tail = NULL;
116 static rrd_queue_t *flushq_head = NULL;
117 static rrd_queue_t *flushq_tail = NULL;
118 static pthread_t queue_thread;
119 static int queue_thread_running = 1;
120 static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER;
121 static pthread_cond_t queue_cond = PTHREAD_COND_INITIALIZER;
123 #if !HAVE_THREADSAFE_LIBRRD
124 static pthread_mutex_t librrd_lock = PTHREAD_MUTEX_INITIALIZER;
127 static int do_shutdown = 0;
129 #if HAVE_THREADSAFE_LIBRRD
130 static int srrd_update (char *filename, char *template,
131 int argc, const char **argv)
135 optind = 0; /* bug in librrd? */
138 status = rrd_update_r (filename, template, argc, (void *) argv);
142 WARNING ("rrdtool plugin: rrd_update_r (%s) failed: %s",
143 filename, rrd_get_error ());
147 } /* int srrd_update */
148 /* #endif HAVE_THREADSAFE_LIBRRD */
150 #else /* !HAVE_THREADSAFE_LIBRRD */
151 static int srrd_update (char *filename, char *template,
152 int argc, const char **argv)
159 assert (template == NULL);
162 new_argv = (char **) malloc ((new_argc + 1) * sizeof (char *));
163 if (new_argv == NULL)
165 ERROR ("rrdtool plugin: malloc failed.");
169 new_argv[0] = "update";
170 new_argv[1] = filename;
172 memcpy (new_argv + 2, argv, argc * sizeof (char *));
173 new_argv[new_argc] = NULL;
175 pthread_mutex_lock (&librrd_lock);
176 optind = 0; /* bug in librrd? */
179 status = rrd_update (new_argc, new_argv);
180 pthread_mutex_unlock (&librrd_lock);
184 WARNING ("rrdtool plugin: rrd_update_r failed: %s: %s",
185 argv[1], rrd_get_error ());
191 } /* int srrd_update */
192 #endif /* !HAVE_THREADSAFE_LIBRRD */
194 static int value_list_to_string (char *buffer, int buffer_len,
195 const data_set_t *ds, const value_list_t *vl)
201 memset (buffer, '\0', buffer_len);
203 status = ssnprintf (buffer, buffer_len, "%u", (unsigned int) vl->time);
204 if ((status < 1) || (status >= buffer_len))
208 for (i = 0; i < ds->ds_num; i++)
210 if ((ds->ds[i].type != DS_TYPE_COUNTER)
211 && (ds->ds[i].type != DS_TYPE_GAUGE)
212 && (ds->ds[i].type != DS_TYPE_DERIVE)
213 && (ds->ds[i].type != DS_TYPE_ABSOLUTE))
216 if (ds->ds[i].type == DS_TYPE_COUNTER)
217 status = ssnprintf (buffer + offset, buffer_len - offset,
218 ":%llu", vl->values[i].counter);
219 else if (ds->ds[i].type == DS_TYPE_GAUGE)
220 status = ssnprintf (buffer + offset, buffer_len - offset,
221 ":%lf", vl->values[i].gauge);
222 else if (ds->ds[i].type == DS_TYPE_DERIVE)
223 status = ssnprintf (buffer + offset, buffer_len - offset,
224 ":%"PRIi64, vl->values[i].derive);
225 else /*if (ds->ds[i].type == DS_TYPE_ABSOLUTE) */
226 status = ssnprintf (buffer + offset, buffer_len - offset,
227 ":%"PRIu64, vl->values[i].absolute);
229 if ((status < 1) || (status >= (buffer_len - offset)))
233 } /* for ds->ds_num */
236 } /* int value_list_to_string */
238 static int value_list_to_filename (char *buffer, int buffer_len,
239 const data_set_t __attribute__((unused)) *ds, const value_list_t *vl)
246 status = ssnprintf (buffer + offset, buffer_len - offset,
248 if ((status < 1) || (status >= buffer_len - offset))
253 status = ssnprintf (buffer + offset, buffer_len - offset,
255 if ((status < 1) || (status >= buffer_len - offset))
259 if (strlen (vl->plugin_instance) > 0)
260 status = ssnprintf (buffer + offset, buffer_len - offset,
261 "%s-%s/", vl->plugin, vl->plugin_instance);
263 status = ssnprintf (buffer + offset, buffer_len - offset,
265 if ((status < 1) || (status >= buffer_len - offset))
269 if (strlen (vl->type_instance) > 0)
270 status = ssnprintf (buffer + offset, buffer_len - offset,
271 "%s-%s.rrd", vl->type, vl->type_instance);
273 status = ssnprintf (buffer + offset, buffer_len - offset,
275 if ((status < 1) || (status >= buffer_len - offset))
280 } /* int value_list_to_filename */
282 static void *rrd_queue_thread (void __attribute__((unused)) *data)
284 struct timeval tv_next_update;
285 struct timeval tv_now;
287 gettimeofday (&tv_next_update, /* timezone = */ NULL);
291 rrd_queue_t *queue_entry;
292 rrd_cache_t *cache_entry;
301 pthread_mutex_lock (&queue_lock);
302 /* Wait for values to arrive */
305 struct timespec ts_wait;
307 while ((flushq_head == NULL) && (queue_head == NULL)
308 && (do_shutdown == 0))
309 pthread_cond_wait (&queue_cond, &queue_lock);
311 if ((flushq_head == NULL) && (queue_head == NULL))
314 /* Don't delay if there's something to flush */
315 if (flushq_head != NULL)
318 /* Don't delay if we're shutting down */
319 if (do_shutdown != 0)
322 /* Don't delay if no delay was configured. */
323 if (write_rate <= 0.0)
326 gettimeofday (&tv_now, /* timezone = */ NULL);
327 status = timeval_cmp (tv_next_update, tv_now, NULL);
328 /* We're good to go */
332 /* We're supposed to wait a bit with this update, so we'll
333 * wait for the next addition to the queue or to the end of
334 * the wait period - whichever comes first. */
335 ts_wait.tv_sec = tv_next_update.tv_sec;
336 ts_wait.tv_nsec = 1000 * tv_next_update.tv_usec;
338 status = pthread_cond_timedwait (&queue_cond, &queue_lock,
340 if (status == ETIMEDOUT)
344 /* XXX: If you need to lock both, cache_lock and queue_lock, at
345 * the same time, ALWAYS lock `cache_lock' first! */
347 /* We're in the shutdown phase */
348 if ((flushq_head == NULL) && (queue_head == NULL))
350 pthread_mutex_unlock (&queue_lock);
354 if (flushq_head != NULL)
356 /* Dequeue the first flush entry */
357 queue_entry = flushq_head;
358 if (flushq_head == flushq_tail)
359 flushq_head = flushq_tail = NULL;
361 flushq_head = flushq_head->next;
363 else /* if (queue_head != NULL) */
365 /* Dequeue the first regular entry */
366 queue_entry = queue_head;
367 if (queue_head == queue_tail)
368 queue_head = queue_tail = NULL;
370 queue_head = queue_head->next;
373 /* Unlock the queue again */
374 pthread_mutex_unlock (&queue_lock);
376 /* We now need the cache lock so the entry isn't updated while
377 * we make a copy of it's values */
378 pthread_mutex_lock (&cache_lock);
380 status = c_avl_get (cache, queue_entry->filename,
381 (void *) &cache_entry);
385 values = cache_entry->values;
386 values_num = cache_entry->values_num;
388 cache_entry->values = NULL;
389 cache_entry->values_num = 0;
390 cache_entry->flags = FLAG_NONE;
393 pthread_mutex_unlock (&cache_lock);
397 sfree (queue_entry->filename);
402 /* Update `tv_next_update' */
403 if (write_rate > 0.0)
405 gettimeofday (&tv_now, /* timezone = */ NULL);
406 tv_next_update.tv_sec = tv_now.tv_sec;
407 tv_next_update.tv_usec = tv_now.tv_usec
408 + ((suseconds_t) (1000000 * write_rate));
409 while (tv_next_update.tv_usec > 1000000)
411 tv_next_update.tv_sec++;
412 tv_next_update.tv_usec -= 1000000;
416 /* Write the values to the RRD-file */
417 srrd_update (queue_entry->filename, NULL,
418 values_num, (const char **)values);
419 DEBUG ("rrdtool plugin: queue thread: Wrote %i value%s to %s",
420 values_num, (values_num == 1) ? "" : "s",
421 queue_entry->filename);
423 for (i = 0; i < values_num; i++)
428 sfree (queue_entry->filename);
432 pthread_mutex_lock (&cache_lock);
433 c_avl_destroy (cache);
435 pthread_mutex_unlock (&cache_lock);
437 pthread_exit ((void *) 0);
439 } /* void *rrd_queue_thread */
441 static int rrd_queue_enqueue (const char *filename,
442 rrd_queue_t **head, rrd_queue_t **tail)
444 rrd_queue_t *queue_entry;
446 queue_entry = (rrd_queue_t *) malloc (sizeof (rrd_queue_t));
447 if (queue_entry == NULL)
450 queue_entry->filename = strdup (filename);
451 if (queue_entry->filename == NULL)
457 queue_entry->next = NULL;
459 pthread_mutex_lock (&queue_lock);
464 (*tail)->next = queue_entry;
467 pthread_cond_signal (&queue_cond);
468 pthread_mutex_unlock (&queue_lock);
471 } /* int rrd_queue_enqueue */
473 static int rrd_queue_dequeue (const char *filename,
474 rrd_queue_t **head, rrd_queue_t **tail)
479 pthread_mutex_lock (&queue_lock);
486 if (strcmp (this->filename, filename) == 0)
495 pthread_mutex_unlock (&queue_lock);
502 prev->next = this->next;
504 if (this->next == NULL)
507 pthread_mutex_unlock (&queue_lock);
509 sfree (this->filename);
513 } /* int rrd_queue_dequeue */
515 static void rrd_cache_flush (int timeout)
524 c_avl_iterator_t *iter;
527 DEBUG ("rrdtool plugin: Flushing cache, timeout = %i", timeout);
531 /* Build a list of entries to be flushed */
532 iter = c_avl_get_iterator (cache);
533 while (c_avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0)
535 if (rc->flags != FLAG_NONE)
537 else if ((now - rc->first_value) < timeout)
539 else if (rc->values_num > 0)
543 status = rrd_queue_enqueue (key, &queue_head, &queue_tail);
545 rc->flags = FLAG_QUEUED;
547 else /* ancient and no values -> waste of memory */
549 char **tmp = (char **) realloc ((void *) keys,
550 (keys_num + 1) * sizeof (char *));
554 ERROR ("rrdtool plugin: "
555 "realloc failed: %s",
556 sstrerror (errno, errbuf,
558 c_avl_iterator_destroy (iter);
563 keys[keys_num] = key;
566 } /* while (c_avl_iterator_next) */
567 c_avl_iterator_destroy (iter);
569 for (i = 0; i < keys_num; i++)
571 if (c_avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0)
573 DEBUG ("rrdtool plugin: c_avl_remove (%s) failed.", keys[i]);
577 assert (rc->values == NULL);
578 assert (rc->values_num == 0);
583 } /* for (i = 0..keys_num) */
587 cache_flush_last = now;
588 } /* void rrd_cache_flush */
590 static int rrd_cache_flush_identifier (int timeout, const char *identifier)
597 if (identifier == NULL)
599 rrd_cache_flush (timeout);
606 snprintf (key, sizeof (key), "%s.rrd",
609 snprintf (key, sizeof (key), "%s/%s.rrd",
610 datadir, identifier);
611 key[sizeof (key) - 1] = 0;
613 status = c_avl_get (cache, key, (void *) &rc);
616 INFO ("rrdtool plugin: rrd_cache_flush_identifier: "
617 "c_avl_get (%s) failed. Does that file really exist?",
622 if (rc->flags == FLAG_FLUSHQ)
626 else if (rc->flags == FLAG_QUEUED)
628 rrd_queue_dequeue (key, &queue_head, &queue_tail);
629 status = rrd_queue_enqueue (key, &flushq_head, &flushq_tail);
631 rc->flags = FLAG_FLUSHQ;
633 else if ((now - rc->first_value) < timeout)
637 else if (rc->values_num > 0)
639 status = rrd_queue_enqueue (key, &flushq_head, &flushq_tail);
641 rc->flags = FLAG_FLUSHQ;
645 } /* int rrd_cache_flush_identifier */
647 static int rrd_cache_insert (const char *filename,
648 const char *value, time_t value_time)
650 rrd_cache_t *rc = NULL;
654 pthread_mutex_lock (&cache_lock);
656 /* This shouldn't happen, but it did happen at least once, so we'll be
660 pthread_mutex_unlock (&cache_lock);
661 WARNING ("rrdtool plugin: cache == NULL.");
665 c_avl_get (cache, filename, (void *) &rc);
669 rc = (rrd_cache_t *) malloc (sizeof (rrd_cache_t));
676 rc->flags = FLAG_NONE;
680 if (rc->last_value >= value_time)
682 pthread_mutex_unlock (&cache_lock);
683 WARNING ("rrdtool plugin: (rc->last_value = %u) >= (value_time = %u)",
684 (unsigned int) rc->last_value,
685 (unsigned int) value_time);
689 values_new = (char **) realloc ((void *) rc->values,
690 (rc->values_num + 1) * sizeof (char *));
691 if (values_new == NULL)
694 void *cache_key = NULL;
696 sstrerror (errno, errbuf, sizeof (errbuf));
698 c_avl_remove (cache, filename, &cache_key, NULL);
699 pthread_mutex_unlock (&cache_lock);
701 ERROR ("rrdtool plugin: realloc failed: %s", errbuf);
708 rc->values = values_new;
710 rc->values[rc->values_num] = strdup (value);
711 if (rc->values[rc->values_num] != NULL)
714 if (rc->values_num == 1)
715 rc->first_value = value_time;
716 rc->last_value = value_time;
718 /* Insert if this is the first value */
721 void *cache_key = strdup (filename);
723 if (cache_key == NULL)
726 sstrerror (errno, errbuf, sizeof (errbuf));
728 pthread_mutex_unlock (&cache_lock);
730 ERROR ("rrdtool plugin: strdup failed: %s", errbuf);
732 sfree (rc->values[0]);
738 c_avl_insert (cache, cache_key, rc);
741 DEBUG ("rrdtool plugin: rrd_cache_insert: file = %s; "
742 "values_num = %i; age = %lu;",
743 filename, rc->values_num,
744 (unsigned long)(rc->last_value - rc->first_value));
746 if ((rc->last_value - rc->first_value + rc->random_variation) >= cache_timeout)
748 /* XXX: If you need to lock both, cache_lock and queue_lock, at
749 * the same time, ALWAYS lock `cache_lock' first! */
750 if (rc->flags == FLAG_NONE)
753 rc->random_variation = (random_timeout - (rand() % random_timeout_mod));
754 status = rrd_queue_enqueue (filename, &queue_head, &queue_tail);
756 rc->flags = FLAG_QUEUED;
760 DEBUG ("rrdtool plugin: `%s' is already queued.", filename);
764 if ((cache_timeout > 0) &&
765 ((time (NULL) - cache_flush_last) > cache_flush_timeout))
766 rrd_cache_flush (cache_flush_timeout);
768 pthread_mutex_unlock (&cache_lock);
771 } /* int rrd_cache_insert */
773 static int rrd_compare_numeric (const void *a_ptr, const void *b_ptr)
775 int a = *((int *) a_ptr);
776 int b = *((int *) b_ptr);
784 } /* int rrd_compare_numeric */
786 static int rrd_write (const data_set_t *ds, const value_list_t *vl,
787 user_data_t __attribute__((unused)) *user_data)
794 if (0 != strcmp (ds->type, vl->type)) {
795 ERROR ("rrdtool plugin: DS type does not match value list type");
799 if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0)
802 if (value_list_to_string (values, sizeof (values), ds, vl) != 0)
805 if (stat (filename, &statbuf) == -1)
809 status = cu_rrd_create_file (filename,
810 ds, vl, &rrdcreate_config);
817 ERROR ("stat(%s) failed: %s", filename,
818 sstrerror (errno, errbuf,
823 else if (!S_ISREG (statbuf.st_mode))
825 ERROR ("stat(%s): Not a regular file!",
830 status = rrd_cache_insert (filename, values, vl->time);
833 } /* int rrd_write */
835 static int rrd_flush (int timeout, const char *identifier,
836 user_data_t __attribute__((unused)) *user_data)
838 pthread_mutex_lock (&cache_lock);
841 pthread_mutex_unlock (&cache_lock);
845 rrd_cache_flush_identifier (timeout, identifier);
847 pthread_mutex_unlock (&cache_lock);
849 } /* int rrd_flush */
851 static int rrd_config (const char *key, const char *value)
853 if (strcasecmp ("CacheTimeout", key) == 0)
855 int tmp = atoi (value);
858 fprintf (stderr, "rrdtool: `CacheTimeout' must "
859 "be greater than 0.\n");
860 ERROR ("rrdtool: `CacheTimeout' must "
861 "be greater than 0.\n");
866 else if (strcasecmp ("CacheFlush", key) == 0)
868 int tmp = atoi (value);
871 fprintf (stderr, "rrdtool: `CacheFlush' must "
872 "be greater than 0.\n");
873 ERROR ("rrdtool: `CacheFlush' must "
874 "be greater than 0.\n");
877 cache_flush_timeout = tmp;
879 else if (strcasecmp ("DataDir", key) == 0)
883 datadir = strdup (value);
886 int len = strlen (datadir);
887 while ((len > 0) && (datadir[len - 1] == '/'))
899 else if (strcasecmp ("StepSize", key) == 0)
901 int temp = atoi (value);
903 rrdcreate_config.stepsize = temp;
905 else if (strcasecmp ("HeartBeat", key) == 0)
907 int temp = atoi (value);
909 rrdcreate_config.heartbeat = temp;
911 else if (strcasecmp ("RRARows", key) == 0)
913 int tmp = atoi (value);
916 fprintf (stderr, "rrdtool: `RRARows' must "
917 "be greater than 0.\n");
918 ERROR ("rrdtool: `RRARows' must "
919 "be greater than 0.\n");
922 rrdcreate_config.rrarows = tmp;
924 else if (strcasecmp ("RRATimespan", key) == 0)
926 char *saveptr = NULL;
932 value_copy = strdup (value);
933 if (value_copy == NULL)
937 while ((ptr = strtok_r (dummy, ", \t", &saveptr)) != NULL)
941 tmp_alloc = realloc (rrdcreate_config.timespans,
942 sizeof (int) * (rrdcreate_config.timespans_num + 1));
943 if (tmp_alloc == NULL)
945 fprintf (stderr, "rrdtool: realloc failed.\n");
946 ERROR ("rrdtool: realloc failed.\n");
950 rrdcreate_config.timespans = tmp_alloc;
951 rrdcreate_config.timespans[rrdcreate_config.timespans_num] = atoi (ptr);
952 if (rrdcreate_config.timespans[rrdcreate_config.timespans_num] != 0)
953 rrdcreate_config.timespans_num++;
954 } /* while (strtok_r) */
956 qsort (/* base = */ rrdcreate_config.timespans,
957 /* nmemb = */ rrdcreate_config.timespans_num,
958 /* size = */ sizeof (rrdcreate_config.timespans[0]),
959 /* compar = */ rrd_compare_numeric);
963 else if (strcasecmp ("XFF", key) == 0)
965 double tmp = atof (value);
966 if ((tmp < 0.0) || (tmp >= 1.0))
968 fprintf (stderr, "rrdtool: `XFF' must "
969 "be in the range 0 to 1 (exclusive).");
970 ERROR ("rrdtool: `XFF' must "
971 "be in the range 0 to 1 (exclusive).");
974 rrdcreate_config.xff = tmp;
976 else if (strcasecmp ("WritesPerSecond", key) == 0)
978 double wps = atof (value);
982 fprintf (stderr, "rrdtool: `WritesPerSecond' must be "
983 "greater than or equal to zero.");
992 write_rate = 1.0 / wps;
995 else if (strcasecmp ("RandomTimeout", key) == 0)
997 random_timeout = atoi (value);
998 if( random_timeout < 0 )
1000 fprintf (stderr, "rrdtool: `RandomTimeout' must "
1001 "be greater than or equal to zero.\n");
1002 ERROR ("rrdtool: `RandomTimeout' must "
1003 "be greater then or equal to zero.\n");
1005 else if (random_timeout==0) {random_timeout=1;}
1006 else {random_timeout_mod = random_timeout * 2;}
1013 } /* int rrd_config */
1015 static int rrd_shutdown (void)
1017 pthread_mutex_lock (&cache_lock);
1018 rrd_cache_flush (-1);
1019 pthread_mutex_unlock (&cache_lock);
1021 pthread_mutex_lock (&queue_lock);
1023 pthread_cond_signal (&queue_cond);
1024 pthread_mutex_unlock (&queue_lock);
1026 if ((queue_thread_running != 0)
1027 && ((queue_head != NULL) || (flushq_head != NULL)))
1029 INFO ("rrdtool plugin: Shutting down the queue thread. "
1030 "This may take a while.");
1032 else if (queue_thread_running != 0)
1034 INFO ("rrdtool plugin: Shutting down the queue thread.");
1037 /* Wait for all the values to be written to disk before returning. */
1038 if (queue_thread_running != 0)
1040 pthread_join (queue_thread, NULL);
1041 memset (&queue_thread, 0, sizeof (queue_thread));
1042 queue_thread_running = 0;
1043 DEBUG ("rrdtool plugin: queue_thread exited.");
1046 /* TODO: Maybe it'd be a good idea to free the cache here.. */
1049 } /* int rrd_shutdown */
1051 static int rrd_init (void)
1053 static int init_once = 0;
1060 if (rrdcreate_config.stepsize < 0)
1061 rrdcreate_config.stepsize = 0;
1062 if (rrdcreate_config.heartbeat <= 0)
1063 rrdcreate_config.heartbeat = 2 * rrdcreate_config.stepsize;
1065 if ((rrdcreate_config.heartbeat > 0)
1066 && (rrdcreate_config.heartbeat < interval_g))
1067 WARNING ("rrdtool plugin: Your `heartbeat' is "
1068 "smaller than your `interval'. This will "
1069 "likely cause problems.");
1070 else if ((rrdcreate_config.stepsize > 0)
1071 && (rrdcreate_config.stepsize < interval_g))
1072 WARNING ("rrdtool plugin: Your `stepsize' is "
1073 "smaller than your `interval'. This will "
1074 "create needlessly big RRD-files.");
1076 /* Set the cache up */
1077 pthread_mutex_lock (&cache_lock);
1079 cache = c_avl_create ((int (*) (const void *, const void *)) strcmp);
1082 ERROR ("rrdtool plugin: c_avl_create failed.");
1086 cache_flush_last = time (NULL);
1087 if (cache_timeout < 2)
1090 cache_flush_timeout = 0;
1092 else if (cache_flush_timeout < cache_timeout)
1093 cache_flush_timeout = 10 * cache_timeout;
1095 pthread_mutex_unlock (&cache_lock);
1097 status = pthread_create (&queue_thread, /* attr = */ NULL,
1098 rrd_queue_thread, /* args = */ NULL);
1101 ERROR ("rrdtool plugin: Cannot create queue-thread.");
1104 queue_thread_running = 1;
1106 DEBUG ("rrdtool plugin: rrd_init: datadir = %s; stepsize = %i;"
1107 " heartbeat = %i; rrarows = %i; xff = %lf;",
1108 (datadir == NULL) ? "(null)" : datadir,
1109 rrdcreate_config.stepsize,
1110 rrdcreate_config.heartbeat,
1111 rrdcreate_config.rrarows,
1112 rrdcreate_config.xff);
1115 } /* int rrd_init */
1117 void module_register (void)
1119 plugin_register_config ("rrdtool", rrd_config,
1120 config_keys, config_keys_num);
1121 plugin_register_init ("rrdtool", rrd_init);
1122 plugin_register_write ("rrdtool", rrd_write, /* user_data = */ NULL);
1123 plugin_register_flush ("rrdtool", rrd_flush, /* user_data = */ NULL);
1124 plugin_register_shutdown ("rrdtool", rrd_shutdown);