环境:openstack rock,mariadb10.3
prometheus 检测到 QPS:rate(mysql_global_status_questions[5m]) 指标从 280 忽然增加到 500, 2-3天里 一直在增加,第4天后趋于稳定,达到 700 左右。决定查看查看 mariadb 的性能,以及具体哪个数据库账户发起较多的请求。
1、查看 mysql 性能
show processlist;
select * from information_schema.processlist where info is not null;
show variables like 'long_query_time';
show global status like "slow_queries";
show variables like 'max_connections';
show global status like 'Threads_connected'; #已经建立的连接
show global status like 'Threads_running'; #正在运行的连接
show global status like 'Connection_errors_internal'; #由于服务器内部本身的错误
show global status like 'Aborted_connects'; #尝试与服务器建立但是失败的次数
show global status like 'Connection_errors_max_connections'; #由于到达最大连接数导致的错误
show global status like 'Innodb_buffer_pool_read_requests'; #bp读取请求
show global status like 'Innodb_buffer_pool_reads'; #需要读取磁盘的请求数
show full processlist # 查看连接数
show global status like 'max_connections'; #查看最大连接数
show global status like 'aborted_connects'; #查看当前失败连接数
show global status like 'aborted_clients'; #由于客户端没有正确关闭连接而死掉的连接数
show global status like 'questions'; # 当前查询总次数
show global status like 'com_insert'; #当前 mysql 实例 insert 语句执行总次数
2、开启日志, GLOBAL log_output=‘Table’ 会将访问存储在 mysql.general_log 表中,但是会比较消耗资源,不需要的时候,最好关闭。
set GLOBAL log_output='Table';
set GLOBAL general_log='ON';
3、一段时间后,关闭日志
set GLOBAL log_output='File';
set GLOBAL general_log='OFF';
4、查看各个用户的查询数量
show GLOBAL VARIABLES like '%general_log%'
show GLOBAL VARIABLES like 'log_output';
show GLOBAL VARIABLES like '%log%'
select * from mysql.user
select count(1) from mysql.general_log;
select * from mysql.general_log order by event_time limit 1;
select * from mysql.general_log order by event_time desc limit 2;
select count(1) from mysql.general_log where user_host like 'nova[nova]%';
select count(1) from mysql.general_log where user_host like 'nova_api%';
select count(1) from mysql.general_log where user_host like 'cinder%';
select count(1) from mysql.general_log where user_host like 'glance%';
select count(1) from mysql.general_log where user_host like 'keystone%';
select count(1) from mysql.general_log where user_host like 'neutron%';
select count(1) from mysql.general_log where user_host like 'nova_cell%';
select count(1) from mysql.general_log where user_host like 'prometheus%';
select count(1) from mysql.general_log where user_host like 'haproxy%';
select count(1) from mysql.general_log where user_host like 'root%';
5、发现 neutron 账户请求占了 65%,但是 neutron 服务并未报错。目前也没有发现更好的方法继续追踪下去