统计时间分布脚本(mysql)
2013-11-21 11:17
316 查看
-- 查询超时记录 select * from visit_record t where t.accesstime>to_date('2013-09-1','yyyy-MM-dd') and t.username is not null and t.result='成功' and t.totaltimecost>5000 and t.clientip <> '192.168.112.53' and t.clientip <> '192.168.112.200' and t.clientip <> '192.168.112.245' order by t.totaltimecost desc ; -- 导出日期范围内的日志信息(已xml格式导出为stat.xml,使用navicat工具导入进stat表) select t.username,t.accesstime,t.totaltimecost,t.accessurl from visit_record t where t.accesstime>to_date('2013-09-1','yyyy-MM-dd') and t.username is not null and t.result='成功' and t.clientip <> '192.168.112.53' and t.clientip <> '192.168.112.200' and t.clientip <> '192.168.112.245' and (t.accessurl='/newOA/m_flow/navPage.do' or t.accessurl='/newOA/m_commWorkflow/submitNode_2p0.do' or t.accessurl='/newOA/user/showDaiBanxiangJsp.do' or t.accessurl='/newOA/user/showDaiBanXiangList.do' ) order by t.totaltimecost desc ; -- 统计超时率(myql库中) select t.ACCESSURL as url ,COUNT(t.ACCESSURL) as 发生次数 ,COUNT(IF(t.TOTALTIMECOST>5000,t.TOTALTIMECOST,null)) as 超时次数 ,COUNT(IF(t.TOTALTIMECOST>5000,t.TOTALTIMECOST,null))/COUNT(t.ACCESSURL) as 超时率 ,ROUND(avg(t.TOTALTIMECOST)) as 平均耗时 ,max(t.TOTALTIMECOST) as 最大耗时 from stat t group by t.ACCESSURL order by 平均耗时 desc; -- 时间分布(异常统计) select t.ACCESSURL as url ,COUNT(IF(t.TOTALTIMECOST>5000 ,t.TOTALTIMECOST,null)) as 超时次数 ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '09:00:00' and '10:00:00' ,t.TOTALTIMECOST,null)) as '9' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '10:00:00' and '11:00:00' ,t.TOTALTIMECOST,null)) as '10' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '11:00:00' and '12:00:00' ,t.TOTALTIMECOST,null)) as '11' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '12:00:00' and '13:00:00' ,t.TOTALTIMECOST,null)) as '12' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '13:00:00' and '14:00:00' ,t.TOTALTIMECOST,null)) as '13' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '14:00:00' and '15:00:00' ,t.TOTALTIMECOST,null)) as '14' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '15:00:00' and '16:00:00' ,t.TOTALTIMECOST,null)) as '15' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '16:00:00' and '17:00:00' ,t.TOTALTIMECOST,null)) as '16' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '17:00:00' and '18:00:00' ,t.TOTALTIMECOST,null)) as '17' from stat t group by t.ACCESSURL with ROLLUP; select t.ACCESSURL as url ,COUNT(t.ACCESSURL) as 发生次数 ,COUNT(IF( time(t.ACCESSTIME) between '09:00:00' and '10:00:00' ,t.TOTALTIMECOST,null)) as '9' ,COUNT(IF( time(t.ACCESSTIME) between '10:00:00' and '11:00:00' ,t.TOTALTIMECOST,null)) as '10' ,COUNT(IF( time(t.ACCESSTIME) between '11:00:00' and '12:00:00' ,t.TOTALTIMECOST,null)) as '11' ,COUNT(IF( time(t.ACCESSTIME) between '12:00:00' and '13:00:00' ,t.TOTALTIMECOST,null)) as '12' ,COUNT(IF( time(t.ACCESSTIME) between '13:00:00' and '14:00:00' ,t.TOTALTIMECOST,null)) as '13' ,COUNT(IF( time(t.ACCESSTIME) between '14:00:00' and '15:00:00' ,t.TOTALTIMECOST,null)) as '14' ,COUNT(IF( time(t.ACCESSTIME) between '15:00:00' and '16:00:00' ,t.TOTALTIMECOST,null)) as '15' ,COUNT(IF( time(t.ACCESSTIME) between '16:00:00' and '17:00:00' ,t.TOTALTIMECOST,null)) as '16' ,COUNT(IF( time(t.ACCESSTIME) between '17:00:00' and '18:00:00' ,t.TOTALTIMECOST,null)) as '17' from stat t group by t.ACCESSURL with ROLLUP; -- 日期分布(正常统计) select t.ACCESSURL as url ,COUNT(t.ACCESSURL) as 发生次数 ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=0 ,t.ACCESSTIME,null)) as '星期1' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=1 ,t.ACCESSTIME,null)) as '星期2' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=2 ,t.ACCESSTIME,null)) as '星期3' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=3 ,t.ACCESSTIME,null)) as '星期4' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=4 ,t.ACCESSTIME,null)) as '星期5' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=5 ,t.ACCESSTIME,null)) as '星期6' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=6 ,t.ACCESSTIME,null)) as '日' from stat t group by t.ACCESSURL select t.ACCESSURL as url ,COUNT(t.ACCESSURL) as 发生次数 ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=0 ,t.ACCESSTIME,null)) as '星期1' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=1 ,t.ACCESSTIME,null)) as '星期2' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=2 ,t.ACCESSTIME,null)) as '星期3' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=3 ,t.ACCESSTIME,null)) as '星期4' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=4 ,t.ACCESSTIME,null)) as '星期5' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=5 ,t.ACCESSTIME,null)) as '星期6' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=6 ,t.ACCESSTIME,null)) as '日' from stat t group by t.ACCESSURL
相关文章推荐
- 利用perl脚本取回MySQL记录的insert时间
- MySQL实时统计脚本--计算QPS,TPS和线程连接数等
- MySQL实时统计脚本--计算QPS,TPS和线程连接数等
- cpu-hogs 的 systemtap 工具,可以实时统计某段时间内实际消耗掉的 CPU 时间在所有用户进程及内核线程之间的比例分布。
- Mysql 根据时间戳按年月日分组统计(做个收藏)
- 【转】Mysql 根据时间戳按年月日分组统计
- mysql date_format 按不同时间单位进行分组统计
- Mysql 根据时间戳按年月日分组统计
- Mysql,Mybatis做时间过滤报表:日周月统计
- mysql 慢查询统计分析脚本
- 服务器时间和时区错误引起的mysql数据统计出错
- 求一个论坛的在线人数,假设有一个论坛,其注册ID有两亿个,每个ID从登陆到退出会向一个日志文件中记下登陆时间和退出时间,要求写一个算法统计一天中论坛的用户在线分布,取样粒度为秒。
- python数据统计脚本实例mysql,redis
- MySQL,PHP语法,函数的不同使用举例时间戳和分类统计
- MySQL 时间差、每15分钟统计一次数据
- mysql-qps统计python脚本(每秒查询处理量)
- MySQL 按时间统计数据
- 解决:shell脚本中,无法执行time命令,以统计某个程序执行时间
- 一段linux上统计平均响应时间的awk脚本
- MySQL实时统计脚本--计算QPS,TPS和线程连接数等