From: Pavel Rochnyack Date: Thu, 12 May 2016 10:24:00 +0000 (+0600) Subject: Allowed custom plugin name in 'dbi', 'oracle' and 'postgresql' plugins (per Database... X-Git-Tag: collectd-5.8.0~66^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5ee365a;p=collectd.git Allowed custom plugin name in 'dbi', 'oracle' and 'postgresql' plugins (per Database block). --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 3eaeb5d5..8ab20d19 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -491,6 +491,7 @@ # # # +# #PluginName "mycompany" # Driver "mysql" # DriverOption "host" "localhost" # DriverOption "username" "collectd" @@ -1014,6 +1015,7 @@ # # # +# #PluginName "warehouse" # ConnectID "db01" # Username "oracle" # Password "secret" @@ -1100,6 +1102,7 @@ # StoreRates true # # +# #PluginName "kingdom" # Host "hostname" # Port "5432" # User "username" diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 9b31de7e..b4fe2f96 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -2017,6 +2017,7 @@ than those of other plugins. It usually looks something like this: + #PluginName "warehouse" Driver "mysql" Interval 120 DriverOption "host" "localhost" @@ -2198,6 +2199,11 @@ the daemon. Other than that, that name is not used. =over 4 +=item B I + +Use I as the plugin name when submitting query results from +this B. Defaults to 'dbi'. + =item B I Sets the interval (in seconds) in which the values will be collected from this @@ -5589,6 +5595,7 @@ plugin's documentation above for details. + #PluginName "warehouse" ConnectID "db01" Username "oracle" Password "secret" @@ -5611,6 +5618,11 @@ values submitted to the daemon. Other than that, that name is not used. =over 4 +=item B I + +Use I as the plugin name when submitting query results from +this B. Defaults to 'oracle'. + =item B I Defines the "database alias" or "service name" to connect to. Usually, these @@ -5964,6 +5976,7 @@ L. + PluginName "kingdom" Host "hostname" Port "5432" User "username" @@ -6285,6 +6298,11 @@ activating this option. The draw-back is, that data covering the specified amount of time will be lost, for example, if a single statement within the transaction fails or if the database server crashes. +=item B I + +Use I as the plugin name when submitting query results from +this B. Defaults to 'postgresql'. + =item B I Specify the plugin instance name that should be used instead of the database diff --git a/src/dbi.c b/src/dbi.c index ac307ff2..ba91bffc 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -62,6 +62,7 @@ struct cdbi_database_s /* {{{ */ { char *name; char *select_db; + char *plugin_name; cdtime_t interval; @@ -172,7 +173,10 @@ static void cdbi_database_free(cdbi_database_t *db) /* {{{ */ return; sfree(db->name); + sfree(db->select_db); + sfree(db->plugin_name); sfree(db->driver); + sfree(db->host); for (size_t i = 0; i < db->driver_options_num; i++) { sfree(db->driver_options[i].key); @@ -298,6 +302,8 @@ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ status = cf_util_get_string(child, &db->host); else if (strcasecmp("Interval", child->key) == 0) status = cf_util_get_cdtime(child, &db->interval); + else if (strcasecmp("PluginName", child->key) == 0) + status = cf_util_get_string(child, &db->plugin_name); else { WARNING("dbi plugin: Option `%s' not allowed here.", child->key); status = -1; @@ -540,7 +546,8 @@ static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */ udb_query_prepare_result( q, prep_area, (db->host ? db->host : hostname_g), - /* plugin = */ "dbi", db->name, column_names, column_num, + /* plugin = */ (db->plugin_name != NULL) ? db->plugin_name : "dbi", + db->name, column_names, column_num, /* interval = */ (db->interval > 0) ? db->interval : 0); /* 0 = error; 1 = success; */ diff --git a/src/oracle.c b/src/oracle.c index 2d98f0aa..69e519bd 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -62,6 +62,7 @@ struct o_database_s { char *connect_id; char *username; char *password; + char *plugin_name; udb_query_preparation_area_t **q_prep_areas; udb_query_t **queries; @@ -141,6 +142,7 @@ static void o_database_free(o_database_t *db) /* {{{ */ sfree(db->username); sfree(db->password); sfree(db->queries); + sfree(db->plugin_name); if (db->q_prep_areas != NULL) for (size_t i = 0; i < db->queries_num; ++i) @@ -192,6 +194,7 @@ static int o_config_add_database(oconfig_item_t *ci) /* {{{ */ db->connect_id = NULL; db->username = NULL; db->password = NULL; + db->plugin_name = NULL; status = cf_util_get_string(ci, &db->name); if (status != 0) { @@ -211,6 +214,8 @@ static int o_config_add_database(oconfig_item_t *ci) /* {{{ */ status = cf_util_get_string(child, &db->username); else if (strcasecmp("Password", child->key) == 0) status = cf_util_get_string(child, &db->password); + else if (strcasecmp("PluginName", child->key) == 0) + status = cf_util_get_string(child, &db->plugin_name); else if (strcasecmp("Query", child->key) == 0) status = udb_query_pick_from_list(child, queries, queries_num, &db->queries, &db->queries_num); @@ -545,7 +550,8 @@ static int o_read_database_query(o_database_t *db, /* {{{ */ status = udb_query_prepare_result( q, prep_area, (db->host != NULL) ? db->host : hostname_g, - /* plugin = */ "oracle", db->name, column_names, column_num, + /* plugin = */ (db->plugin_name != NULL) ? db->plugin_name : "oracle", + db->name, column_names, column_num, /* interval = */ 0); if (status != 0) { ERROR("oracle plugin: o_read_database_query (%s, %s): " diff --git a/src/postgresql.c b/src/postgresql.c index d0c0ae13..70467c21 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -139,6 +139,7 @@ typedef struct { char *password; char *instance; + char *plugin_name; char *sslmode; @@ -250,6 +251,8 @@ static c_psql_database_t *c_psql_database_new(const char *name) { db->instance = sstrdup(name); + db->plugin_name = NULL; + db->sslmode = NULL; db->krbsrvname = NULL; @@ -300,6 +303,8 @@ static void c_psql_database_delete(void *data) { sfree(db->instance); + sfree(db->plugin_name); + sfree(db->sslmode); sfree(db->krbsrvname); @@ -539,9 +544,11 @@ static int c_psql_exec_query(c_psql_database_t *db, udb_query_t *q, else host = db->host; - status = - udb_query_prepare_result(q, prep_area, host, "postgresql", db->instance, - column_names, (size_t)column_num, db->interval); + status = udb_query_prepare_result( + q, prep_area, host, + (db->plugin_name != NULL) ? db->plugin_name : "postgresql", + db->instance, column_names, (size_t)column_num, db->interval); + if (0 != status) { log_err("udb_query_prepare_result failed with status %i.", status); BAIL_OUT(-1); @@ -1139,6 +1146,8 @@ static int c_psql_config_database(oconfig_item_t *ci) { cf_util_get_string(c, &db->password); else if (0 == strcasecmp(c->key, "Instance")) cf_util_get_string(c, &db->instance); + else if (0 == strcasecmp (c->key, "PluginName")) + cf_util_get_string (c, &db->plugin_name); else if (0 == strcasecmp(c->key, "SSLMode")) cf_util_get_string(c, &db->sslmode); else if (0 == strcasecmp(c->key, "KRBSrvName"))