Merge remote-tracking branch 'github/master'
[collectd.git] / src / plugin.c
index 0b91561..cd99204 100644 (file)
@@ -104,6 +104,9 @@ static c_avl_tree_t *data_sets;
 
 static char *plugindir = NULL;
 
+#ifndef DEFAULT_MAX_READ_INTERVAL
+# define DEFAULT_MAX_READ_INTERVAL TIME_T_TO_CDTIME_T (86400)
+#endif
 static c_heap_t       *read_heap = NULL;
 static llist_t        *read_list;
 static int             read_loop = 1;
@@ -111,6 +114,7 @@ static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t  read_cond = PTHREAD_COND_INITIALIZER;
 static pthread_t      *read_threads = NULL;
 static int             read_threads_num = 0;
+static cdtime_t        max_read_interval = DEFAULT_MAX_READ_INTERVAL;
 
 static write_queue_t  *write_queue_head;
 static write_queue_t  *write_queue_tail;
@@ -155,7 +159,7 @@ static void plugin_update_internal_statistics (void) { /* {{{ */
        vl.values_len = 2;
        vl.time = 0;
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
-       sstrncpy (vl.plugin, "internal", sizeof (vl.plugin));
+       sstrncpy (vl.plugin, "collectd", sizeof (vl.plugin));
 
        vl.type_instance[0] = 0;
        vl.values_len = 1;
@@ -532,8 +536,8 @@ static void *plugin_read_thread (void __attribute__((unused)) *args)
                if (status != 0)
                {
                        rf->rf_effective_interval *= 2;
-                       if (rf->rf_effective_interval > TIME_T_TO_CDTIME_T (86400))
-                               rf->rf_effective_interval = TIME_T_TO_CDTIME_T (86400);
+                       if (rf->rf_effective_interval > max_read_interval)
+                               rf->rf_effective_interval = max_read_interval;
 
                        NOTICE ("read-function of plugin `%s' failed. "
                                        "Will suspend it for %.3f seconds.",
@@ -1517,7 +1521,7 @@ void plugin_init_all (void)
        /* Init the value cache */
        uc_init ();
 
-       if (IS_TRUE (global_option_get ("InternalStatistics")))
+       if (IS_TRUE (global_option_get ("CollectInternalStats")))
                record_statistics = 1;
 
        chain_name = global_option_get ("PreCacheChain");
@@ -1593,11 +1597,15 @@ void plugin_init_all (void)
                le = le->next;
        }
 
+       max_read_interval = global_option_get_time ("MaxReadInterval",
+                       DEFAULT_MAX_READ_INTERVAL);
+
        /* Start read-threads */
        if (read_heap != NULL)
        {
                const char *rt;
                int num;
+
                rt = global_option_get ("ReadThreads");
                num = atoi (rt);
                if (num != -1)
@@ -2135,9 +2143,11 @@ int plugin_dispatch_values (value_list_t const *vl)
        static pthread_mutex_t statistics_lock = PTHREAD_MUTEX_INITIALIZER;
 
        if (check_drop_value ()) {
-               pthread_mutex_lock(&statistics_lock);
-               stats_values_dropped++;
-               pthread_mutex_unlock(&statistics_lock);
+               if(record_statistics) {
+                       pthread_mutex_lock(&statistics_lock);
+                       stats_values_dropped++;
+                       pthread_mutex_unlock(&statistics_lock);
+               }
                return (0);
        }