日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

mysql常见监控项

發(fā)布時(shí)間:2023/12/9 数据库 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql常见监控项 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

 1、MySQL服務(wù)運(yùn)行狀態(tài)

約定所有MySQL服務(wù)都必須以ip1(內(nèi)網(wǎng)ip)來(lái)綁定,每個(gè)機(jī)器只有一個(gè)ip1,可以有多個(gè)端口,即多個(gè)MySQL Server。采集程序讀取ip端口信息文件來(lái)判斷server是否存在。

sockParam=`ps aux | grep -P "mysqld.*--port=${port}" | grep -oP " --socket.*\.sock"`? # 空則獲取不到該服務(wù)器端口mysql socket配置,請(qǐng)檢查mysql配置是否正確
MYSQL="/usr/local/mysql/bin/mysql -hlocalhost --port=${port} ${sockParam} -u${user} -p${password} "
MYSQL_ADMIN="/usr/local/mysql/bin/mysqladmin -hlocalhost --port=${port} ${sockParam} -u${user} -p${password} "
curStatus=`${MYSQL} -e"show global status"`? # 空則是獲取不到該服務(wù)器mysql狀態(tài),請(qǐng)檢查mysql是否正常運(yùn)行
if [ -z "${curStatus}" ]
then
? ? portExists=0
else
? ? echo "${curStatus}" >> ${curFile}
? ? portExists=1

  2、連接數(shù)

${MYSQL_ADMIN} processlist -v | wc -l

  3、線程數(shù)

grep 'Threads_connected' ${curFile} | awk '{print $2}'

  4、慢查詢數(shù)

grep 'Slow_queries' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值,等于最近1分鐘的慢查詢次數(shù)。上次數(shù)據(jù)保存在last.cache。

  5、打開表數(shù)

grep 'Open_tables' ${curFile} | awk -F ' ' '{print $2}'

  6、每秒執(zhí)行select數(shù)

grep 'Com_select' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量。上次數(shù)據(jù)保存在last.cache。  

  7、每秒執(zhí)行delete數(shù)

grep 'Com_delete' ${curFile} | grep -v 'multi' | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量。上次數(shù)據(jù)保存在last.cache。

  8、每秒執(zhí)行insert數(shù)

grep 'Com_insert' ${curFile} | grep -v 'select' | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量。上次數(shù)據(jù)保存在last.cache。

  9、每秒執(zhí)行update數(shù)

grep 'Com_update' ${curFile} | grep -v 'multi' | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量。上次數(shù)據(jù)保存在last.cache。

  10、每秒鐘執(zhí)行replace數(shù)

grep 'Com_replace' ${curFile} | grep -v 'select' | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量。上次數(shù)據(jù)保存在last.cache。 

  11、每秒鐘執(zhí)行的 Innodb_rows_deleted

grep 'Innodb_rows_deleted' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量。上次數(shù)據(jù)保存在last.cache。  

  12、每秒鐘執(zhí)行的 Innodb_rows_inserted

grep 'Innodb_rows_inserted' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量。上次數(shù)據(jù)保存在last.cache。  

  13、每秒鐘執(zhí)行的 Innodb_rows_read

grep 'Innodb_rows_read' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量。上次數(shù)據(jù)保存在last.cache。

  14、每秒鐘執(zhí)行的 Innodb_rows_updated

grep 'Innodb_rows_updated' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量。上次數(shù)據(jù)保存在last.cache。

  15、每秒鐘執(zhí)行的 innodb rows total

expr ${innodbRowsDeletedPS} + ${innodbRowsInsertedPS} + ${innodbRowsReadPS} + ${innodbRowsUpdatedPS}

等于前面四個(gè)Innodb_rows_*執(zhí)行次數(shù)的總和

  16、每秒處理命令數(shù) qps

expr ${mysqlSelectNumPS} + ${mysqlInsertNumPS} + ${mysqlUpdateNumPS} + ${mysqlDeleteNumPS} + ${mysqlReplaceNumPS}

等于前面五個(gè)mysql命令Com_*的數(shù)量總和

  17、每秒接收字節(jié)數(shù) KByte/s

grep 'Bytes_received' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量,除以1024得到單位KByte/s。上次數(shù)據(jù)保存在last.cache。

  18、每秒發(fā)送字節(jié)數(shù)

grep 'Bytes_sent' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值除以時(shí)間差,等于最近1分鐘的執(zhí)行數(shù)量,除以1024得到單位KByte/s。上次數(shù)據(jù)保存在last.cache。

  19、可立即獲得鎖的次數(shù)

grep 'Table_locks_immediate' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值,等于最近1分鐘的可立即獲得鎖數(shù)量。上次數(shù)據(jù)保存在last.cache。

  20、不可立即獲得鎖的次數(shù)

grep 'Table_locks_waited' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值,等于最近1分鐘的不可立即獲得鎖數(shù)量。上次數(shù)據(jù)保存在last.cache。

  21、一行鎖定需等待時(shí)間

grep 'Innodb_row_lock_waits' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值,等于最近1分鐘的一行鎖定需等待時(shí)間。上次數(shù)據(jù)保存在last.cache。

  22、 當(dāng)前臟頁(yè)數(shù)

grep 'Innodb_buffer_pool_pages_dirty' ${curFile} | awk -F ' ' '{print $2}'

  23、要求清空的緩沖池頁(yè)數(shù)

grep 'Innodb_buffer_pool_pages_flushed' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值,等于最近1分鐘的要求清空的緩沖池頁(yè)數(shù)。上次數(shù)據(jù)保存在last.cache。

  24、Innodb 寫入日志字節(jié)數(shù) KByte

