使用mysqld_exporter监控MySQL并展示数据

 

mysqld_exporter是Prometheus用于监控MySQL指标的一个导出器,支持对MySQL 5.5以上进行监控。用来抓取mysql的相关信息,下面是mysqld_exporter 安装的相关信息

环境: 192.168.31.40 MariaDB-5.5.68 mysqld_exporter_0.12.1

一、下载mysqld_exporter 并安装

官方网址:https://prometheus.io/download/

使用mysqld_exporter监控MySQL并展示数据

选择对应的版本下载

使用mysqld_exporter监控MySQL并展示数据

[root@node-1 ~]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz

#解压 ,移动到/usr/local 路径下 并从命名为 mysqld_exporter

[root@node-1 ~]# tar -xf mysqld_exporter-0.12.1.linux-amd64.tar.gz

[root@node-1 ~]# mv mysqld_exporter-0.12.1.linux-amd64 /usr/local/mysqld_exporter

二、登陆数据库,创建授权账户

[root@node-1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 278
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> grant PROCESS, REPLICATION CLIENT, SELECT on *.* to 'exporter'@'localhost' identified by 'fxkjnj';
MariaDB [(none)]> flush privileges;

#注意: 这里我只授权了本机登陆,因为 mysqld_exporter 也安装在数据库这台主机上

#退出验证,使用exporter 用户登陆数据库

 [root@node-1 ~]# mysql -uroot -p'fxkjnj'
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 286
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*A88C2B91E04CF458B1EFF3228824DEA7CE4ABA22' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> 

三、创建mysqld_exporter 的配置文件 my.cnf

[root@node-1 mysqld_exporter]# vim /usr/local/mysqld_exporter/my.cnf

[client]

host=192.168.31.40

port=3306

user=exporter

password=fxkjnj

四、创建mysql_exporter 启动文件,使用systemd 管理

[root@node-1 mysqld_exporter]# vim /etc/systemd/system/mysqld_exporter.service 
[Unit]
Description=mysqld_exporter
Documentation=mysqld_exporter-doc
 [Service]
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/my.cnf
 [Install]
WantedBy=multi-user.target

#初始化并启动mysqld_exporter

[root@node-1 mysqld_exporter]# systemctl daemon-reload

[root@node-1 mysqld_exporter]# systemctl start mysqld_exporter.service

#查看进程及端口

[root@node-1 ~]# ps -ef | grep mysqld_exporter | grep -v grep

root 60884 1 0 16:55 ? 00:00:02 /usr/local/mysqld_exporter/mysqld_exporter –config.my-cnf=/usr/local/mysqld_exporter/my.cnf

[root@node-1 ~]# netstat -ntlup | grep mysqld_export

tcp6 0 0 :::9104 :::* LISTEN 60884/mysqld_export

五、修改prometheus 配置文件 指定 mysqld_exporter 采集器地址

[root@prometheus ~]#vim /etc/prometheus/prometheus.yml

[root@prometheus ~]#vim /etc/prometheus/prometheus.yml
..............

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['192.168.31.250:9090']


  - job_name: 'mysql'
    static_configs:
    - targets: ['192.168.31.40:9104']

..............

#热加载prometheus

[root@prometheus ~]# ps -ef | grep prometheus | grep -v grep | awk ‘{print $2}’ | xargs kill -HUP

#登陆到prometheus 控制台,可以在status/targets 里看到 mysqld_exporter 采集器相关信息

使用mysqld_exporter监控MySQL并展示数据

点击 http://192.168.31.40:9104/metrics 可以看到相关数据

使用mysqld_exporter监控MySQL并展示数据

六、使用grafana 展示 mysqld_exporter 采集器采集的数据

PS: grafana 添加 prometheus 数据源 过程 省略。。。。。。。。。。

为了最终的效果,我们使用 Grafana 官网小伙伴提供的dashboard 来展示数据

模板地址: https://grafana.com/grafana/dashboards/7362 ID: 7362

使用mysqld_exporter监控MySQL并展示数据

点击 Download JSON , 下载完后 登陆Grafana ,默认地址 http://IP:3000

找到左侧 + 号,import 导入刚刚下载的json 文件

使用mysqld_exporter监控MySQL并展示数据

使用mysqld_exporter监控MySQL并展示数据

使用mysqld_exporter监控MySQL并展示数据

选择好数据源

稍等片刻,就可以看到 最终的效果

使用mysqld_exporter监控MySQL并展示数据

使用mysqld_exporter监控MySQL并展示数据

本篇只涉及到 使用mysqld_exporter 收集mysql 数据并展示 ,并没有写到 触发器的配置告警,这个等后面再更新

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/8203

(0)
杰斯的头像杰斯
上一篇 2023年5月19日 下午5:21
下一篇 2023年5月23日 下午4:28

相关推荐

  • Linux下查找并删除挖矿程序实例

    症状表现 从外网连接服务器时,间接性断开特别频繁。在断开的时候,从内网也连接不上 排查方法 从链路等硬件方面去排查 通过zabbix监控的服务器的端口,发现这个服务器一直在间断性占用1000M带宽,实际客户购买的带宽15M,这就是客户间断性频繁断网的原因。 在排除了线路等相关问题后,将问题锁定在客户系统内。 在软件中排查 在Linux系统中,我们可以使用to…

    2022年6月14日
    1.3K00
  • 使用netcat检测UDP端口是否开启

    一般我们使用tcping或者telnet检测目标IP的的TCP端口是否开放。但这两种工具对UDP端口无效。 Netcat是什么 NC(netcat)被称为网络工具中的瑞士军刀,体积小巧,但功能强大。 Nc主要功能 Nc可以在两台设备上面相互交互,即侦听模式/传输模式 可以使用的参数 其实常用的就几个参数-n,-v,-l,-p,-q

    2022年12月6日
    1.1K00
  • Linux安装青龙面板 稳定版超级详细

    一.安装docker容器 1.工具安装 复制所有代码然后直接右键粘贴进去 中间过程输入y 回车 yum install docker-io –y 这里输入y 安装成功之后是这个样子 输入以下代码回车 systemctl start docker 复制粘贴下面命令回车 docker ps 如果显示下图 即为成功 二.安装青龙面板 1.安装面板 (想改青龙面板端…

    2022年6月22日
    3.2K00
  • linux中为cp和mv命令添加进度条

    安装高级复制补丁以在 Linux 中向 cp 和 mv 命令添加进度条 cp 和 mv 命令是GNU coreutils. 所以你需要GNU coreutils从这里下载最新的。 现在两个新的补丁的二进制文件即cp与mv将在中创建coreutils-9.0/src的文件夹。只需将它们复制到你的 $PATH 中,如下所示: 该cpg和mvg命令有现在进度条的功…

    2023年6月16日
    97100
  • CentOS 7 磁盘挂载教程

    mount命令是经常会使用到的命令,它用于挂载Linux系统外的文件 进行挂载操作后,用户便可以在挂载目录中使用硬盘资源了。默认情况下Linux系统并不会像Windows系统那样自动的挂载光盘和U盘设备,需要自行完成。 语法 语法格式:mount [参数] [设备] [挂载点] 常用参数 -t 指定文件系统,即挂载类型 -l 显示已加载的文件系统列表 -h …

    2022年6月9日
    3.0K10

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信