zoukankan      html  css  js  c++  java
  • 脚本获取rds慢日志

    #!/bin/bash

    #慢日志开始时间
    stime='2019-03-05T00:01Z'
    #慢日志结束时间
    etime='2019-03-05T16:00Z'
    #页面大小
    pagenum=100
    #rds实例ID
    rds_id='rr-bp1487z0p4r345hra'

    function get_slows {
    python rds.py $1 $2 $3 $4
    }


    count=`get_slows "$stime" "$etime" 1 "$rds_id" |grep TotalRecordCount|awk -F' ' '{print $2}'`

    if [ "$count" == "0" ];then
    echo '没有慢日志~';exit
    fi

    pd=$(echo "scale=1;$count/"$pagenum""|bc)
    xs=$(echo $pd|cut -d'.' -f2)
    #总页数
    zs=$(echo $pd|cut -d'.' -f1)

    #判断计算总条数小于100时整数部分为0时,变量赋值为0
    if [ ! -n "$zs" ];then
    zs=0
    fi

    if [ "$xs" -gt 0 ];then
    zs=$((zs+1))
    fi

    #sql总量
    full_sql=$(echo `echo $stime|cut -d'T' -f1|sed -r 's#-#_#g'`_`echo $stime|cut -d'T' -f2|cut -d'Z' -f1|sed -r 's#:##g'`_`echo $etime|cut -d'T' -f1|sed -r 's#-#_#g'`_`echo $etime|cut -d'T' -f2|cut -d'Z' -f1|sed -r 's#:##g'`).sql

    for i in `seq $zs`;do

    get_slows "$stime" "$etime" "$i" "$rds_id">>/tmp/slow/$full_sql
    done

    #去重后sql
    uniq_sql=uniq_$full_sql
    grep SQLText /tmp/slow/"$full_sql"|sed -r 's#"SQLText": "##g'|sed 's/.$//'|sed 's/^ *//'|sed -r 's#\n##g' |sed -r 's#\##g'|sed -r 's#_[0-9]##g'|uniq -c|awk '{$1="";print $0}' >/tmp/slow/"$rds_id""$uniq_sql"
    sed -i 's/$/;/' /tmp/slow/"$rds_id""$uniq_sql"


    运行脚本结果
    [rdsuser@ansible ~]$ ls /tmp/slow/
    2019_03_05_1500_2019_03_06_1600.sql    uniq_2019_03_05_1500_2019_03_06_1600.sql

    打赏:

  • 相关阅读:
    (第九周)视频发布及git统计报告
    (第九周)团队项目16
    (第九周)团队项目15
    (第九周)团队项目14
    C# 中请求数据方式
    C#中Json和List/DataSet相互转换
    C#枚举注释实例
    C#常用简单线程实例
    C#动态多线程实例
    MySql中文乱码
  • 原文地址:https://www.cnblogs.com/hmysql/p/10628011.html
Copyright © 2011-2022 走看看