Prometheus+Grafana监控MySQL - Go语言中文社区

Prometheus+Grafana监控MySQL


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. 监控效果图
    监控效果图

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

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq292913477/article/details/85625242
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2019-08-27 15:08:34
  • 阅读 ( 2157 )
  • 分类:数据库

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