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"
50 typedef struct rrd_cache_s rrd_cache_t;
57 typedef enum rrd_queue_dir_e rrd_queue_dir_t;
62 struct rrd_queue_s *next;
64 typedef struct rrd_queue_s rrd_queue_t;
69 static const char *config_keys[] =
82 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
84 /* If datadir is zero, the daemon's basedir is used. If stepsize or heartbeat
85 * is zero a default, depending on the `interval' member of the value list is
87 static char *datadir = NULL;
88 static double write_rate = 0.0;
89 static rrdcreate_config_t rrdcreate_config =
96 /* timespans = */ NULL,
97 /* timespans_num = */ 0,
99 /* consolidation_functions = */ NULL,
100 /* consolidation_functions_num = */ 0
103 /* XXX: If you need to lock both, cache_lock and queue_lock, at the same time,
104 * ALWAYS lock `cache_lock' first! */
105 static int cache_timeout = 0;
106 static int cache_flush_timeout = 0;
107 static int random_timeout = 1;
108 static int random_timeout_mod = 1;
109 static time_t cache_flush_last;
110 static c_avl_tree_t *cache = NULL;
111 static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
113 static rrd_queue_t *queue_head = NULL;
114 static rrd_queue_t *queue_tail = NULL;
115 static rrd_queue_t *flushq_head = NULL;
116 static rrd_queue_t *flushq_tail = NULL;
117 static pthread_t queue_thread;
118 static int queue_thread_running = 1;
119 static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER;
120 static pthread_cond_t queue_cond = PTHREAD_COND_INITIALIZER;
122 #if !HAVE_THREADSAFE_LIBRRD
123 static pthread_mutex_t librrd_lock = PTHREAD_MUTEX_INITIALIZER;
126 static int do_shutdown = 0;
128 #if HAVE_THREADSAFE_LIBRRD
129 static int srrd_update (char *filename, char *template,
130 int argc, const char **argv)
134 optind = 0; /* bug in librrd? */
137 status = rrd_update_r (filename, template, argc, (void *) argv);
141 WARNING ("rrdtool plugin: rrd_update_r (%s) failed: %s",
142 filename, rrd_get_error ());
146 } /* int srrd_update */
147 /* #endif HAVE_THREADSAFE_LIBRRD */
149 #else /* !HAVE_THREADSAFE_LIBRRD */
150 static int srrd_update (char *filename, char *template,
151 int argc, const char **argv)
158 assert (template == NULL);
161 new_argv = (char **) malloc ((new_argc + 1) * sizeof (char *));
162 if (new_argv == NULL)
164 ERROR ("rrdtool plugin: malloc failed.");
168 new_argv[0] = "update";
169 new_argv[1] = filename;
171 memcpy (new_argv + 2, argv, argc * sizeof (char *));
172 new_argv[new_argc] = NULL;
174 pthread_mutex_lock (&librrd_lock);
175 optind = 0; /* bug in librrd? */
178 status = rrd_update (new_argc, new_argv);
179 pthread_mutex_unlock (&librrd_lock);
183 WARNING ("rrdtool plugin: rrd_update_r failed: %s: %s",
184 argv[1], rrd_get_error ());
190 } /* int srrd_update */
191 #endif /* !HAVE_THREADSAFE_LIBRRD */
193 static int value_list_to_string (char *buffer, int buffer_len,
194 const data_set_t *ds, const value_list_t *vl)
200 memset (buffer, '\0', buffer_len);
202 status = ssnprintf (buffer, buffer_len, "%u", (unsigned int) vl->time);
203 if ((status < 1) || (status >= buffer_len))
207 for (i = 0; i < ds->ds_num; i++)
209 if ((ds->ds[i].type != DS_TYPE_COUNTER)
210 && (ds->ds[i].type != DS_TYPE_GAUGE)
211 && (ds->ds[i].type != DS_TYPE_DERIVE)
212 && (ds->ds[i].type != DS_TYPE_ABSOLUTE))
215 if (ds->ds[i].type == DS_TYPE_COUNTER)
216 status = ssnprintf (buffer + offset, buffer_len - offset,
217 ":%llu", vl->values[i].counter);
218 else if (ds->ds[i].type == DS_TYPE_GAUGE)
219 status = ssnprintf (buffer + offset, buffer_len - offset,
220 ":%lf", vl->values[i].gauge);
221 else if (ds->ds[i].type == DS_TYPE_DERIVE)
222 status = ssnprintf (buffer + offset, buffer_len - offset,
223 ":%"PRIi64, vl->values[i].derive);
224 else /*if (ds->ds[i].type == DS_TYPE_ABSOLUTE) */
225 status = ssnprintf (buffer + offset, buffer_len - offset,
226 ":%"PRIu64, vl->values[i].absolute);
228 if ((status < 1) || (status >= (buffer_len - offset)))
232 } /* for ds->ds_num */
235 } /* int value_list_to_string */
237 static int value_list_to_filename (char *buffer, int buffer_len,
238 const data_set_t __attribute__((unused)) *ds, const value_list_t *vl)
245 status = ssnprintf (buffer + offset, buffer_len - offset,
247 if ((status < 1) || (status >= buffer_len - offset))
252 status = ssnprintf (buffer + offset, buffer_len - offset,
254 if ((status < 1) || (status >= buffer_len - offset))
258 if (strlen (vl->plugin_instance) > 0)
259 status = ssnprintf (buffer + offset, buffer_len - offset,
260 "%s-%s/", vl->plugin, vl->plugin_instance);
262 status = ssnprintf (buffer + offset, buffer_len - offset,
264 if ((status < 1) || (status >= buffer_len - offset))
268 if (strlen (vl->type_instance) > 0)
269 status = ssnprintf (buffer + offset, buffer_len - offset,
270 "%s-%s.rrd", vl->type, vl->type_instance);
272 status = ssnprintf (buffer + offset, buffer_len - offset,
274 if ((status < 1) || (status >= buffer_len - offset))
279 } /* int value_list_to_filename */
281 static void *rrd_queue_thread (void __attribute__((unused)) *data)
283 struct timeval tv_next_update;
284 struct timeval tv_now;
286 gettimeofday (&tv_next_update, /* timezone = */ NULL);
290 rrd_queue_t *queue_entry;
291 rrd_cache_t *cache_entry;
300 pthread_mutex_lock (&queue_lock);
301 /* Wait for values to arrive */
304 struct timespec ts_wait;
306 while ((flushq_head == NULL) && (queue_head == NULL)
307 && (do_shutdown == 0))
308 pthread_cond_wait (&queue_cond, &queue_lock);
310 if ((flushq_head == NULL) && (queue_head == NULL))
313 /* Don't delay if there's something to flush */
314 if (flushq_head != NULL)
317 /* Don't delay if we're shutting down */
318 if (do_shutdown != 0)
321 /* Don't delay if no delay was configured. */
322 if (write_rate <= 0.0)
325 gettimeofday (&tv_now, /* timezone = */ NULL);
326 status = timeval_cmp (tv_next_update, tv_now, NULL);
327 /* We're good to go */
331 /* We're supposed to wait a bit with this update, so we'll
332 * wait for the next addition to the queue or to the end of
333 * the wait period - whichever comes first. */
334 ts_wait.tv_sec = tv_next_update.tv_sec;
335 ts_wait.tv_nsec = 1000 * tv_next_update.tv_usec;
337 status = pthread_cond_timedwait (&queue_cond, &queue_lock,
339 if (status == ETIMEDOUT)
343 /* XXX: If you need to lock both, cache_lock and queue_lock, at
344 * the same time, ALWAYS lock `cache_lock' first! */
346 /* We're in the shutdown phase */
347 if ((flushq_head == NULL) && (queue_head == NULL))
349 pthread_mutex_unlock (&queue_lock);
353 if (flushq_head != NULL)
355 /* Dequeue the first flush entry */
356 queue_entry = flushq_head;
357 if (flushq_head == flushq_tail)
358 flushq_head = flushq_tail = NULL;
360 flushq_head = flushq_head->next;
362 else /* if (queue_head != NULL) */
364 /* Dequeue the first regular entry */
365 queue_entry = queue_head;
366 if (queue_head == queue_tail)
367 queue_head = queue_tail = NULL;
369 queue_head = queue_head->next;
372 /* Unlock the queue again */
373 pthread_mutex_unlock (&queue_lock);
375 /* We now need the cache lock so the entry isn't updated while
376 * we make a copy of it's values */
377 pthread_mutex_lock (&cache_lock);
379 status = c_avl_get (cache, queue_entry->filename,
380 (void *) &cache_entry);
384 values = cache_entry->values;
385 values_num = cache_entry->values_num;
387 cache_entry->values = NULL;
388 cache_entry->values_num = 0;
389 cache_entry->flags = FLAG_NONE;
392 pthread_mutex_unlock (&cache_lock);
396 sfree (queue_entry->filename);
401 /* Update `tv_next_update' */
402 if (write_rate > 0.0)
404 gettimeofday (&tv_now, /* timezone = */ NULL);
405 tv_next_update.tv_sec = tv_now.tv_sec;
406 tv_next_update.tv_usec = tv_now.tv_usec
407 + ((suseconds_t) (1000000 * write_rate));
408 while (tv_next_update.tv_usec > 1000000)
410 tv_next_update.tv_sec++;
411 tv_next_update.tv_usec -= 1000000;
415 /* Write the values to the RRD-file */
416 srrd_update (queue_entry->filename, NULL,
417 values_num, (const char **)values);
418 DEBUG ("rrdtool plugin: queue thread: Wrote %i value%s to %s",
419 values_num, (values_num == 1) ? "" : "s",
420 queue_entry->filename);
422 for (i = 0; i < values_num; i++)
427 sfree (queue_entry->filename);
431 pthread_mutex_lock (&cache_lock);
432 c_avl_destroy (cache);
434 pthread_mutex_unlock (&cache_lock);
436 pthread_exit ((void *) 0);
438 } /* void *rrd_queue_thread */
440 static int rrd_queue_enqueue (const char *filename,
441 rrd_queue_t **head, rrd_queue_t **tail)
443 rrd_queue_t *queue_entry;
445 queue_entry = (rrd_queue_t *) malloc (sizeof (rrd_queue_t));
446 if (queue_entry == NULL)
449 queue_entry->filename = strdup (filename);
450 if (queue_entry->filename == NULL)
456 queue_entry->next = NULL;
458 pthread_mutex_lock (&queue_lock);
463 (*tail)->next = queue_entry;
466 pthread_cond_signal (&queue_cond);
467 pthread_mutex_unlock (&queue_lock);
470 } /* int rrd_queue_enqueue */
472 static int rrd_queue_dequeue (const char *filename,
473 rrd_queue_t **head, rrd_queue_t **tail)
478 pthread_mutex_lock (&queue_lock);
485 if (strcmp (this->filename, filename) == 0)
494 pthread_mutex_unlock (&queue_lock);
501 prev->next = this->next;
503 if (this->next == NULL)
506 pthread_mutex_unlock (&queue_lock);
508 sfree (this->filename);
512 } /* int rrd_queue_dequeue */
514 static void rrd_cache_flush (int timeout)
523 c_avl_iterator_t *iter;
526 DEBUG ("rrdtool plugin: Flushing cache, timeout = %i", timeout);
530 /* Build a list of entries to be flushed */
531 iter = c_avl_get_iterator (cache);
532 while (c_avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0)
534 if (rc->flags != FLAG_NONE)
536 else if ((now - rc->first_value) < timeout)
538 else if (rc->values_num > 0)
542 status = rrd_queue_enqueue (key, &queue_head, &queue_tail);
544 rc->flags = FLAG_QUEUED;
546 else /* ancient and no values -> waste of memory */
548 char **tmp = (char **) realloc ((void *) keys,
549 (keys_num + 1) * sizeof (char *));
553 ERROR ("rrdtool plugin: "
554 "realloc failed: %s",
555 sstrerror (errno, errbuf,
557 c_avl_iterator_destroy (iter);
562 keys[keys_num] = key;
565 } /* while (c_avl_iterator_next) */
566 c_avl_iterator_destroy (iter);
568 for (i = 0; i < keys_num; i++)
570 if (c_avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0)
572 DEBUG ("rrdtool plugin: c_avl_remove (%s) failed.", keys[i]);
576 assert (rc->values == NULL);
577 assert (rc->values_num == 0);
582 } /* for (i = 0..keys_num) */
586 cache_flush_last = now;
587 } /* void rrd_cache_flush */
589 static int rrd_cache_flush_identifier (int timeout, const char *identifier)
596 if (identifier == NULL)
598 rrd_cache_flush (timeout);
605 snprintf (key, sizeof (key), "%s.rrd",
608 snprintf (key, sizeof (key), "%s/%s.rrd",
609 datadir, identifier);
610 key[sizeof (key) - 1] = 0;
612 status = c_avl_get (cache, key, (void *) &rc);
615 INFO ("rrdtool plugin: rrd_cache_flush_identifier: "
616 "c_avl_get (%s) failed. Does that file really exist?",
621 if (rc->flags == FLAG_FLUSHQ)
625 else if (rc->flags == FLAG_QUEUED)
627 rrd_queue_dequeue (key, &queue_head, &queue_tail);
628 status = rrd_queue_enqueue (key, &flushq_head, &flushq_tail);
630 rc->flags = FLAG_FLUSHQ;
632 else if ((now - rc->first_value) < timeout)
636 else if (rc->values_num > 0)
638 status = rrd_queue_enqueue (key, &flushq_head, &flushq_tail);
640 rc->flags = FLAG_FLUSHQ;
644 } /* int rrd_cache_flush_identifier */
646 static int rrd_cache_insert (const char *filename,
647 const char *value, time_t value_time)
649 rrd_cache_t *rc = NULL;
653 pthread_mutex_lock (&cache_lock);
655 /* This shouldn't happen, but it did happen at least once, so we'll be
659 pthread_mutex_unlock (&cache_lock);
660 WARNING ("rrdtool plugin: cache == NULL.");
664 c_avl_get (cache, filename, (void *) &rc);
668 rc = (rrd_cache_t *) malloc (sizeof (rrd_cache_t));
675 rc->flags = FLAG_NONE;
679 if (rc->last_value >= value_time)
681 pthread_mutex_unlock (&cache_lock);
682 WARNING ("rrdtool plugin: (rc->last_value = %u) >= (value_time = %u)",
683 (unsigned int) rc->last_value,
684 (unsigned int) value_time);
688 values_new = (char **) realloc ((void *) rc->values,
689 (rc->values_num + 1) * sizeof (char *));
690 if (values_new == NULL)
693 void *cache_key = NULL;
695 sstrerror (errno, errbuf, sizeof (errbuf));
697 c_avl_remove (cache, filename, &cache_key, NULL);
698 pthread_mutex_unlock (&cache_lock);
700 ERROR ("rrdtool plugin: realloc failed: %s", errbuf);
707 rc->values = values_new;
709 rc->values[rc->values_num] = strdup (value);
710 if (rc->values[rc->values_num] != NULL)
713 if (rc->values_num == 1)
714 rc->first_value = value_time;
715 rc->last_value = value_time;
717 /* Insert if this is the first value */
720 void *cache_key = strdup (filename);
722 if (cache_key == NULL)
725 sstrerror (errno, errbuf, sizeof (errbuf));
727 pthread_mutex_unlock (&cache_lock);
729 ERROR ("rrdtool plugin: strdup failed: %s", errbuf);
731 sfree (rc->values[0]);
737 c_avl_insert (cache, cache_key, rc);
740 DEBUG ("rrdtool plugin: rrd_cache_insert: file = %s; "
741 "values_num = %i; age = %lu;",
742 filename, rc->values_num,
743 (unsigned long)(rc->last_value - rc->first_value));
746 if ((rc->last_value - rc->first_value) >= (cache_timeout + (random_timeout - (rand() % random_timeout_mod) ) ) )
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)
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);