前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Prometheus+Grafana监控MySQL

Prometheus+Grafana监控MySQL

作者头像
拓荒者
发布2019-03-11 14:30:27
1.4K0
发布2019-03-11 14:30:27
举报
文章被收录于专栏:运维经验分享

首先安装GO

$ yum install go $  go version go1.6.3 linux/amd64

下载安装Prometheus(https://prometheus.io/download/) cd /data wget https://github.com/prometheus/prometheus/releases/download/v2.3.0/prometheus-2.3.0.linux-amd64.tar.gz tar -zxvf prometheus-2.3.0.linux-amd64.tar.gz  cd prometheus-2.3.0.linux-amd64 vi prometheus.yml

global:   scrape_interval:     60s   evaluation_interval: 60s scrape_configs:   - job_name: prometheus     static_configs:       - targets: ['192.168.1.211:9090']         labels:           instance: prometheus   - job_name: linux     static_configs:       - targets: ['10.10.0.186:9100']         labels:           instance: db1   - job_name: mysql     static_configs:       - targets: ['10.10.0.186:9104']         labels:           instance: db1

注意各个单词的开头位置

10.10.0.186是我们数据库主机的IP,端口则是对应的exporter的监听端口。

启动Prometheus

$ ./prometheus -config.file=prometheus.yml

INFO[0000] Starting prometheus (version=1.6.2, branch=master, revision=b38e977fd8cc2a0d13f47e7f0e17b82d1a908a9a)  source=main.go:88 INFO[0000] Build context (go=go1.8.1, user=root@c99d9d650cf4, date=20170511-12:59:13)  source=main.go:89 INFO[0000] Loading configuration file prometheus.yml     source=main.go:251 INFO[0000] Loading series map and head chunks...         source=storage.go:421 INFO[0000] 1032 series loaded.                           source=storage.go:432 INFO[0000] Starting target manager...                    source=targetmanager.go:61 INFO[0000] Listening on :9090                            source=web.go:259

Prometheus内置了一个web界面,我们可通过http://192.168.1.211:9090进行访问:

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

下一步我们需要安装并运行exporter,下载exporters并解压到被监控端服务器:

rometheus和Grafana对MySQL服务器性能进行监控。

我们用到了以下两个exporter:

node_exporter – 用于机器系统数据收集 mysqld_exporter – 用于MySQL服务器数据收集

cd /data

wget https://github.com/prometheus/node_exporter/releases/download/v0.15.2/node_exporter-0.15.2.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

被监控安装GO环境

$ yum install go -y $ go version go version go1.6.3 linux/amd64

##$ tar xvf node_exporter-0.15.2.linux-amd64.tar.gz -C /usr/local/

tar -zxvf node_exporter-0.15.2.linux-amd64.tar.gz $ nohup /data/mysqld_exporter-0.10.0.linux-amd64/node_exporter &

可以./node_exporte &

安装运行mysqld_exporter

mysqld_exporter需要连接到Mysql,所以需要Mysql的权限,我们先为它创建用户并赋予所需的权限.

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

$ tar -zxvf mysqld_exporter-0.10.0.linux-amd64.tar.gz

我们再次回到Status->Targets页面,可以看到两个Target的状态已经变成UP了:

创建.my.cnf文件并运行mysqld_exporter:

$ cat << EOF > .my.cnf [client] user=root password=Root@2018 EOF $ $ ./mysqld_exporter -config.my-cnf=".my.cnf"

###$ /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" & ./mysqld_exporter -config.my-cnf=".my.cnf" &

也可以 nohup /data/mysqld_exporter-0.10.0.linux-amd64/mysqld_exporter -config.my-cnf=".my.cnf" &

六、安装运行Grafana Grafana安装配置介绍 yum  sudo yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.3-1.x86_64.rpm rpm $ wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.3-1.x86_64.rpm $ sudo yum install initscripts fontconfig $ sudo rpm -Uvh grafana-5.1.3-1.x86_64.rpm

yum install fontconfig yum install freetype* yum install urw-fonts

导入Prometheus Dashboard:

$ git clone https://github.com/percona/grafana-dashboards.git $ cp -r grafana-dashboards/dashboards /var/lib/grafana

$ systemctl daemon-reload $ systemctl start grafana-server $ systemctl status grafana-server

sudo systemctl enable grafana-server.service

vi /etc/grafana/provisioning/dashboards/sample.yaml 第二行开始删掉注释 # # config file version apiVersion: 1

providers:  - name: 'default'    orgId: 1    folder: ''    type: file    options:      path: /var/lib/grafana/dashboards

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018/06/15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
Grafana 服务
Grafana 服务(TencentCloud Managed Service for Grafana,TCMG)是腾讯云基于社区广受欢迎的开源可视化项目 Grafana ,并与 Grafana Lab 合作开发的托管服务。TCMG 为您提供安全、免运维 Grafana 的能力,内建腾讯云多种数据源插件,如 Prometheus 监控服务、容器服务、日志服务 、Graphite 和 InfluxDB 等,最终实现数据的统一可视化。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档