summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 979041e)
raw | patch | inline | side by side (parent: 979041e)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 16 Feb 2009 17:17:53 +0000 (18:17 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 16 Feb 2009 17:17:53 +0000 (18:17 +0100) |
This is required by the default PostgreSQL queries.
src/collectd.conf.pod | patch | blob | history | |
src/utils_db_query.c | patch | blob | history |
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index a1c2b073fcf1bec15f35a823e207bca7073d8d9a..e323c36cdae48b647550efa2027a095bc7f9ff53 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
=item B<InstancePrefix> I<prefix>
-Prepends I<prefix> followed by a dash I<("-")> to the type instance. See
-B<InstancesFrom> on how the rest of the type instance is built.
+Prepends I<prefix> to the type instance. If B<InstancesFrom> (see below) is not
+given, the string is simply copied. If B<InstancesFrom> is given, I<prefix> and
+all strings returned in the appropriate columns are concatenated together,
+separated by dahes I<("-")>.
=item B<InstancesFrom> I<column0> [I<column1> ...]
-Specifies the columns whose values will be used to create the "TypeInstance"
-for each row. You need to specify at least one column for each query. If you
-specify more than one column, the value of all columns will be join together
-with the hyphen as separation character.
+Specifies the columns whose values will be used to create the "type-instance"
+for each row. If you specify more than one column, the value of all columns
+will be join together with the dahes I<("-")> as separation character.
The plugin itself does not check whether or not all built instances are
-different. It's your responsibility to assure that each is unique.
+different. It's your responsibility to assure that each is unique. This is
+especially true, if you do not specify B<InstancesFrom>: B<You> have to make
+sure that only one row is returned in this case.
-There must be at least one B<InstancesFrom> option inside each B<Result> block.
+If neither B<InstancePrefix> nor B<InstancesFrom> is given, the type-instance
+will be empty.
=item B<ValuesFrom> I<column0> [I<column1> ...]
diff --git a/src/utils_db_query.c b/src/utils_db_query.c
index 33107649f1f7be1b298b6f49c4c5084534530c7e..c2897c7c88c51717fde50b4d9c5b97b92b6c5727 100644 (file)
--- a/src/utils_db_query.c
+++ b/src/utils_db_query.c
assert (r->ds != NULL);
assert (((size_t) r->ds->ds_num) == r->values_num);
- DEBUG ("db query utils: udb_result_submit: r->instance_prefix = %s;",
- (r->instance_prefix == NULL) ? "NULL" : r->instance_prefix);
- for (i = 0; i < r->instances_num; i++)
- {
- DEBUG ("db query utils: udb_result_submit: r->instances_buffer[%zu] = %s;",
- i, r->instances_buffer[i]);
- }
-
vl.values = (value_t *) calloc (r->ds->ds_num, sizeof (value_t));
if (vl.values == NULL)
{
sstrncpy (vl.plugin_instance, q->db_name, sizeof (vl.type_instance));
sstrncpy (vl.type, r->type, sizeof (vl.type));
- if (r->instance_prefix == NULL)
+ /* Set vl.type_instance {{{ */
+ if (r->instances_num <= 0)
{
- strjoin (vl.type_instance, sizeof (vl.type_instance),
- r->instances_buffer, r->instances_num, "-");
+ if (r->instance_prefix == NULL)
+ vl.type_instance[0] = 0;
+ else
+ sstrncpy (vl.type_instance, r->instance_prefix,
+ sizeof (vl.type_instance));
}
- else
+ else /* if ((r->instances_num > 0) */
{
- char tmp[DATA_MAX_NAME_LEN];
+ if (r->instance_prefix == NULL)
+ {
+ strjoin (vl.type_instance, sizeof (vl.type_instance),
+ r->instances_buffer, r->instances_num, "-");
+ }
+ else
+ {
+ char tmp[DATA_MAX_NAME_LEN];
- strjoin (tmp, sizeof (tmp), r->instances_buffer, r->instances_num, "-");
- tmp[sizeof (tmp) - 1] = 0;
+ strjoin (tmp, sizeof (tmp), r->instances_buffer, r->instances_num, "-");
+ tmp[sizeof (tmp) - 1] = 0;
- snprintf (vl.type_instance, sizeof (vl.type_instance), "%s-%s",
- r->instance_prefix, tmp);
+ snprintf (vl.type_instance, sizeof (vl.type_instance), "%s-%s",
+ r->instance_prefix, tmp);
+ }
}
vl.type_instance[sizeof (vl.type_instance) - 1] = 0;
+ /* }}} */
plugin_dispatch_values (&vl);
/* Allocate r->instances_pos, r->values_pos, r->instances_buffer, and
* r->values_buffer {{{ */
- r->instances_pos = (size_t *) calloc (r->instances_num, sizeof (size_t));
- if (r->instances_pos == NULL)
+ if (r->instances_num > 0)
{
- ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
- BAIL_OUT (-ENOMEM);
- }
+ r->instances_pos = (size_t *) calloc (r->instances_num, sizeof (size_t));
+ if (r->instances_pos == NULL)
+ {
+ ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
+ BAIL_OUT (-ENOMEM);
+ }
+
+ r->instances_buffer = (char **) calloc (r->instances_num, sizeof (char *));
+ if (r->instances_buffer == NULL)
+ {
+ ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
+ BAIL_OUT (-ENOMEM);
+ }
+ } /* if (r->instances_num > 0) */
r->values_pos = (size_t *) calloc (r->values_num, sizeof (size_t));
if (r->values_pos == NULL)
BAIL_OUT (-ENOMEM);
}
- r->instances_buffer = (char **) calloc (r->instances_num, sizeof (char *));
- if (r->instances_buffer == NULL)
- {
- ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
- BAIL_OUT (-ENOMEM);
- }
-
r->values_buffer = (char **) calloc (r->values_num, sizeof (char *));
if (r->values_buffer == NULL)
{
"result in query `%s'", query_name);
status = -1;
}
- if (r->instances == NULL)
- {
- WARNING ("db query utils: `InstancesFrom' not given for "
- "result in query `%s'", query_name);
- status = -1;
- }
if (r->values == NULL)
{
WARNING ("db query utils: `ValuesFrom' not given for "