Prometheus+Grafana监控MySQL

7 篇文章 0 订阅
5 篇文章 0 订阅

Prometheus

Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的。

安装使用

  1. 下载安装( https://prometheus.io/download/
$ cd /usr/local
$ wget https://github.com/prometheus/prometheus/releases/download/v2.6.0/prometheus-2.6.0.linux-amd64.tar.gz
$ tar xvf prometheus-2.6.0.linux-amd64.tar.gz
$ mv prometheus-2.6.0.linux-amd64 prometheus
  1. 修改配置,scrape_configs部分如下(IP自行替换,注意YAML格式)
$ cd /usr/local/prometheus/
$ vim prometheus.yml
scrape_configs:
 - job_name: 'prometheus'
   static_configs:
   - targets: ['192.168.10.66:9090']

 - job_name: 'linux'
   static_configs:
   - targets: ['192.168.10.66:9100']
     labels:
       instance: db1

 - job_name: 'mysql'
   static_configs:
     - targets: ['192.168.10.66:9104']
       labels:
         instance: db1
  1. 启动
$ ./prometheus --config.file=prometheus.yml
  1. 访问
    浏览器访问http://monitor_host:9090,出现以下界面则表示安装成功
    Prometheus

exporter

Status->Targets页面下,可以看到配置的两个Target的State为DOWN
exporter

安装node_exporter

$ wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.14.0.linux-amd64.tar.gz
$ tar xvf node_exporter-0.14.0.linux-amd64.tar.gz /usr/local/
$ nohup /usr/local/node_exporter-0.14.0.linux-amd64/node_exporter &

安装mysqld_exporter

下载解压

$ wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz
$ tar xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz /usr/local/

由于mysqld_exporter需要连接到MySQL,创建用户并赋予所需的权限

mysql> GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'mysql_monitor'@'localhost' identified by 'mysql_monitor';
mysql> GRANT SELECT ON *.* TO 'mysql_monitor'@'localhost';

创建.my.cnf配置文件

$ vim /usr/local/mysqld_exporter-0.10.0.linux-amd64/.my.cnf

[client]
user=mysql_monitor
password=mysql_monitor

运行

$ nohup /usr/local/mysqld_exporter-0.10.0.linux-amd64/mysqld_exporter --config.my-cnf="/usr/local/mysqld_exporter-0.10.0.linux-amd64/.my.cnf" &

再刷新Status->Targets页面,可以看到配置的两个Target的State为UP:
exporter

Grafana

安装使用

  1. 下载安装
$ wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.0.1-1.x86_64.rpm 
$ sudo yum localinstall grafana-5.0.1-1.x86_64.rpm -y
  1. 启动服务
$ systemctl daemon-reload
$ systemctl start grafana-server
$ systemctl status grafana-server
  1. 访问
    浏览器访问http://monitor_host:3000,出现Grafana界面则表示安装成功(默认帐号/密码为admin/admin):
    Grafana

  2. 配置Data Resources
    登录成功,并点击左侧边栏进入Configuration->Data Resources配置数据源如下:
    Data Resources

  3. 导入Dashboards

1.可在Grafana官网自行选择dashboards:https://grafana.com/dashboards
2.本文使用的是percona提供的dashboards:https://github.com/percona/grafana-dashboards/tree/master/dashboards

点击左侧边栏进入Create->Import导入Dashboards:

导入System_Overview.json(https://github.com/percona/grafana-dashboards/blob/master/dashboards/System_Overview.json)

导入MySQL_Overview.json(https://github.com/percona/grafana-dashboards/blob/master/dashboards/MySQL_Overview.json)

  1. 监控效果图
    监控效果图

以上为个人安装总结,如有问题欢迎指出!

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值