From: Florian Forster Date: Thu, 29 Mar 2007 17:21:14 +0000 (+0200) Subject: Implemented `LoadDS' which tells plugins to only register their DataSources. X-Git-Tag: collectd-4.0.0~117^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2f0dfdda8bc499fdb161c6a5850ec176e75bd4fa;p=collectd.git Implemented `LoadDS' which tells plugins to only register their DataSources. --- diff --git a/src/apache.c b/src/apache.c index 887977e4..4184247c 100644 --- a/src/apache.c +++ b/src/apache.c @@ -354,17 +354,23 @@ static int apache_read (void) } /* int apache_read */ #endif /* APACHE_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&apache_bytes_ds); - plugin_register_data_set (&apache_requests_ds); - plugin_register_data_set (&apache_scoreboard_ds); - plugin_register_data_set (&apache_connections_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&apache_bytes_ds); + plugin_register_data_set (&apache_requests_ds); + plugin_register_data_set (&apache_scoreboard_ds); + plugin_register_data_set (&apache_connections_ds); + } #if APACHE_HAVE_READ - plugin_register_config ("apache", config, - config_keys, config_keys_num); - plugin_register_init ("apache", init); - plugin_register_read ("apache", apache_read); + if (load & MR_READ) + { + plugin_register_config ("apache", config, + config_keys, config_keys_num); + plugin_register_init ("apache", init); + plugin_register_read ("apache", apache_read); + } #endif -} +} /* void module_register */ diff --git a/src/apcups.c b/src/apcups.c index fc94e7d7..2539c32f 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -488,16 +488,22 @@ static int apcups_read (void) return (0); } /* apcups_read */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds_voltage); - plugin_register_data_set (&ds_percent); - plugin_register_data_set (&ds_timeleft); - plugin_register_data_set (&ds_temperature); - plugin_register_data_set (&ds_frequency); - - plugin_register_config ("apcups", apcups_config, config_keys, config_keys_num); + if (load & MR_DATASETS) + { + plugin_register_data_set (&ds_voltage); + plugin_register_data_set (&ds_percent); + plugin_register_data_set (&ds_timeleft); + plugin_register_data_set (&ds_temperature); + plugin_register_data_set (&ds_frequency); + } - plugin_register_read ("apcups", apcups_read); - plugin_register_shutdown ("apcups", apcups_shutdown); -} + if (load & MR_READ) + { + plugin_register_config ("apcups", apcups_config, config_keys, + config_keys_num); + plugin_register_read ("apcups", apcups_read); + plugin_register_shutdown ("apcups", apcups_shutdown); + } +} /* void module_register */ diff --git a/src/apple_sensors.c b/src/apple_sensors.c index f994b319..6b3cfc5e 100644 --- a/src/apple_sensors.c +++ b/src/apple_sensors.c @@ -262,13 +262,19 @@ static int as_read (void) } /* int as_read */ #endif /* IOKIT_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&fanspeed_ds); - plugin_register_data_set (&temperature_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&fanspeed_ds); + plugin_register_data_set (&temperature_ds); + } #if IOKIT_HAVE_READ - plugin_register_init ("apple_sensors", as_init); - plugin_register_read ("apple_sensors", as_read); + if (load & MR_READ) + { + plugin_register_init ("apple_sensors", as_init); + plugin_register_read ("apple_sensors", as_read); + } #endif /* IOKIT_HAVE_READ */ -} +} /* void module_register */ diff --git a/src/battery.c b/src/battery.c index 53442ce6..bdf46194 100644 --- a/src/battery.c +++ b/src/battery.c @@ -555,14 +555,20 @@ static int battery_read (void) } #endif /* BATTERY_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&charge_ds); - plugin_register_data_set (¤t_ds); - plugin_register_data_set (&voltage_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&charge_ds); + plugin_register_data_set (¤t_ds); + plugin_register_data_set (&voltage_ds); + } #if BATTERY_HAVE_READ - plugin_register_init ("battery", battery_init); - plugin_register_read ("battery", battery_read); + if (load & MR_READ) + { + plugin_register_init ("battery", battery_init); + plugin_register_read ("battery", battery_read); + } #endif /* BATTERY_HAVE_READ */ -} +} /* void module_register */ diff --git a/src/configfile.c b/src/configfile.c index 1d3b8954..311ebb38 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -60,6 +60,7 @@ typedef struct cf_global_option_s * Prototypes of callback functions */ static int dispatch_value_plugindir (const oconfig_item_t *ci); +static int dispatch_value_loadds (const oconfig_item_t *ci); static int dispatch_value_loadplugin (const oconfig_item_t *ci); /* @@ -70,7 +71,8 @@ static cf_callback_t *first_callback = NULL; static cf_value_map_t cf_value_map[] = { {"PluginDir", dispatch_value_plugindir}, - {"LoadPlugin", dispatch_value_loadplugin} + {"LoadPlugin", dispatch_value_loadplugin}, + {"LoadDS", dispatch_value_loadds} }; static int cf_value_map_num = STATIC_ARRAY_LEN (cf_value_map); @@ -182,6 +184,18 @@ static int dispatch_value_plugindir (const oconfig_item_t *ci) return (0); } +static int dispatch_value_loadds (const oconfig_item_t *ci) +{ + assert (strcasecmp (ci->key, "LoadDS") == 0); + + if (ci->values_num != 1) + return (-1); + if (ci->values[0].type != OCONFIG_TYPE_STRING) + return (-1); + + return (plugin_load (ci->values[0].value.string, MR_DATASETS)); +} /* int dispatch_value_loadds */ + static int dispatch_value_loadplugin (const oconfig_item_t *ci) { assert (strcasecmp (ci->key, "LoadPlugin") == 0); @@ -191,7 +205,7 @@ static int dispatch_value_loadplugin (const oconfig_item_t *ci) if (ci->values[0].type != OCONFIG_TYPE_STRING) return (-1); - return (plugin_load (ci->values[0].value.string)); + return (plugin_load (ci->values[0].value.string, MR_EVERYTHING)); } /* int dispatch_value_loadplugin */ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) diff --git a/src/cpu.c b/src/cpu.c index 1dcbdcd2..1dc78657 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -402,12 +402,16 @@ static int cpu_read (void) } #endif /* CPU_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds); + if (load & MR_DATASETS) + plugin_register_data_set (&ds); #if CPU_HAVE_READ - plugin_register_init ("cpu", init); - plugin_register_read ("cpu", cpu_read); + if (load & MR_READ) + { + plugin_register_init ("cpu", init); + plugin_register_read ("cpu", cpu_read); + } #endif /* CPU_HAVE_READ */ -} +} /* void module_register */ diff --git a/src/cpufreq.c b/src/cpufreq.c index 5ceaacc8..e4caf5ff 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -155,12 +155,16 @@ static int cpufreq_read (void) #endif /* CPUFREQ_HAVE_READ */ #undef BUFSIZE -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&data_set); + if (load & MR_DATASETS) + plugin_register_data_set (&data_set); #if CPUFREQ_HAVE_READ - plugin_register_init ("cpufreq", cpufreq_init); - plugin_register_read ("cpufreq", cpufreq_read); + if (load & MR_READ) + { + plugin_register_init ("cpufreq", cpufreq_init); + plugin_register_read ("cpufreq", cpufreq_read); + } #endif /* CPUFREQ_HAVE_READ */ } diff --git a/src/csv.c b/src/csv.c index 4379fe5f..e67a9ca9 100644 --- a/src/csv.c +++ b/src/csv.c @@ -265,9 +265,12 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl) return (0); } /* int csv_write */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_config ("csv", csv_config, - config_keys, config_keys_num); - plugin_register_write ("csv", csv_write); -} + if (load & MR_WRITE) + { + plugin_register_config ("csv", csv_config, + config_keys, config_keys_num); + plugin_register_write ("csv", csv_write); + } +} /* void module_register */ diff --git a/src/df.c b/src/df.c index 48d58c3f..afd3e0b1 100644 --- a/src/df.c +++ b/src/df.c @@ -223,13 +223,18 @@ static int df_read (void) } /* int df_read */ #endif /* DF_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds); + if (load & MR_DATASETS) + plugin_register_data_set (&ds); #if DF_HAVE_READ - plugin_register_config ("df", df_config, config_keys, config_keys_num); - plugin_register_init ("df", df_init); - plugin_register_read ("df", df_read); + if (load & MR_READ) + { + plugin_register_config ("df", df_config, + config_keys, config_keys_num); + plugin_register_init ("df", df_init); + plugin_register_read ("df", df_read); + } #endif } /* void module_register */ diff --git a/src/disk.c b/src/disk.c index 2a5b713b..c9d2f364 100644 --- a/src/disk.c +++ b/src/disk.c @@ -589,15 +589,21 @@ static int disk_read (void) } /* int disk_read */ #endif /* DISK_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&octets_ds); - plugin_register_data_set (&operations_ds); - plugin_register_data_set (&merged_ds); - plugin_register_data_set (&time_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&octets_ds); + plugin_register_data_set (&operations_ds); + plugin_register_data_set (&merged_ds); + plugin_register_data_set (&time_ds); + } #if DISK_HAVE_READ - plugin_register_init ("disk", disk_init); - plugin_register_read ("disk", disk_read); + if (load & MR_READ) + { + plugin_register_init ("disk", disk_init); + plugin_register_read ("disk", disk_read); + } #endif /* DISK_HAVE_READ */ -} +} /* void module_register */ diff --git a/src/dns.c b/src/dns.c index 473003a7..c9beb166 100644 --- a/src/dns.c +++ b/src/dns.c @@ -433,16 +433,22 @@ static int dns_read (void) } /* int dns_read */ #endif -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&octets_ds); - plugin_register_data_set (&qtype_ds); - plugin_register_data_set (&opcode_ds); - plugin_register_data_set (&rcode_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&octets_ds); + plugin_register_data_set (&qtype_ds); + plugin_register_data_set (&opcode_ds); + plugin_register_data_set (&rcode_ds); + } #if DNS_HAVE_READ - plugin_register_config ("dns", dns_config, config_keys, config_keys_num); - plugin_register_init ("dns", dns_init); - plugin_register_read ("dns", dns_read); + if (load & MR_READ) + { + plugin_register_config ("dns", dns_config, config_keys, config_keys_num); + plugin_register_init ("dns", dns_init); + plugin_register_read ("dns", dns_read); + } #endif } /* void module_register */ diff --git a/src/email.c b/src/email.c index c8c3982b..ed588193 100644 --- a/src/email.c +++ b/src/email.c @@ -869,18 +869,23 @@ static int email_read (void) return (0); } /* int email_read */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&email_count_ds); - plugin_register_data_set (&email_size_ds); - plugin_register_data_set (&spam_check_ds); - plugin_register_data_set (&spam_score_ds); - - plugin_register_config ("email", email_config, config_keys, config_keys_num); - plugin_register_init ("email", email_init); - plugin_register_read ("email", email_read); + if (load & MR_DATASETS) + { + plugin_register_data_set (&email_count_ds); + plugin_register_data_set (&email_size_ds); + plugin_register_data_set (&spam_check_ds); + plugin_register_data_set (&spam_score_ds); + } + + if (load & MR_READ) + { + plugin_register_config ("email", email_config, config_keys, config_keys_num); + plugin_register_init ("email", email_init); + plugin_register_read ("email", email_read); + } plugin_register_shutdown ("email", email_shutdown); -} /* void module_register (void) */ +} /* void module_register */ /* vim: set sw=4 ts=4 tw=78 noexpandtab : */ - diff --git a/src/entropy.c b/src/entropy.c index 68c57daf..fd48c742 100644 --- a/src/entropy.c +++ b/src/entropy.c @@ -88,10 +88,13 @@ static int entropy_read (void) } #endif /* ENTROPY_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds); + if (load & MR_DATASETS) + plugin_register_data_set (&ds); + #if ENTROPY_HAVE_READ - plugin_register_read ("entropy", entropy_read); + if (load & MR_READ) + plugin_register_read ("entropy", entropy_read); #endif -} +} /* void module_register */ diff --git a/src/exec.c b/src/exec.c index c7c72029..82c7efa6 100644 --- a/src/exec.c +++ b/src/exec.c @@ -356,12 +356,19 @@ static int exec_read (void) return (0); } /* int exec_read */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds_counter); - plugin_register_data_set (&ds_gauge); - plugin_register_config ("exec", exec_config, config_keys, config_keys_num); - plugin_register_read ("exec", exec_read); + if (load & MR_DATASETS) + { + plugin_register_data_set (&ds_counter); + plugin_register_data_set (&ds_gauge); + } + + if (load & MR_READ) + { + plugin_register_config ("exec", exec_config, config_keys, config_keys_num); + plugin_register_read ("exec", exec_read); + } } /* void module_register */ /* diff --git a/src/hddtemp.c b/src/hddtemp.c index a7758613..505d10f5 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -514,14 +514,18 @@ static int hddtemp_read (void) /* module_register Register collectd plugin. */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&temperature_ds); + if (load & MR_DATASETS) + plugin_register_data_set (&temperature_ds); #if HDDTEMP_HAVE_READ - plugin_register_config ("hddtemp", hddtemp_config, - config_keys, config_keys_num); - plugin_register_init ("hddtemp", hddtemp_init); - plugin_register_read ("hddtemp", hddtemp_read); + if (load & MR_READ) + { + plugin_register_config ("hddtemp", hddtemp_config, + config_keys, config_keys_num); + plugin_register_init ("hddtemp", hddtemp_init); + plugin_register_read ("hddtemp", hddtemp_read); + } #endif /* HDDTEMP_HAVE_READ */ } diff --git a/src/interface.c b/src/interface.c index 308c48ff..960cc622 100644 --- a/src/interface.c +++ b/src/interface.c @@ -389,20 +389,25 @@ static int interface_read (void) } /* int interface_read */ #endif /* INTERFACE_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&octets_ds); - plugin_register_data_set (&packets_ds); - plugin_register_data_set (&errors_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&octets_ds); + plugin_register_data_set (&packets_ds); + plugin_register_data_set (&errors_ds); + } plugin_register_config ("interface", interface_config, config_keys, config_keys_num); + if (load & MR_READ) + { #if HAVE_LIBKSTAT - plugin_register_init ("interface", interface_init); + plugin_register_init ("interface", interface_init); #endif - #if INTERFACE_HAVE_READ - plugin_register_read ("interface", interface_read); + plugin_register_read ("interface", interface_read); #endif -} + } +} /* void module_register */ diff --git a/src/iptables.c b/src/iptables.c index 47f0e550..1df35fa0 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -358,18 +358,24 @@ static int iptables_shutdown (void) } /* int iptables_shutdown */ #endif /* IPTABLES_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ipt_bytes_ds); - plugin_register_data_set (&ipt_packets_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&ipt_bytes_ds); + plugin_register_data_set (&ipt_packets_ds); + } #if IPTABLES_HAVE_READ - plugin_register_config ("iptables", iptables_config, - config_keys, config_keys_num); - plugin_register_read ("iptables", iptables_read); - plugin_register_shutdown ("iptables", iptables_shutdown); + if (load & MR_READ) + { + plugin_register_config ("iptables", iptables_config, + config_keys, config_keys_num); + plugin_register_read ("iptables", iptables_read); + plugin_register_shutdown ("iptables", iptables_shutdown); + } #endif -} +} /* void module_register */ #undef BUFSIZE #undef MODULE_NAME diff --git a/src/irq.c b/src/irq.c index e39d0a57..3df9d869 100644 --- a/src/irq.c +++ b/src/irq.c @@ -25,8 +25,6 @@ #include "plugin.h" #include "configfile.h" -#define MODULE_NAME "irq" - #if KERNEL_LINUX # define IRQ_HAVE_READ 1 #else @@ -216,16 +214,19 @@ static int irq_read (void) } /* int irq_read */ #endif /* IRQ_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds_irq); + if (load & MR_DATASETS) + plugin_register_data_set (&ds_irq); #if IRQ_HAVE_READ - plugin_register_config ("irq", irq_config, - config_keys, config_keys_num); - plugin_register_read ("irq", irq_read); + if (load & MR_READ) + { + plugin_register_config ("irq", irq_config, + config_keys, config_keys_num); + plugin_register_read ("irq", irq_read); + } #endif /* IRQ_HAVE_READ */ -} +} /* void module_register */ #undef BUFSIZE -#undef MODULE_NAME diff --git a/src/load.c b/src/load.c index b92e54f5..7be594d1 100644 --- a/src/load.c +++ b/src/load.c @@ -23,8 +23,6 @@ #include "common.h" #include "plugin.h" -#define MODULE_NAME "load" - #if defined(HAVE_GETLOADAVG) || defined(KERNEL_LINUX) || defined(HAVE_LIBSTATGRAB) # define LOAD_HAVE_READ 1 #else @@ -151,12 +149,13 @@ static int load_read (void) } #endif /* LOAD_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds); + if (load & MR_DATASETS) + plugin_register_data_set (&ds); + #if LOAD_HAVE_READ - plugin_register_read ("load", load_read); + if (load & MR_READ) + plugin_register_read ("load", load_read); #endif -} - -#undef MODULE_NAME +} /* void module_register */ diff --git a/src/logfile.c b/src/logfile.c index 4563c892..5cb40914 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -113,12 +113,11 @@ static void logfile_log (int severity, const char *msg) return; } /* void logfile_log (int, const char *) */ -void module_register (void) +void module_register (modreg_e load) { plugin_register_config ("logfile", logfile_config, config_keys, config_keys_num); plugin_register_log ("logfile", logfile_log); - return; } /* void module_register (void) */ /* vim: set sw=4 ts=4 tw=78 noexpandtab : */ diff --git a/src/mbmon.c b/src/mbmon.c index fcb4cc74..08c49fe3 100644 --- a/src/mbmon.c +++ b/src/mbmon.c @@ -339,14 +339,20 @@ static int mbmon_read (void) /* module_register Register collectd plugin. */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&fanspeed_ds); - plugin_register_data_set (&temperature_ds); - plugin_register_data_set (&voltage_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&fanspeed_ds); + plugin_register_data_set (&temperature_ds); + plugin_register_data_set (&voltage_ds); + } #if MBMON_HAVE_READ - plugin_register_config ("mbmon", mbmon_config, config_keys, config_keys_num); - plugin_register_read ("mbmon", mbmon_read); + if (load & MR_READ) + { + plugin_register_config ("mbmon", mbmon_config, config_keys, config_keys_num); + plugin_register_read ("mbmon", mbmon_read); + } #endif /* MBMON_HAVE_READ */ -} +} /* void module_register */ diff --git a/src/memory.c b/src/memory.c index 66bcefae..21877205 100644 --- a/src/memory.c +++ b/src/memory.c @@ -327,12 +327,16 @@ static int memory_read (void) } #endif /* MEMORY_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds); + if (load & MR_DATASETS) + plugin_register_data_set (&ds); #if MEMORY_HAVE_READ - plugin_register_init ("memory", memory_init); - plugin_register_read ("memory", memory_read); + if (load & MR_READ) + { + plugin_register_init ("memory", memory_init); + plugin_register_read ("memory", memory_read); + } #endif /* MEMORY_HAVE_READ */ -} +} /* void module_register */ diff --git a/src/multimeter.c b/src/multimeter.c index d80c990c..02abfc8a 100644 --- a/src/multimeter.c +++ b/src/multimeter.c @@ -260,13 +260,17 @@ static int multimeter_shutdown (void) } #endif /* MULTIMETER_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&data_set); + if (load & MR_DATASETS) + plugin_register_data_set (&data_set); #if MULTIMETER_HAVE_READ - plugin_register_init ("multimeter", multimeter_init); - plugin_register_read ("multimeter", multimeter_read); - plugin_register_shutdown ("multimeter", multimeter_shutdown); + if (load & MR_READ) + { + plugin_register_init ("multimeter", multimeter_init); + plugin_register_read ("multimeter", multimeter_read); + plugin_register_shutdown ("multimeter", multimeter_shutdown); + } #endif /* MULTIMETER_HAVE_READ */ -} +} /* void module_register */ diff --git a/src/mysql.c b/src/mysql.c index 92b49bff..5fbe5a66 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -377,16 +377,22 @@ static int mysql_read (void) } /* int mysql_read */ #endif /* MYSQL_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds_commands); - plugin_register_data_set (&ds_handler); - plugin_register_data_set (&ds_qcache); - plugin_register_data_set (&ds_threads); - plugin_register_data_set (&ds_octets); + if (load & MR_DATASETS) + { + plugin_register_data_set (&ds_commands); + plugin_register_data_set (&ds_handler); + plugin_register_data_set (&ds_qcache); + plugin_register_data_set (&ds_threads); + plugin_register_data_set (&ds_octets); + } #if MYSQL_HAVE_READ - plugin_register_config ("mysql", config, config_keys, config_keys_num); - plugin_register_read ("mysql", mysql_read); + if (load & MR_READ) + { + plugin_register_config ("mysql", config, config_keys, config_keys_num); + plugin_register_read ("mysql", mysql_read); + } #endif /* MYSQL_HAVE_READ */ } /* void module_register */ diff --git a/src/network.c b/src/network.c index 6d86c1d0..4b50ce2d 100644 --- a/src/network.c +++ b/src/network.c @@ -1343,9 +1343,9 @@ static int network_init (void) return (0); } /* int network_init */ -void module_register (void) +void module_register (modreg_e load) { plugin_register_config ("network", network_config, config_keys, config_keys_num); plugin_register_init ("network", network_init); -} +} /* void module_register */ diff --git a/src/nfs.c b/src/nfs.c index d54c8388..40e4110b 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -24,8 +24,6 @@ #include "common.h" #include "plugin.h" -#define MODULE_NAME "nfs" - /* #if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) */ #if KERNEL_LINUX # define NFS_HAVE_READ 1 @@ -380,13 +378,13 @@ static int nfs_read (void) } #endif /* NFS_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&procedure_ds); + if (load & MR_DATASETS) + plugin_register_data_set (&procedure_ds); #if NFS_HAVE_READ - plugin_register_read ("nfs", nfs_read); + if (load & MR_READ) + plugin_register_read ("nfs", nfs_read); #endif -} - -#undef MODULE_NAME +} /* void module_register */ diff --git a/src/ntpd.c b/src/ntpd.c index dded360c..7f4d62a0 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -960,15 +960,22 @@ static int ntpd_read (void) } /* int ntpd_read */ #endif /* NTPD_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&time_offset_ds); - plugin_register_data_set (&time_dispersion_ds); - plugin_register_data_set (&delay_ds); - plugin_register_data_set (&frequency_offset_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&time_offset_ds); + plugin_register_data_set (&time_dispersion_ds); + plugin_register_data_set (&delay_ds); + plugin_register_data_set (&frequency_offset_ds); + } #if NTPD_HAVE_READ - plugin_register_config ("ntpd", ntpd_config, config_keys, config_keys_num); - plugin_register_read ("ntpd", ntpd_read); + if (load & MR_READ) + { + plugin_register_config ("ntpd", ntpd_config, + config_keys, config_keys_num); + plugin_register_read ("ntpd", ntpd_read); + } #endif /* NTPD_HAVE_READ */ -} +} /* void module_register */ diff --git a/src/ping.c b/src/ping.c index 7c30a25e..6dcd9ec7 100644 --- a/src/ping.c +++ b/src/ping.c @@ -239,10 +239,16 @@ static int ping_read (void) return (0); } /* int ping_read */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds); - plugin_register_init ("ping", ping_init); - plugin_register_read ("ping", ping_read); - plugin_register_config ("ping", ping_config, config_keys, config_keys_num); + if (load & MR_DATASETS) + plugin_register_data_set (&ds); + + if (load & MR_READ) + { + plugin_register_config ("ping", ping_config, + config_keys, config_keys_num); + plugin_register_init ("ping", ping_init); + plugin_register_read ("ping", ping_read); + } } /* void module_register */ diff --git a/src/plugin.c b/src/plugin.c index 86ffbde7..c6762dec 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -118,10 +118,10 @@ static int plugin_unregister (llist_t *list, const char *name) * object, but it will bitch about a shared object not having a * ``module_register'' symbol.. */ -static int plugin_load_file (char *file) +static int plugin_load_file (char *file, modreg_e load) { lt_dlhandle dlh; - void (*reg_handle) (void); + void (*reg_handle) (modreg_e mr); DEBUG ("file = %s", file); @@ -137,7 +137,7 @@ static int plugin_load_file (char *file) return (1); } - if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL) + if ((reg_handle = (void (*) (modreg_e)) lt_dlsym (dlh, "module_register")) == NULL) { WARNING ("Couldn't find symbol ``module_register'' in ``%s'': %s\n", file, lt_dlerror ()); @@ -145,7 +145,7 @@ static int plugin_load_file (char *file) return (-1); } - (*reg_handle) (); + (*reg_handle) (load); return (0); } @@ -291,7 +291,7 @@ void plugin_set_dir (const char *dir) } #define BUFSIZE 512 -int plugin_load (const char *type) +int plugin_load (const char *type, modreg_e mr) { DIR *dh; const char *dir; @@ -348,7 +348,7 @@ int plugin_load (const char *type) continue; } - if (plugin_load_file (filename) == 0) + if (plugin_load_file (filename, mr) == 0) { /* success */ ret = 0; diff --git a/src/plugin.h b/src/plugin.h index ba6cde28..0164e9cf 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -46,6 +46,15 @@ /* * Public data types */ +enum modreg +{ + MR_EVERYTHING = 7, + MR_DATASETS = 1, + MR_READ = 2, + MR_WRITE = 4 +}; +typedef enum modreg modreg_e; + typedef unsigned long long counter_t; typedef double gauge_t; @@ -119,7 +128,8 @@ void plugin_set_dir (const char *dir); * functions. * * ARGUMENTS - * `type' Name of the plugin to load. + * `name' Name of the plugin to load. + * `mr' Types of functions to request from the plugin. * * RETURN VALUE * Returns zero upon success, a value greater than zero if no plugin was found @@ -128,7 +138,7 @@ void plugin_set_dir (const char *dir); * NOTES * No attempt is made to re-load an already loaded module. */ -int plugin_load (const char *name); +int plugin_load (const char *name, modreg_e mr); void plugin_init_all (void); void plugin_read_all (const int *loop); diff --git a/src/processes.c b/src/processes.c index 5fd12212..f57f2d31 100644 --- a/src/processes.c +++ b/src/processes.c @@ -1075,21 +1075,26 @@ static int ps_read (void) } /* int ps_read */ #endif /* PROCESSES_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&state_ds); - plugin_register_data_set (&rss_ds); - plugin_register_data_set (&time_ds); - plugin_register_data_set (&count_ds ); - plugin_register_data_set (&pagefaults_ds ); + if (load & MR_DATASETS) + { + plugin_register_data_set (&state_ds); + plugin_register_data_set (&rss_ds); + plugin_register_data_set (&time_ds); + plugin_register_data_set (&count_ds); + plugin_register_data_set (&pagefaults_ds); + } #if PROCESSES_HAVE_READ + if (load & MR_READ) + { #if HAVE_THREAD_INFO | KERNEL_LINUX - plugin_register_config ("processes", ps_config, - config_keys, config_keys_num); + plugin_register_config ("processes", ps_config, + config_keys, config_keys_num); #endif - plugin_register_init ("processes", ps_init); - plugin_register_read ("processes", ps_read); + plugin_register_init ("processes", ps_init); + plugin_register_read ("processes", ps_read); + } #endif /* PROCESSES_HAVE_READ */ -} - +} /* void module_register */ diff --git a/src/rrdtool.c b/src/rrdtool.c index 6dc14c76..b221341c 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -817,7 +817,7 @@ static int rrd_init (void) return (0); } /* int rrd_init */ -void module_register (void) +void module_register (modreg_e load) { plugin_register_config ("rrdtool", rrd_config, config_keys, config_keys_num); diff --git a/src/sensors.c b/src/sensors.c index 4b0fc3da..551d267c 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -449,16 +449,22 @@ static int sensors_read (void) } /* int sensors_read */ #endif /* SENSORS_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&fanspeed_ds); - plugin_register_data_set (&temperature_ds); - plugin_register_data_set (&voltage_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&fanspeed_ds); + plugin_register_data_set (&temperature_ds); + plugin_register_data_set (&voltage_ds); + } #if SENSORS_HAVE_READ - plugin_register_config ("sensors", sensors_config, - config_keys, config_keys_num); - plugin_register_read ("sensors", sensors_read); - plugin_register_shutdown ("sensors", sensors_shutdown); + if (load & MR_READ) + { + plugin_register_config ("sensors", sensors_config, + config_keys, config_keys_num); + plugin_register_read ("sensors", sensors_read); + plugin_register_shutdown ("sensors", sensors_shutdown); + } #endif } /* void module_register */ diff --git a/src/serial.c b/src/serial.c index 9fb26df1..c2786720 100644 --- a/src/serial.c +++ b/src/serial.c @@ -136,11 +136,13 @@ static int serial_read (void) } /* int serial_read */ #endif /* SERIAL_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&octets_ds); + if (load & MR_DATASETS) + plugin_register_data_set (&octets_ds); #if SERIAL_HAVE_READ - plugin_register_read ("serial", serial_read); + if (load & MR_READ) + plugin_register_read ("serial", serial_read); #endif /* SERIAL_HAVE_READ */ -} +} /* void module_register */ diff --git a/src/swap.c b/src/swap.c index 6b0620cd..86bdc352 100644 --- a/src/swap.c +++ b/src/swap.c @@ -312,12 +312,16 @@ static int swap_read (void) } /* int swap_read */ #endif /* SWAP_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&data_set); + if (load & MR_DATASETS) + plugin_register_data_set (&data_set); #if SWAP_HAVE_READ - plugin_register_init ("swap", swap_init); - plugin_register_read ("swap", swap_read); + if (load & MR_READ) + { + plugin_register_init ("swap", swap_init); + plugin_register_read ("swap", swap_read); + } #endif /* SWAP_HAVE_READ */ -} +} /* void module_register */ diff --git a/src/syslog.c b/src/syslog.c index 3123e89b..d643e39a 100644 --- a/src/syslog.c +++ b/src/syslog.c @@ -86,12 +86,10 @@ static int sl_shutdown (void) return (0); } -void module_register (void) +void module_register (modreg_e load) { plugin_register_config ("syslog", sl_config, config_keys, config_keys_num); plugin_register_init ("syslog", sl_init); plugin_register_log ("syslog", sl_log); plugin_register_shutdown ("syslog", sl_shutdown); - - return; } /* void module_register(void) */ diff --git a/src/tape.c b/src/tape.c index 85a63a89..2345cb34 100644 --- a/src/tape.c +++ b/src/tape.c @@ -162,15 +162,21 @@ static int tape_read (void) } #endif /* TAPE_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&octets_ds); - plugin_register_data_set (&operations_ds); - plugin_register_data_set (&merged_ds); - plugin_register_data_set (&time_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&octets_ds); + plugin_register_data_set (&operations_ds); + plugin_register_data_set (&merged_ds); + plugin_register_data_set (&time_ds); + } #if TAPE_HAVE_READ - plugin_register_init ("tape", tape_init); - plugin_register_read ("tape", tape_read); + if (load & MR_READ) + { + plugin_register_init ("tape", tape_init); + plugin_register_read ("tape", tape_read); + } #endif /* TAPE_HAVE_READ */ } diff --git a/src/unixsock.c b/src/unixsock.c index 75f3117e..aa5b67c0 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -844,7 +844,7 @@ static int us_write (const data_set_t *ds, const value_list_t *vl) return (0); } -void module_register (void) +void module_register (modreg_e load) { plugin_register_config ("unixsock", us_config, config_keys, config_keys_num); diff --git a/src/users.c b/src/users.c index 03d6148c..e600aab3 100644 --- a/src/users.c +++ b/src/users.c @@ -109,9 +109,13 @@ static int users_read (void) } /* int users_read */ #endif /* USERS_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&ds); - plugin_register_read ("users", users_read); - return; + if (load & MR_DATASETS) + plugin_register_data_set (&ds); + +#if USERS_HAVE_READ + if (load & MR_READ) + plugin_register_read ("users", users_read); +#endif } /* void module_register(void) */ diff --git a/src/vserver.c b/src/vserver.c index e4742e91..2e390609 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -362,17 +362,23 @@ static int vserver_read (void) } /* int vserver_read */ #endif /* VSERVER_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&octets_ds); - plugin_register_data_set (&load_ds); - plugin_register_data_set (&threads_ds); - plugin_register_data_set (&processes_ds); - plugin_register_data_set (&memory_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&octets_ds); + plugin_register_data_set (&load_ds); + plugin_register_data_set (&threads_ds); + plugin_register_data_set (&processes_ds); + plugin_register_data_set (&memory_ds); + } #if VSERVER_HAVE_READ - plugin_register_init ("vserver", vserver_init); - plugin_register_read ("vserver", vserver_read); + if (load & MR_READ) + { + plugin_register_init ("vserver", vserver_init); + plugin_register_read ("vserver", vserver_read); + } #endif /* VSERVER_HAVE_READ */ } /* void module_register(void) */ diff --git a/src/wireless.c b/src/wireless.c index 8ce7854c..007272e1 100644 --- a/src/wireless.c +++ b/src/wireless.c @@ -167,13 +167,17 @@ static int wireless_read (void) } /* int wireless_read */ #endif /* WIRELESS_HAVE_READ */ -void module_register (void) +void module_register (modreg_e load) { - plugin_register_data_set (&quality_ds); - plugin_register_data_set (&power_ds); - plugin_register_data_set (&noise_ds); + if (load & MR_DATASETS) + { + plugin_register_data_set (&quality_ds); + plugin_register_data_set (&power_ds); + plugin_register_data_set (&noise_ds); + } #if WIRELESS_HAVE_READ - plugin_register_read ("wireless", wireless_read); + if (load & MR_READ) + plugin_register_read ("wireless", wireless_read); #endif /* WIRELESS_HAVE_READ */ -} +} /* void module_register */