最近生產(chǎn)環(huán)境一套數(shù)據(jù)庫(kù)因?yàn)榀偪駥?xiě)日志數(shù)據(jù),造成主鍵值溢出的情況出現(xiàn),因此有必要將這個(gè)指標(biāo)監(jiān)控起來(lái)。
mysqld_exporter自帶的這個(gè)功能,下面是我使用的啟動(dòng)參數(shù):
nohup ./mysqld_exporter --config.my-cnf="./my.cnf" --web.listen-address=":9104" --collect.heartbeat --collect.auto_increment.columns --collect.binlog_size --collect.engine_innodb_status --collect.engine_tokudb_status --collect.slave_hosts --collect.slave_status --collect.info_schema.processlist --collect.info_schema.innodb_metrics > /dev/null 2>1
紅色高亮的參數(shù),就是用來(lái)采集到自增id的使用情況的。
實(shí)際上執(zhí)行的類(lèi)似這個(gè)SQL:
SELECT table_schema, table_name, column_name, AUTO_INCREMENT, POW(2, CASE data_type WHEN 'tinyint' THEN 7 WHEN 'smallint' THEN 15 WHEN 'mediumint' THEN 23 WHEN 'int' THEN 31 WHEN 'bigint' THEN 63 END+(column_type LIKE '% unsigned'))-1 AS max_int FROM information_schema.tables t JOIN information_schema.columns c USING (table_schema,table_name) WHERE c.extra = 'auto_increment' AND t.TABLE_SCHEMA NOT IN ('information_schema','mysql', 'sys','test','performance_schema') AND t.auto_increment IS NOT NULL ;
在prometheus的web界面,我們可以測(cè)試編寫(xiě)如下的promql, 找出剩余自增id可以率少于40%的實(shí)例的庫(kù)+表名
(mysql_info_schema_auto_increment_column_max{schema!~'test|mysql'} - mysql_info_schema_auto_increment_column{schema!~'test|mysql'})/mysql_info_schema_auto_increment_column_max{schema!~'test|mysql'}*100 40
取到數(shù)據(jù)后,我們可以在alertmanager里面配置相關(guān)的告警,或者再grafana上面繪制圖,如下:
到此這篇關(guān)于使用prometheus統(tǒng)計(jì)MySQL自增主鍵的剩余可用百分比的文章就介紹到這了,更多相關(guān)prometheus統(tǒng)計(jì)MySQL自增主鍵內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
標(biāo)簽:秦皇島 白銀 定西 澳門(mén) 寧夏 恩施 益陽(yáng) 杭州
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《使用prometheus統(tǒng)計(jì)MySQL自增主鍵的剩余可用百分比》,本文關(guān)鍵詞 使用,prometheus,統(tǒng)計(jì),MySQL,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。