Skip to content
Snippets Groups Projects
Verified Commit 026480fd authored by Florian Pritz's avatar Florian Pritz
Browse files

WIP: Monitor mysql table stats


TODO this still needs to give zabbix SELECT permissions to the tables,
otherwise the table statistics are not available. Do we want zabbix to
be able to read everything? Not sure yet, leaning towards no.

I don't want to lose the other changes though so I'm commiting this here
for now.

Signed-off-by: default avatarFlorian Pritz <bluewind@xinu.at>
parent b7ab03fa
Branches wip/aur
No related tags found
No related merge requests found
......@@ -42,6 +42,8 @@
- name: configure zabbix-agent user
mysql_user: user={{zabbix_agent_mysql_user}} host=localhost password={{vault_mariadb_users.zabbix_agent}}
# TODO give zabbix-agent select permissions on all tablesse. maybe don't?
- name: install zabbix mysql config
template: src=zabbix_agentd.my.cnf.j2 dest=/etc/zabbix/zabbix_agentd.my.cnf owner=zabbix-agent group=zabbix-agent mode=0600
......
......@@ -7,27 +7,30 @@ use JSON;
my $config = $ARGV[0];
my $mode = $ARGV[1];
my $user = $ARGV[2];
if (!($mode eq "userstat" or $mode eq "discover")) {
print STDERR "mode is not userstat or discover\n";
die;
}
if ($mode eq "userstat" and not defined $user) {
print STDERR "userstat requires user to be defined\n";
die;
}
my $db = DBI->connect("DBI:mysql:mysql_read_default_file=$config");
if ($mode eq "userstat") {
my $user = $ARGV[2] // die "user not defined";
$db->{FetchHashKeyName} = "NAME_lc";
print encode_json($db->selectrow_hashref("select * from information_schema.user_statistics where user = ?", undef, $user));
} elsif ($mode eq "tablestats") {
my $schema = $ARGV[2] // die "schema not defined";
my $table = $ARGV[3] // die "table not defined";
$db->{FetchHashKeyName} = "NAME_lc";
print encode_json($db->selectrow_hashref("select * from information_schema.table_statistics where table_schema = ? and table_name = ?", undef, $schema, $table));
} elsif ($mode eq "tablestats_discover") {
print encode_json({
data => $db->selectall_arrayref("select table_schema '{#SCHEMA}', table_name '{#TABLENAME}' from information_schema.table_statistics", {Slice=>{}})
});
} elsif ($mode eq "discover") {
print encode_json({
data => $db->selectall_arrayref("select user '{#USERNAME}' from information_schema.user_statistics", {Slice=>{}})
});
} else {
die "unhandeled mode";
}
......@@ -12,6 +12,8 @@ TLSPSKFile=/etc/zabbix/zabbix_agentd.psk
UserParameter=mysql.ping,mysqladmin --defaults-file="/etc/zabbix/zabbix_agentd.my.cnf" ping|grep alive|wc -l
UserParameter=mysql.version,mysql --defaults-file="/etc/zabbix/zabbix_agentd.my.cnf" -V
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | mysql --defaults-file="/etc/zabbix/zabbix_agentd.my.cnf" -N | awk '{print $$2}'
UserParameter=mysql.tablestats[*],/usr/local/bin/mysql-user-stats.pl "/etc/zabbix/zabbix_agentd.my.cnf" tablestats '$1'
UserParameter=mysql.tablestats_discover,/usr/local/bin/mysql-user-stats.pl "/etc/zabbix/zabbix_agentd.my.cnf" tablestats_discover
UserParameter=mysql.userstats[*],/usr/local/bin/mysql-user-stats.pl "/etc/zabbix/zabbix_agentd.my.cnf" userstat '$1'
UserParameter=mysql.userstats_discover,/usr/local/bin/mysql-user-stats.pl "/etc/zabbix/zabbix_agentd.my.cnf" discover
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment