我正在调查从 MySQL 到 NoSQL DBaaS 的大转变,但在尝试预测费用时遇到了问题。从本质上讲,我无法弄清楚我当前的 MySQL 服务器每天处理多少查询来尝试估计我将与Cloudant一起使用的请求数量,每 100 个 PUT、POST 和 DELETE 收费 0.015 美元,每 500 个 GET 收费 0.015 美元和头。
我发现了很多关于使用SHOW STATUS和SHOW GLOBAL STATUS来获取 MySQL 自己收集的统计信息的信息,但没有时间框架参考。
例如,SHOW GLOBAL STATUS 返回以下内容:
Queries | 13576675
Run Code Online (Sandbox Code Playgroud)
这很好,除了我不知道包含该数字的时间范围。什么时候有 1300 万次查询?每月?年?自古以来?
MySQL 文档并没有详细说明太多:
查询
服务器执行的语句数。与 Questions 变量不同,此变量包括在存储程序中执行的语句。它不计算 COM_PING 或 COM_STATISTICS 命令。这个变量是在 MySQL 5.0.76 中添加的。
在此先感谢您的帮助。
Max*_*eul 20
对于选择:
show global status like "Com_select";
Run Code Online (Sandbox Code Playgroud)
更新:
show global status like "Com_update";
Run Code Online (Sandbox Code Playgroud)
插入:
show global status like "Com_insert";
Run Code Online (Sandbox Code Playgroud)
删除:
show global status like "Com_delete";
Run Code Online (Sandbox Code Playgroud)
自 MySQL 上次重新启动以来,所有值都是“累积”。
因此,要在一小时内获得您的选择:
晚上 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)
Run Code Online (Sandbox Code Playgroud)
晚上 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)
Run Code Online (Sandbox Code Playgroud)
过去一小时 SELECT 的次数:672363 - 671664 = 699
此致
小智 12
我使用这个视图来关注每秒、每分钟、每小时和每天的查询数量:
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');
Run Code Online (Sandbox Code Playgroud)
示例输出:
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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19403 次 |
最近记录: |