免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1532 | 回复: 0
打印 上一主题 下一主题

一些mysql dba变量监控小程序 [复制链接]

论坛徽章:
9
每日论坛发贴之星
日期:2016-01-04 06:20:00数据库技术版块每日发帖之星
日期:2016-01-04 06:20:00每日论坛发贴之星
日期:2016-01-04 06:20:00数据库技术版块每日发帖之星
日期:2016-01-04 06:20:00IT运维版块每日发帖之星
日期:2016-01-04 06:20:00IT运维版块每日发帖之星
日期:2016-01-04 06:20:00综合交流区版块每日发帖之星
日期:2016-01-04 06:20:00综合交流区版块每日发帖之星
日期:2016-01-04 06:20:00数据库技术版块每周发帖之星
日期:2016-03-07 16:30:25
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-27 21:21 |只看该作者 |倒序浏览

I’m
observing the process of most awesome SHOW commands being abolished,
destroyed and some weird information_schema tables are introduced
instead.
Say, even though you can select configuration variables using
@@syntax, you can’t do same for much more interesting to DBAs status
variables in any more interesting logic.
Apparently instead of doing
SHOW STATUS LIKE "questions"
one has to do this now (I’m being dramatic here, above hasn’t been
removed yet, but hasn’t been expanded for better usage either):
SELECT VARIABLE_NAME, VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_STATUS
WHERE VARIABLE_NAME="QUESTIONS"
Do note, those SQL standard followers will get caps-lock button swapped with space bar soon.
Of course, we, DBAs, know that one can simplify stuff by creating stored routines:
CREATE FUNCTION `gstatus`(v varchar(64)) returns varchar(1024)
return
( SELECT variable_value
  FROM information_schema.global_status
  where variable_name=v LIMIT 1
)
So we can do such simple things as:
mysql> select m.gstatus("questions");
+------------------------+
| m.gstatus("questions") |
+------------------------+
| 140                    |
+------------------------+
1 row in set (0.00 sec)
Of course, this leads to solution of one of most common DBA problems, how to get decent status variable values per time:
CREATE PROCEDURE m.report(in timer float)
begin
DROP TEMPORARY TABLE IF EXISTS status_old;
CREATE TEMPORARY TABLE status_old
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_STATUS;
SELECT SLEEP(timer) into @x;
SELECT
    s.variable_name status,
    (s.variable_value-o.variable_value)/timer value
FROM INFORMATION_SCHEMA.GLOBAL_STATUS s
    JOIN status_old o USING (variable_name)
WHERE s.variable_value>0;
DROP TEMPORARY TABLE status_old;
end
So, the “show me changes-per-second for values in last 0.5s” would look like this:
ysql> call m.report(0.5) //
+-----------------------------------+---------+
| status                            | value   |
+-----------------------------------+---------+
| ABORTED_CLIENTS                   |       0 |
| ABORTED_CONNECTS                  |       0 |
| BYTES_RECEIVED                    |  532662 |
| BYTES_SENT                        | 1140894 |
...
| QUERIES                           |    2884 |
| QUESTIONS                         |    2878 |
| SELECT_FULL_JOIN                  |       2 |
| SELECT_RANGE                      |     196 |
| SELECT_SCAN                       |     146 |
...
| THREADS_CACHED                    |      12 |
| THREADS_CONNECTED                 |     -28 |
| THREADS_CREATED                   |       4 |
| THREADS_RUNNING                   |      -2 |
| UPTIME                            |       2 |
| UPTIME_SINCE_FLUSH_STATUS         |       2 |
+-----------------------------------+---------+
125 rows in set (0.53 sec)
Query OK, 0 rows affected, 1 warning (0.54 sec)
So, by spending five minutes on writing very simple
INFORMATION_SCHEMA procedure we can resolve one of usual nightmares in
MySQL DBA environments.
I can get back now to the initial idea of this post – if one DBA can
write such small neat thing in few minutes, would you imagine how
useful can a collaboratively built repository of DBA-assisting stored
procedures in functions, and how we can spit at all the SQL standard
verbosity, and make our systems easy to manage? :) I think we shouldn’t
allow not to share such utilities, as widespread use and “expect it
already there” would make overall work much much easier. Let’s use and
reuse (and someone should set up framework for building such thing ;-))
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/90603/showart_2039031.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP