MySQL数据库之利用Prometheus和Grafana监控MySQL
小标 2019-05-13 来源 : 阅读 2540 评论 0

摘要:本文主要向大家介绍了MySQL数据库之利用Prometheus和Grafana监控MySQL,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。

本文主要向大家介绍了MySQL数据库之利用Prometheus和Grafana监控MySQL,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。

MySQL数据库之利用Prometheus和Grafana监控MySQL

 一、 Prometheus 是一个开源的服务监控系统和时间序列数据库。:

官方GitHub地址为:https://github.com/prometheus/prometheus

官方地址:https://prometheus.io/

官方拓扑图如下

MySQL数据库之利用Prometheus和Grafana监控MySQL

特性:

  • 高维度数据模型

  • 自定义查询语言

  • 可视化数据展示

  • 高效的存储策略

  • 易于运维

  • 提供各种客户端开发库

  • 警告和报警

  • 数据导出

二、安装Prometheus(服务器环境为Centos7.2,本实验服务端跟被监控MySQL在同一台服务器)

前提条件请关闭SELinux与Firewalld(centos6  为iptables)

下载安装prometheus
$ wget https://github.com/prometheus/prometheus/releases/download/v1.7.1/prometheus-1.7.1.linux-amd64.tar.gz
$ mkdir  /opt/prometheus
$ tar zxf prometheus-1.7.1.linux-amd64.tar.gz  -C /opt/prometheus --strip-components=1
编辑配置prometheus.yml文件,内容如下:
global:
  scrape_interval:     15s
  evaluation_interval: 15s
  external_labels:
      monitor: 'codelab-monitor'
rule_files:
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['192.168.1.199:9090']
  - job_name: linux
    static_configs:
      - targets: ['192.168.1.199:9100']
        labels:
          instance: db1
  - job_name: mysql
    static_configs:
      - targets: ['192.168.1.199:9104']
        labels:
          instance: db1

后台启动prometheus
 nohup /opt/prometheus/prometheus -config.file=prometheus.yml & 
tail -200f nohup.out 
time=""2017-06-12T11:51:16+08:00"" level=info msg=""Starting prometheus (version=1.7.0, branch=master, revision=bfa37c8ee39d11078662dce16c162a61dccf616c)"" source=""main.go:88"" 
time=""2017-06-12T11:51:16+08:00"" level=info msg=""Build context (go=go1.8.3, user=root@7a6329cc02bb, date=20170607-09:43:48)"" source=""main.go:89"" 
time=""2017-06-12T11:51:16+08:00"" level=info msg=""Host details (Linux 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 monitor (none))"" source=""main.go:90"" 
time=""2017-06-12T11:51:16+08:00"" level=info msg=""Loading configuration file prometheus.yml"" source=""main.go:252"" 
time=""2017-06-12T11:51:16+08:00"" level=info msg=""Loading series map and head chunks..."" source=""storage.go:428"" 
time=""2017-06-12T11:51:16+08:00"" level=info msg=""2200 series loaded."" source=""storage.go:439"" 
time=""2017-06-12T11:51:16+08:00"" level=info msg="" source=""web.go:259""
Prometheus提供一个内置的web界面。我们可以通过//192.168.1。199:9090访问

MySQL数据库之利用Prometheus和Grafana监控MySQL

在 Status -> Targets 页面下,我们可以看到我们配置的两个Target,它们的 State 

MySQL数据库之利用Prometheus和Grafana监控MySQL

三、接下来我们安装client客户端

1、安装client
$ wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.14.0.linux-amd64.tar.gz
$ wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz
$ mkdir /opt/prometheus_exporters
$ tar zxf node_exporter-0.14.0.linux-amd64.tar.gz -C /opt/prometheus_exporters --strip-components=1  && tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C /opt/prometheus_exporters --strip-components=1
2、启动os监控client
 nohup /opt/prometheus_exporters/node_exporter & 
tail -200f nohup.out 
time=""2017-06-12T11:28:52+08:00"" level=info msg="" - hwmon"" source=""node_exporter.go:162""
time=""2017-06-12T11:28:52+08:00"" level=info msg="" - netstat"" source=""node_exporter.go:162""
time=""2017-06-12T11:28:52+08:00"" level=info msg="" - stat"" source=""node_exporter.go:162""
time=""2017-06-12T11:28:52+08:00"" level=info msg="" - vmstat"" source=""node_exporter.go:162""
time=""2017-06-12T11:28:52+08:00"" level=info source=""node_exporter.go:186""
3、mysqld_exporter需要连接到MySQL,需要授权
mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'monitor'@'localhost' identified by 'test123';
mysql> GRANT SELECT ON performance_schema.* TO 'monitor'@'localhost';
4、创建 .my.cnf 文件并运行mysqld_exporter
[root@monitor prometheus_exporters]# cat .my.cnf 
[client]
user=monitor
password=test123
[root@monitor prometheus_exporters]# export DATA_SOURCE_NAME=""monitor:test123@(monitor:3306)/""
#####(monitor:3306)/此monitor为主机名
启动mysqld_exporter
nohup /opt/prometheus_exporters/mysqld_exporter -config.my-cnf="".my.cnf"" &
tail -200f nohup.out
time=""2017-06-12T11:30:07+08:00"" level=info msg=""Starting mysqld_exporter (version=0.10.0, branch=master, revision=80680068f15474f87847c8ee8f18a2939a26196a)"" source=""mysqld_exporter.go:460""
time=""2017-06-12T11:30:07+08:00"" level=info msg=""Build context (go=go1.8.1, user=root@3b0154cd9e8e, date=20170425-11:24:12)"" source=""mysqld_exporter.go:461""
time=""2017-06-12T11:30:08+08:00"" level=info msg="" source=""mysqld_exporter.go:479""

我们回到192.168.1.199:9090,可以看到

 Status -> Targets 页面

MySQL数据库之利用Prometheus和Grafana监控MySQL

四、安装和运行Grafana

1、安装Grafana
#wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.3.2-1.x86_64.rpm 
#yum localinstall grafana-4.3.2-1.x86_64.rpm 
替换grafana的dashboards
Grafana 并没有太多的配置好的图表模板,除了 Percona 开源的一些外,很多需要自行配置。
下载dashboards(https://github.com/percona/grafana-dashboards)
git clone https://github.com/percona/grafana-dashboards.git
cp -r grafana-dashboards/dashboards /var/lib/grafana/
2、编辑配置文件 /etc/grafana/grafana.ini ,修改 dashboards.json 段落下两个参数的值:
[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards
2、运行 Grafana
 systemctl start grafana-server
# [root@monitor prometheus_exporters]# ps aux |grep grafana
root      3211  0.0  0.0 112664   972 pts/1    S+   11:40   0:00 grep --color=auto grafana
grafana  21241  0.3  0.8 805720 39620 ?        Ssl  6月12   4:42 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile= cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins

我们可通过 //192.168.1.199:3000 访问Grafana网页界面(缺省的帐号/密码为admin/admin):

MySQL数据库之利用Prometheus和Grafana监控MySQL

登录并设置数据源

MySQL数据库之利用Prometheus和Grafana监控MySQL

MySQL数据库之利用Prometheus和Grafana监控MySQL

至此大功告成

我们可以看到os与数据库监控数据了

本文由职坐标整理并发布,希望对同学们学习MySQL有所帮助,更多内容请关注职坐标数据库MySQL数据库频道!

本文由职坐标整理并发布,希望对同学们学习MySQL有所帮助,更多内容请关注职坐标数据库MySQL数据库频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程