grep 'Innodb_os_log_written' ${curFile} | awk -F ' ' '{print $2}'

需要計(jì)算兩次的慢查詢次數(shù)得到差值,等于最近1分鐘的寫入日志字節(jié)數(shù),除以1024得到KByte。上次數(shù)據(jù)保存在last.cache。

  25、占用內(nèi)存大小 MByte

pid=`ps aux | grep 'mysqld' | grep -Ev 'safe|grep' | awk '{print $2}' `
mem=`cat /proc/${pid}/status | grep 'VmRSS' | awk '{print $2}'`
mysqlMem=`echo "scale=2;${mem} / 1024" | bc`

除以1024得到MByte

  26、handler socket每秒處理數(shù)

curHsTableLock=`grep 'Hs_table_lock' ${curFile} | awk '{print $2}'`
preHsTableLock=`grep 'Hs_table_lock' ${preFile} | awk '{print $2}'`
if [ -n "${curHsTableLock}" ]
then
? ? hsQPS=`echo "scale=0;(${curHsTableLock} - ${preHsTableLock}) / ${intervalTime}" | bc`
else
? ? hsQPS=0
fi

  27、主從同步和狀態(tài)

#主從信息
#是否為從服務(wù)器
slave_running=`grep 'Slave_running' ${curFile} | awk '{print $2}'`
if [ "${slave_running}A" = "ONA" ]
then
? ? slaveRunning=1
? ? slaveStatus=`${MYSQL} -e'show slave status\G'`
? ? echo "${slaveStatus}" > ${slaveFile}
? ??
? ? slaveIoRunning=`grep 'Slave_IO_Running' ${slaveFile} | awk -F ':' '{print $2}'`
? ? slaveSqlRunning=`grep 'Slave_SQL_Running' ${slaveFile} | awk -F ':' '{print $2}'`

? ? if [ "${slaveIoRunning}A" == "NoA" -o "${slaveSqlRunning}A" == "NoA" ]
? ? then
? ? ? ? slaveRunning=3
? ? fi
? ??
? ? secondsBehindMaster=`grep 'Seconds_Behind_Master' ${slaveFile} | awk -F ':' '{print $2}'`
? ? if [ "${secondsBehindMaster}A" = "NULLA" ]
? ? then
? ? ? ? secondsBehindMaster=8888? # 表示主從不同步
? ? fi

? ? #是從庫(kù)時(shí) 獲取主庫(kù)ip
? ? master=`grep 'Master_Host' ${slaveFile} | awk -F ':' '{print $2}'`
? ? masterPort=`grep 'Master_Port' ${slaveFile} | awk -F ':' '{print $2}'`
else
? ? master=""
? ? masterPort=""
? ? slaveRunning=0
? ? secondsBehindMaster=10000? # 不用檢測(cè)
fi

注:Seconds_Behind_Master,該值作為判斷主從延時(shí)的指標(biāo),那么它又是怎么得到這個(gè)值的呢,同時(shí),它為什么又受到很多人 的質(zhì)疑?

Seconds_Behind_Master是通過(guò)比較sql_thread執(zhí)行的event的timestamp和io_thread復(fù)制好的 event的timestamp(簡(jiǎn)寫為ts)進(jìn)行比較,而得到的這么一個(gè)差值。我們都知道的relay-log和主庫(kù)的bin-log里面的內(nèi)容完全一樣,在記錄sql語(yǔ)句的同時(shí)會(huì)被記錄上當(dāng)時(shí)的ts,所以比較參考的值來(lái)自于binlog,其實(shí)主從沒(méi)有必要與NTP進(jìn)行同步,也就是說(shuō)無(wú)需保證主從時(shí)鐘的 一致。你也會(huì)發(fā)現(xiàn),其實(shí)比較真正是發(fā)生在io_thread與sql_thread之間,而io_thread才真正與主庫(kù)有關(guān)聯(lián),于是,問(wèn)題就出來(lái)了, 當(dāng)主庫(kù)I/O負(fù)載很大或是網(wǎng)絡(luò)阻塞,io_thread不能及時(shí)復(fù)制binlog(沒(méi)有中斷,也在復(fù)制),而sql_thread一直都能跟上 io_thread的腳本,這時(shí)Seconds_Behind_Master的值是0,也就是我們認(rèn)為的無(wú)延時(shí),但是,實(shí)際上不是,你懂得。這也就是為什 么大家要批判用這個(gè)參數(shù)來(lái)監(jiān)控?cái)?shù)據(jù)庫(kù)是否發(fā)生延時(shí)不準(zhǔn)的原因,但是這個(gè)值并不是總是不準(zhǔn),如果當(dāng)io_thread與master網(wǎng)絡(luò)很好的情況下,那么 該值也是很有價(jià)值的。

之前,提到 Seconds_Behind_Master這個(gè)參數(shù)會(huì)有負(fù)值出現(xiàn),我們已經(jīng)知道該值是io_thread的最近跟新的ts與sql_thread執(zhí)行到 的ts差值,前者始終是大于后者的,唯一的肯能就是某個(gè)event的ts發(fā)生了錯(cuò)誤,比之前的小了,那么當(dāng)這種情況發(fā)生時(shí),負(fù)值出現(xiàn)就成為可能。

  28、檢測(cè)采集Agent心跳情況

轉(zhuǎn)載于:https://www.cnblogs.com/cyt1153/p/6608069.html

總結(jié)

以上是生活随笔為你收集整理的mysql常见监控项的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。