Prometheus(三)部署Mariadb数据库

1)安装数据库:

[root@localhost ~] yum -y install mariadb-server
[root@localhost ~] systemctl restart mariadb

2)创建数据库授权用户

[root@localhost ~] mysql
MariaDB [(none)]> create user 'mysqld_exporter'@'localhost' identified by '123456';
MariaDB [(none)]> grant process, replication client, select on *.* to 'mysqld_exporter'@'localhost';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> select Host,User from mysql.user;

3)安装mysqld_exporter

[root@localhost opt] ll
total 6956
-rw-r--r--. 1 root root 7121565 May 18  2020 mysqld_exporter-0.12.1.linux-amd64.tar.gz
[root@localhost opt] tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
[root@localhost opt] cp -r mysqld_exporter-0.12.1.linux-amd64 /usr/local/mysqld_exporter

4)配置数据库认证

[root@localhost ~] cd /usr/local/mysqld_exporter/
[root@localhost mysqld_exporter] vi .mysqld_exporter.cnf 
[client]
user=mysqld_exporter
password=123456

5)启动mysqld_exporter

[root@localhost mysqld_exporter] ./mysqld_exporter --config.my-cnf=".mysqld_exporter.cnf"
[root@localhost ~] netstat -tlunp|grep 9104
tcp6       0      0 :::9104          :::*              LISTEN      12070/./mysqld_expo

在这里插入图片描述
6)创建系统服务启动配置文件mysqld_exporter.service

[root@localhost ~] vi /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=Prometheus MySQL daemon
After=network.target

[Service]
User=root
Group=root
Type=simple
Restart=always
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter \
    --config.my-cnf=/usr/local/mysqld_exporter/.mysqld_exporter.cnf \
    --collect.global_status \
    --collect.auto_increment.columns \
    --collect.info_schema.processlist \
    --collect.binlog_size \
    --collect.info_schema.tablestats \
    --collect.global_variables \
    --collect.info_schema.innodb_metrics \
    --collect.info_schema.query_response_time \
    --collect.info_schema.userstats \
    --collect.info_schema.tables \
    --collect.perf_schema.tablelocks \
    --collect.perf_schema.file_events \
    --collect.perf_schema.eventswaits \
    --collect.perf_schema.indexiowaits \
    --collect.perf_schema.tableiowaits \
    --collect.slave_status \
    --web.listen-address=0.0.0.0:9104

[Install]
WantedBy=multi-user.target
[root@localhost ~] systemctl daemon-reload
[root@localhost ~] systemctl start mysqld_exporter

启动成功
在这里插入图片描述

7)与prometheus集成

[root@localhost ~] vi /usr/local/prometheus/prometheus.yml
  - job_name: 'mysqld_exporter'
    scrape_interval: 10s
    static_configs:
    - targets: ['192.168.1.20:9104']
#添加一个job
[root@localhost ~] systemctl restart prometheus

在这里插入图片描述
8)web测试
访问:http://IP:9090
1、查询吞吐量
监控任何系统时,我们的主要关注点是确保系统工作有效完成,数据库运行时完成大量的查询操作,所有监控优先级应该确保MySQL按照预期执行查询。MySQL有一个名为Questions的内部计数器,MySQL术语为“服务器状态变量”。对于客户端应用程序发送的所有语句,该计数器都是递增的。
MariaDB [(none)]> show global status like “Questions”;
±--------------±------+
| Variable_name | Value |
±--------------±------+
| Questions | 513 |
±--------------±------+
数学命令行:mysql_global_status_questions
在这里插入图片描述

2、查询执行性能
关于查询执行性能表现方面,可以使用MySQL提供的Slow_queries计数器,每当查询的执行时间超过long_query_time参数指定的秒数时,计数器就会增加。默认阀值为10秒。
MariaDB [(none)]> show global status like “Slow_queries”;
±--------------±------+
| Variable_name | Value |
±--------------±------+
| Slow_queries | 0 |
±--------------±------+
数学命令行:mysql_global_status_slow_queries

3、连接情况
为了防止MySQL服务器的过载运行,数据库管理员需要根据业务进行预评估,以便现在客户端连接MySQL的数量。可以在my.cnf文件中配置最大连接数max_connections=512。
MariaDB [(none)]> show variables like “max_connections”;
±----------------±------+
| Variable_name | Value |
±----------------±------+
| max_connections | 512 |
±----------------±------+
数学命令行:mysql_global_variables_max_connections
在这里插入图片描述

4、缓存池使用情况
当MySQL默认的存储引擎是InnoDB时,会使用缓存池来缓存表和索引的数据。可以在my.cnf中配置innodb_buffer_pool_size=128M。这是InnoDB最重要的参数,主要作用是缓存innodb表和索引、数据和插入数据,默认值为128M。
MariaDB [(none)]> show global status like “Innodb_buffer_pool_reads”;
±-------------------------±------+
| Variable_name | Value |
±-------------------------±------+
| Innodb_buffer_pool_reads | 144 |
±-------------------------±------+
数学命令行:mysql_global_status_innodb_buffer_pool_reads

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值