collectd/collectd — pull request #317 by mwongatemma (2013-05-09 19:34:21+00:00)
Title: Annotate meta data for db plugins

Annotate the value_list_t structure with information such that it can
store database name, schema name, table name, and index name as
metadata if so desired.

For database stats:

SELECT datname, numbackends
FROM pg_stat_database

This query lets us get stats for all databases in a single query. In
the block the following parameter needs to be set to annotate
the metadata from which database the data is from:

DatabaseNameFrom "datname"

In the event that DatabaseNameFrom is not set, the name used the
block will be set as the database name in the metadata.

For table stats:

SELECT schemaname, relname, seq_scan
FROM pg_stat_all_tables

To keep the data distinct, the following parameters need to be set for
each value selected in the tag, resulting in a reversed order
naming scheme in type_instance:

InstancePrefix "seq_scan"
InstancesFrom "relname" "schemaname"

In the block the following parameters need be set to annotate
the data with the schema and table information:

SchemaNameFrom "schemaname"
TableNameFrom "relname"

For index stats:

SELECT schemaname, relname, indexrelname, idx_scan
FROM pg_stat_all_indexes

To keep the data distinct, the following parameters need to be set for
each value selected in the tag, resulting in a reversed order
naming scheme in type_instance:

InstancePrefix "idx_scan"
InstancesFrom "indexrelname" "relname" "schemaname"

In the block the following parameters need be set to annotate
the data with the schema, table, and index information:

SchemaNameFrom "schemaname"
TableNameFrom "relname"
IndexNameFrom "indexrelname"

Note there is no need to select the database name when querying for
table and index stats because these stats can only be queried per
database.

Using InstancesFrom is still required to ensure the instances are
distinct but the '-' separated value can still be ambiguous as database,
schema, table, and index names may contain '-'s.