Code

core: Changed internal API to allow for per-plugin intervals.
[collectd.git] / src / python.c
index ee673883e49b120512d855aef6e4266a793967d6..3e678f3a7cfc002db128e1140384c119852d3f08 100644 (file)
@@ -315,6 +315,10 @@ void cpy_log_exception(const char *context) {
        PyErr_Clear();
 }
 
+cdtime_t cpy_get_plugin_interval(void) {
+       return plugin_interval;
+}
+
 static int cpy_read_callback(user_data_t *data) {
        cpy_callback_t *c = data->data;
        PyObject *ret;
@@ -627,8 +631,14 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwd
        user_data = malloc(sizeof(*user_data));
        user_data->free_func = cpy_destroy_user_data;
        user_data->data = c;
-       ts.tv_sec = interval;
-       ts.tv_nsec = (interval - ts.tv_sec) * 1000000000;
+       if (interval > 0.0) {
+               ts.tv_sec = interval;
+               ts.tv_nsec = (interval - ts.tv_sec) * 1000000000;
+       }
+       else {
+               CDTIME_T_TO_TIMESPEC (plugin_interval, &ts);
+       }
+
        plugin_register_complex_read(/* group = */ NULL, buf,
                        cpy_read_callback, &ts, user_data);
        return cpy_string_to_unicode_or_bytes(buf);
@@ -1142,7 +1152,8 @@ static int cpy_config(oconfig_item_t *ci) {
        return 0;
 }
 
-void module_register(void) {
+void module_register(plugin_loaddata_t *data) {
+       PLUGIN_INIT_INTERVAL (data);
        plugin_register_complex_config("python", cpy_config);
        plugin_register_init("python", cpy_init);
        plugin_register_shutdown("python", cpy_shutdown);