scavern

Update MySQL Global Stats datasource to read config from my.cnf

Recommended Posts

Hi,

I had an alert yesterday for the Threads_connected datapoint on the MySQL Global Stats datasource. We actually increased the max_connections in the my.cnf config file.
Is it possible to either read my.cnf file (assuming SSH credentials are available), or get the max connections variable to see what it is actually configured as?

This will negate the need to manually check the value in the config and adjust thresholds. 

Share this post


Link to post
Share on other sites

Yes, you could write a property source that would SSH into the server and get the max_connections from the config file and set it as a property on the device. Then you'd need to slightly modify the mysql global stats datasource so that it used that property in a complex datapoint that uses a formula like this:

if(un(##max_connections##), threads_connected, threads_connected / ##max_connections##)

I haven't tested this, but this is the gist of how it would work. 

There's an example Expect script here: https://github.com/sweenig/monitoring-recipes/blob/master/DataSources/Groovy/Expect/Groovy_Expect_Example.groovy

Share this post


Link to post
Share on other sites

Or, you could not add SSH overhead and just use a query :).

MariaDB [(none)]> show variables like '%conn%';
+-----------------------------------------------+-----------------+
| Variable_name                                 | Value           |
+-----------------------------------------------+-----------------+
| character_set_connection                      | utf8            |
| collation_connection                          | utf8_general_ci |
| connect_timeout                               | 10              |
| default_master_connection                     |                 |
| extra_max_connections                         | 1               |
| init_connect                                  |                 |
| max_connect_errors                            | 100             |
| max_connections                               | 151             |
| max_user_connections                          | 0               |
| performance_schema_session_connect_attrs_size | -1              |
+-----------------------------------------------+-----------------+
10 rows in set (0.00 sec)

Confirmed via same user with GRANT USAGE as normally required for "show global status" results.

Share this post


Link to post
Share on other sites

Either way, but a property has the advantage of being able to be referenced in alert messages, so sure :).  If you want to reference it for percentage utilization, I think it still needs to be a DP as well.

Share this post


Link to post
Share on other sites

Cool. I was trying to figure out how to get the output of two queries within the single DS. I guess you could cobble together some sort of union of the two so that it returns a single recordset?

Share this post


Link to post
Share on other sites

Wait, wait, wait. Isn't 

show global status;

contained inside

show variables;

If that's the case (to be verified), you could just change the query to "show variables;" and it should output all the same stuff along with max_connections. Then it's just a matter of adding the datapoint.

Share this post


Link to post
Share on other sites

I don't think so, but perhaps.  global status should have current statistics and variables should have static settings.  Could be wrong, of course. 

As far as the DP versus property issue, yeah, I have run into this before.  We wanted to be able to reference a property in widgets and you simply can't, so we had to create a datapoint from the property (this is to be able to display resource commit usage for our clients).  So, we have a DS applied to collectors that only has complex groovy datapoints with the value ##property## for each.  Rough edges :).

Share this post


Link to post
Share on other sites
Just now, mnagel said:

we have a DS applied to collectors that only has complex groovy datapoints with the value ##property## for each.

Exactly how I would do it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.