如何每天确定MySQL查询?


15

我正在研究从MySQL到NoSQL DBaaS的重大转变,但是在尝试预测费用时遇到了一个问题。本质上,我无法弄清楚我当前的MySQL服务器每天要处理多少个查询,以尝试估计Cloudant使用的请求数,每100个PUT,POST和DELETE收取$ 0.015的费用,每500 GET收取$ 0.015的费用和头。

我已经找到了许多有关使用SHOW STATUSSHOW GLOBAL STATUS来获取MySQL自身收集的统计信息,但是没有时间表。

例如,SHOW GLOBAL STATUS返回以下内容:

Queries                           | 13576675

很好,除了我不知道包裹那个数字的时间表。1300万次查询何时?每月?年?从时间开始?

MySQL文档并没有详细说明:

查询

服务器执行的语句数。与Questions变量不同,此变量包括在存储的程序中执行的语句。它不计算COM_PING或COM_STATISTICS命令。这个变量是在MySQL 5.0.76中添加的。

在此先感谢您的帮助。


2
Queries全局状态变量计数这是一切,因为服务器上次启动... SHOW STATUS LIKE 'Uptime';秒前。许多状态变量已被清除,FLUSH STATUS;Queries至少在我刚刚确认的测试服务器中并未清除,它们是MySQL 5.5.19和5.6.14。
Michael-sqlbot

Answers:


15

对于SELECT:

show global status like "Com_select";

更新:

show global status like "Com_update";

插入:

show global status like "Com_insert";

删除:

show global status like "Com_delete";

自MySQL上次重启以来,AL1值是“ cumulativ”。

因此,在一小时内获得您的选择:

晚上9点:

[21:00:00] [DEV\(none)] mysql> show global status like "Com_select";
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| Com_select    | 671664 |
+---------------+--------+
1 row in set (0.00 sec)

晚上10点:

[22:00:00] [DEV\(none)] mysql> show global status like "Com_select";
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| Com_select    | 672363 |
+---------------+--------+
1 row in set (0.00 sec)

过去一个小时的SELECT数:672363-671664 = 699

最好的祝福


谢谢@mfouilleul,这很有帮助。我将把它与持续时间var结合起来,找出查询量。
AJB

1
为了清楚起见,show global status like 'Com_%';命令适用于整个服务器,对吗?在共享环境中,替代方案是什么—例如:估计距max_questions达到的每小时最大查询量(QPH)有多远。
Fabien Snauwaert

9

我使用此视图来关注每秒,分钟,小时和天的查询数量:

create or replace view _dba_query_stats as
select 
  SUBSTRING(VARIABLE_NAME, 5) as query_type, 
  VARIABLE_VALUE as total_count, 
  round(VARIABLE_VALUE / ( select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status'), 2) as per_second,
  round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60)))       as per_minute,
  round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60*60)))    as per_hour, 
  round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60*60*24))) as per_day,
  FROM_UNIXTIME(round(UNIX_TIMESTAMP(sysdate()) - (select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status'))) report_period_start,
  sysdate() as report_period_end,
  TIME_FORMAT(SEC_TO_TIME((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status')),'%Hh %im') as report_period_duration
from 
  information_schema.GLOBAL_STATUS 
where 
  VARIABLE_NAME in ('Com_select', 'Com_delete', 'Com_update', 'Com_insert');

样本输出:

query_type total_count per_second per_minute per_hour per_day report_period_start report_period_end   report_period_duration
DELETE               0          0          0       0        0 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
INSERT           36595       0.09          5     320     7672 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
SELECT        14842019      36.02       2161  129656  3111738 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
UPDATE          189137       0.46         28    1652    39654 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.