当前位置: 首页 > 后端技术 > Java

普罗米修斯监控mysql

时间:2023-04-01 18:42:52 Java

Prometheus监控mysql本文主要介绍如何使用Prometheus监控mysql1。安装配置mariadb1.1安装mariadb#简单点直接yuminstallmariadbyum-yinstallmariadbmariadb-serversystemctlstartmariadb#启动mariadbsystemctlenablemariadb#设置开机自启动mysql_secure_installation#设置root密码等相关mysql-uroot-proot123#测试登录1.2配置mariadb为exporter创建用户#创建mysql_monitor用户并授予权限mysql>grantselect,replicationclient,processON*.*to'mysql_monitor'@'localhost'identifiedby'mysql123';#Refreshconfigurationmysql>flushprivileges;mysql>quit2.mysqld_exporter安装配置2.1下载mysqld_exporter地址:https://prometheus.io/downloa...#解压tar文件到/usr/localtar-zxvfmysqld_exporter-0.14.0.linux-arm64.tar.gz-C/usr/local#重命名mvmysqld_exporter-0.14.0.linux-arm64/mysqld_exporter2.2配置mysql账户信息vi/usr/local/mysqld_exporter/.my.cnf#根据具体填写以下内容情况是上面创建的mysql账号[client]user=mysql_monitorpassword=mysql123我把.my.cnf的配置放在mysqld_exporter下2.3启动mysqld_exporter通过./mysqld_exporter-h可以看到在帮助文档中可以找到的配置方法指定cnf文件#--config.my-cnf指定的my-cnf文件所在位置就是我们上面创建的/mysqld_exporter--config.my-cnf=/usr/local/mysqld_exporter/.my.cnf启动成功:2.4访问mysqld_exporter的指标默认9104端口我访问这里:http://172.16.225.110:9104/me...,可以看到指标都出来了3.Prometheus配置mysqld_exporter配置mysqld_exporter后,还可以看到收集到的指标,可以去Prometheus配置拉取,修改Prometheusyml文件添加如下job-job_name:'mysqld_agent'static_configs:-targets:["172.16.225.110:9104"]#Restart./prometheus--配置文件=普罗米修斯。yml登录Prometheus查看Status/Targets,可以看到mysqld_agent作业已经处于up状态4.验证查询指标mysql线程连接数查询mysql_global_status_threads_connected指标第一次只有一个连接,这个连接就是连接mysqld_exporter,然后打开终端连接mysql,稍等片刻,再次查询将是2个线程。小结本文主要介绍Promethues如何监控mysql,详细分析mysqld_exporter的使用方法,以及Prometheus如何配置访问。最近需要补充一下运维平台监控相关的知识。欢迎大家访问个人博客JohnnyHut欢迎关注个人公众号