bash load/sql monitor

Discussion in 'Programming/Scripts' started by mark verduffelt, Oct 18, 2016.

  1. mark verduffelt

    mark verduffelt New Member

    Hi,
    Because my server has often a high load of 80+, i want to see what query's are running out all the resources.
    I was writing a bash file to see when the load is higher then 10 mail me the actually mysql processes but it doesn't work, can someone help me please? I have a problem with mysqlproc (if i tree in the commandline : alias mysqlproc='. /usr/local/directadmin/conf/mysql.conf; mysqladmin -u $user --password=$passwd processlist' and then set mysqlproc , i get want I want)

    #!/bin/bash
    mysqlproc='. /usr/local/directadmin/conf/mysql.conf; mysqladmin -u $user --password=$passwd processlist'
    trigger=10.00
    load=`cat /proc/loadavg | awk '{print $1}'`
    response=`echo | awk -v T=$trigger -v L=$load 'BEGIN{if ( L > T){ print "greater"}}'`
    if [[ $response = "greater" ]]
    then
    sar -q | mail -s"High load on server - [ $load ] [ $mysqlproc]" markverduffelt[aaat]and....com
    fi
    echo $load
    echo $mysqlproc
     

Share This Page