Use prometheus to count the remaining available percentage of MySQL auto-increment primary keys

Use prometheus to count the remaining available percentage of MySQL auto-increment primary keys

Recently, a database in the production environment wrote log data crazily, causing primary key value overflow, so it is necessary to monitor this indicator.

mysqld_exporter comes with this feature. Here are the startup parameters I use:

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 &

The parameters highlighted in red are used to collect the usage of the auto-increment ID.

The SQL actually executed is similar to this:

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; 

In the Prometheus web interface, we can test and write the following promql to find the library + table name of the instance with the remaining auto-increment ID rate less than 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

After obtaining the data, we can configure relevant alarms in the alertmanager, or draw a graph on grafana, as follows:

This is the end of this article about using prometheus to count the remaining available percentage of MySQL auto-increment primary keys. For more relevant prometheus statistics on MySQL auto-increment primary keys, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Use Grafana+Prometheus to monitor MySQL service performance
  • Detailed explanation of performance monitoring of MySQL server using Prometheus and Grafana
  • SpringBoot sample code using prometheus monitoring
  • Example of integrating prometheus monitoring with springboot2.X
  • Detailed steps for SpringBoot+Prometheus+Grafana to implement application monitoring and alarm
  • Detailed installation and configuration tutorial of Prometheus
  • Prometheus Getting Started Tutorial: SpringBoot Implements Custom Metrics Monitoring
  • Detailed explanation of the process of developing the middleware Exporter in Prometheus
  • How to integrate Prometheus with springboot
  • How to write custom indicators using the prometheus python library (complete code)
  • Detailed explanation of the tutorial on monitoring Springboot applications using Prometheus+Grafana
  • Prometheus monitors MySQL using grafana display

<<:  Detailed Explanation of JavaScript Framework Design Patterns

>>:  Modularity in Node.js, npm package manager explained

Recommend

MySQL5.7 master-slave configuration example analysis

MySQL5.7 master-slave configuration implementatio...

Vue parent component calls child component function implementation

Vue parent component calls the function of the ch...

How to forget the password of Jenkins in Linux

1.Jenkins installation steps: https://www.jb51.ne...

What to do after installing Ubuntu 20.04 (beginner's guide)

Ubuntu 20.04 has been released, bringing many new...

Four modes of Oracle opening and closing

>1 Start the database In the cmd command windo...

WeChat applet implements a simple dice game

This article shares the specific code of the WeCh...

Mysql | Detailed explanation of fuzzy query using wildcards (like,%,_)

Wildcard categories: %Percent wildcard: indicates...

Vue's guide to pitfalls using throttling functions

Preface In a common business scenario, we need to...

SQL implementation of LeetCode (196. Delete duplicate mailboxes)

[LeetCode] 196.Delete Duplicate Emails Write a SQ...

Detailed analysis of matching rules when Nginx processes requests

When nginx receives a request, it will first matc...

Linux uses NetworkManager to randomly generate your MAC address

Nowadays, whether you are on the sofa at home or ...

Alibaba Cloud Server Tomcat cannot be accessed

Table of contents 1. Introduction 2. Solution 2.1...

A brief discussion on the role of Vue3 defineComponent

Table of contents defineComponent overload functi...

CSS sets the box container (div) height to always be 100%

Preface Sometimes you need to keep the height of ...

Introduction to container data volumes in Docker

Table of contents Docker container data volume Us...