Several of our customers use collectd to capture and push system statistics to graphs engines such as graphite. When it comes to MySQL, it has a specific plugin with several built-in statistics that are useful but not enough in most cases. One option to overcome this limitation is to use the DBI plugin to build custom statistics, based on MySQL queries. This approach can be used to easily capture any status variable or even to collect application metrics. It's worth mentioning that even though this post is oriented to MySQL databases, the DBI plugin can be used with other RDBMSs as well.
collectd.conf.rpmsave back to collectd.conf
LoadPlugin clause, this file will store the metrics configuration and datasource. The configuration is fairly self explanatory and each section is documented here, but allow me to point out a few details to save you time:
MinVersion clause to specify what is the minimum MySQL version this metric can executed against (in this case version should at least 5.1)<database> block once for each MySQL instance running locally. Then bind the database with the corresponding metric by using the Query clauseType and the name provided inside the tagDERIVE) or the actual values returned by the query (GAUGE)LoadPlugin dbi by the following block:
<LoadPlugin dbi> Interval <secs> </LoadPlugin>
<type>_<query_name>.rrd) or that the new metric is available on graphite so that it could be plotted after enough values are captured.
The DBI plugin allows you to enhance MySQL (and also other popular RDBMS) monitoring when you have a collectd-based infrastructure in place. Starting from MySQL v5.1, any configuration or status variable can be accessed through the information schema, using a standard SELECT statement against GLOBAL_VARIABLES or GLOBAL_STATUS tables respectively. Finally, remember that by default, the DBI plugin will use the global collectd polling interval and even when this variable is configured at the plugin level, all queries will be executed simultaneously.
Ready to optimize your MySQL Database for the future?