使用prometheus統(tǒng)計MySQL自增主鍵的剩余可用百分比
最近生產(chǎn)環(huán)境一套數(shù)據(jù)庫因為瘋狂寫日志數(shù)據(jù),造成主鍵值溢出的情況出現(xiàn),因此有必要將這個指標監(jiān)控起來。
mysqld_exporter自帶的這個功能,下面是我使用的啟動參數(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ù),就是用來采集到自增id的使用情況的。
實際上執(zhí)行的類似這個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界面,我們可以測試編寫如下的promql, 找出剩余自增id可以率少于40%的實例的庫+表名
(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里面配置相關的告警,或者再grafana上面繪制圖,如下:
到此這篇關于使用prometheus統(tǒng)計MySQL自增主鍵的剩余可用百分比的文章就介紹到這了,更多相關prometheus統(tǒng)計MySQL自增主鍵內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
- 使用Grafana+Prometheus監(jiān)控mysql服務性能
- 利用Prometheus與Grafana對Mysql服務器的性能監(jiān)控詳解
- SpringBoot使用prometheus監(jiān)控的示例代碼
- springboot2.X整合prometheus監(jiān)控的實例講解
- SpringBoot+Prometheus+Grafana實現(xiàn)應用監(jiān)控和報警的詳細步驟
- Prometheus的安裝和配置教程詳解
- Prometheus 入門教程之SpringBoot 實現(xiàn)自定義指標監(jiān)控
- Prometheus開發(fā)中間件Exporter過程詳解
- springboot集成普羅米修斯(Prometheus)的方法
- 使用 prometheus python 庫編寫自定義指標的方法(完整代碼)
- 使用Prometheus+Grafana的方法監(jiān)控Springboot應用教程詳解
- Prometheus 監(jiān)控MySQL使用grafana展示
相關文章
MySQL 實現(xiàn)樹的遍歷詳解及簡單實現(xiàn)示例
這篇文章主要介紹了MySQL 實現(xiàn)樹的遍歷詳解及簡單實現(xiàn)示例的相關資料,這里提供了示例代碼及測試結(jié)果,需要的朋友可以參考下2017-01-01詳解MySQL用事件調(diào)度器Event Scheduler創(chuàng)建定時任務
事件調(diào)度器(Event Scheduler)是在MySQLv5.1.6中新增的一個功能,它相當于一個定時器,可以在指定的時間點執(zhí)行一條SQL語句或一個語句塊,也可以用于在固定間隔重復執(zhí)行。下面跟著小編一起來學習學習在MySQL中如何用事件調(diào)度器Event Scheduler創(chuàng)建定時任務2016-08-08