Grafana+Prometheus 监控 MySQL
转自:Grafana+Prometheus 监控 MySQL
架构图

环境
| IP | 环境 | 需装软件 | 
|---|---|---|
| 192.168.0.237 | mysql-5.7.20 | node_exporter-0.15.2.linux-amd64.tar.gz  mysqld_exporter-0.10.0.linux-amd64.tar.gz  | 
| 192.168.0.248 | grafana+prometheus | prometheus-2.1.0.linux-amd64.tar.gz  node_exporter-0.15.2.linux-amd64.tar.gz grafana-4.6.3.linux-x64.tar.gz  | 
在 192.168.0.248 上安装 grafana prometheus
安装 prometheus
# 创建保存软件的目录
mkdir /data/software/ -p
cd /data/software/
# 解压 prometheus
tar xvf prometheus-2.1.0.linux-amd64.tar.gz -C /iba/
cd /iba/
mv prometheus-2.1.0.linux-amd64 prometheus
cd prometheus/
cp prometheus.yml /tmp/prometheus.yml.20181203
# 配置 prometheus.yml
cat prometheus.yml
# my global config
global:
  scrape_interval:    15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: 'Host'
  file_sd_configs:
  - files:
    - host.yml
  metrics_path: /metrics
  relabel_configs:
  - source_labels: [__address__]
    regex: (.*)
    target_label: instance
    replacement: $1
  - source_labels: [__address__]
    regex: (.*)
    target_label: __address__
    replacement: $1:9100
- job_name: 'MySQL'
  file_sd_configs:
  - files:
    - mysql.yml
  metrics_path: /metrics
  relabel_configs:
  - source_labels: [__address__]
    regex: (.*)
    target_label: instance
    replacement: $1
  - source_labels: [__address__]
    regex: (.*)
    target_label: __address__
    replacement: $1:9104
- job_name: 'prometheus'
  static_configs:
  - targets:
    - localhost:9090
cat host.yml
- labels:
    service: test
  targets:
  - 192.168.0.248
  - 192.168.0.237
cat mysql.yml
- labels:
    service: test
  targets:
  - 192.168.0.237
# 测试 prometheus 是否可以正常启动
/iba/prometheus/prometheus --storage.tsdb.retention=30d &
ps -ef|grep prometh
kill -9 14650
# 配置 prometheus.service 文件
vi /usr/lib/systemd/system/prometheus.service
# 内容为
[Unit]
Description=Prometheus instance
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
Restart=on-failure
WorkingDirectory=/iba/prometheus/
RuntimeDirectory=prometheus
RuntimeDirectoryMode=0750
ExecStart=/iba/prometheus/prometheus  --storage.tsdb.retention=30d --config.file=/iba/prometheus/prometheus.yml
LimitNOFILE=10000
TimeoutStopSec=20
[Install]
WantedBy=multi-user.target
# 启动 prometheus
systemctl start prometheus
systemctl status prometheus -l
# 开放防火墙
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" accept"
firewall-cmd --reload
浏览器输入 http://192.168.0.248:9090 访问

prometheus.yml 文件参考:
https://prometheus.io/docs/prometheus/latest/configuration/configuration/
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Crelabel_config%3E
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Cfile_sd_config%3E
安装 node_exporter 获取主机信息
# 解压 node_exporter
cd /data/software/
tar xf node_exporter-0.15.2.linux-amd64.tar.gz -C /usr/local
mv node_exporter-0.15.2.linux-amd64 node_exporter
nohup ./node_exporter &
安装 grafana
cd /iba/software
# 解压
tar xf grafana-4.6.3.linux-x64.tar.gz -C /iba/prometheus/
cd /iba/prometheus/
mv grafana-4.6.3 grafana
cd grafana/
# 测试
./bin/grafana-server 
# 停止
ctrl+c
cat /usr/lib/systemd/system/grafana-server.service
[Unit]
Description=Grafana instance
Documentation=http://docs.grafana.org
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
Restart=on-failure
WorkingDirectory=/iba/prometheus/grafana
RuntimeDirectory=grafana
RuntimeDirectoryMode=0750
ExecStart=/iba/prometheus/grafana/bin/grafana-server
LimitNOFILE=10000
TimeoutStopSec=20
[Install]
WantedBy=multi-user.target
# 启动
systemctl start grafana-server
systemctl status grafana-server -l
访问 http://192.168.0.248:3000,默认用户和密码是 admin/admin

配置数据源


下载 grafana-dashboards-1.6.1.tar.gz,解压,使用浏览器导入 dashboard, 下载地址:https://github.com/percona/grafana-dashboards/archive/v1.6.1.tar.gz




在 192.168.0.237 安装 node_exporter 和 mysqld_exporter
cd /iba/software/
tar zxf node_exporter-0.15.2.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-0.15.2.linux-amd64 node_exporter
# 启动
cd node_exporter/
nohup ./node_exporter &
几分钟后 grafana 出现了新服务器的信息

在mysql上配置监控使用的用户
GRANT REPLICATION CLIENT, PROCESS, SELECT ON *.* TO 'mysql_monitor'@'%' IDENTIFIED BY 'mysql_monitor';
FLUSH PRIVILEGES;
cd /iba/software/
tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv mysqld_exporter-0.10.0.linux-amd64/ mysqld_exporter
cd mysqld_exporter/
# 在 mysql 上创建一个专门用于监控的用户,
cat .my.cnf
[client]
user=mysql_monitor
password=mysql_monitor
# 启动
nohup /usr/local/mysqld_exporter/mysqld_exporter  -config.my-cnf="/usr/local/mysqld_exporter/.my.cnf" &
导入 dashboard: MySQL_Overview.json

Grafana+Prometheus 监控 MySQL的更多相关文章
- 使用 Docker 部署 Grafana + Prometheus 监控 MySQL 数据库
		
一.背景 在平时开发过程当中需要针对 MySQL 数据库进行监控,这里我们可以使用 Grafana 和 Prometheus 来实现监控功能.Grafana 是一款功能强大的仪表盘面板,支持多种数据源 ...
 - Grafana+Prometheus监控mysql性能
		
#cmd /usr/local 今天讲一下如何监控服务器中的mysql数据库的性能 一.数据库操作 1.mysql启动 #service mysqld start #启动数据库 #service my ...
 - Prometheus 监控Mysql服务器及Grafana可视化
		
Prometheus 监控Mysql服务器及Grafana可视化. mysql_exporter:用于收集MySQL性能信息. 使用版本 mysqld_exporter 0.11.0 官方地址 使用文 ...
 - Grafan+Prometheus 监控 MySQL
		
架构图 环境 IP 环境 需装软件 192.168.0.237 mysql-5.7.20 node_exporter-0.15.2.linux-amd64.tar.gz mysqld_exporter ...
 - 采用prometheus 监控mysql
		
1. prometheus 是什么 开源的系统监控和报警工具,监控项目的流量.内存量.负载量等实时数据. 它通过直接或短时jobs中介收集监控数据,在本地存储所有收集到的数据,并且通过定义好的rule ...
 - Prometheus 监控MySQL
		
目录 0.简介 1.mysql_exporter部署 2.mysql报警规则 0.简介 文中主要监控MySQL/MySQL主从信息 版本:mysql-5.7,mysql_exporter-0.12.1 ...
 - 手把手教你使用 Prometheus 监控 MySQL 与 MariaDB.md
		
概述 MySQL 是常用的关系型数据库,MariaDB 作为 MySQL 的分支版本,兼容 MySQL 协议,也越来越流行.在 Kubernetes 环境中如何使用 Prometheus 来对它们进行 ...
 - Grafana + Prometheus 监控PostgreSQL
		
效果图 部署环境 服务器名称 IP地址 部署业务 备注 部署agent sht-sgmhadoopcm-01 172.16.101.54 PostgreSQL 监控服务器.被监控服务器 node_ex ...
 - Grafana+Prometheus监控
		
添加模板一定要看说明以及依赖 监控redis https://blog.52itstyle.com/archives/2049/ http://www.cnblogs.com/sfnz/p/65669 ...
 
随机推荐
- 《Java算法》判重算法-整数判重
			
判重算法-整数判重 /** * 判断大于1,小于63的整数是否出现重复数字. * * 算法逻辑:先获取8 根据移位(1 << arrInt[i]) 得到2进制数100000000 , * ...
 - 《Java基础知识》Java类的定义及其实例化
			
类必须先定义才能使用.类是创建对象的模板,创建对象也叫类的实例化. 下面通过一个简单的例子来理解Java中类的定义: public class Dog { String name; int age; ...
 - GHOST CMS - 配置 Config
			
Config For self-hosted Ghost users, a custom configuration file can be used to override Ghost's defa ...
 - C++生成完全二叉树
			
C++生成完全二叉树 2019-12-20 By Gauss 1.背景介绍 完全二叉树是效率很高的数据结构,完全二叉树是由满二叉树而引出来的.对于深度为K的,有n个结点的二叉树,当且仅当其每一个结点都 ...
 - wpf键盘
			
一.键盘类和键盘事件 WPF提供了基础的键盘类(System.Input.Keyboard类),该类提供与键盘相关的事件.方法和属性,这些事件.方法和属性提供有关键盘状态的信息.Keyboard的事件 ...
 - Cesium 限制相机进入地下
			
有时我们在Cesium操作时,点击鼠标中间滚轮可更改视角,有时会使相机进入地下,导致体验很差,网上说了很多中方法,效果都不好或者没效果,下面是我翻了源码找到的方法,亲测有效.如有问题可按照专栏上的联系 ...
 - Electron中使用sql.js操作SQLite数据库
			
推荐sql.js——一款纯js的sqlite工具. 一.关于sql.js sql.js(https://github.com/kripken/sql.js)通过使用Emscripten编译SQLite ...
 - ASP.NET Aries 高级开发教程:表单检测字段是否已存(番外篇)
			
前言: 昨天刚好有人问了这个问题,因此就针对这个问题,补上一篇吧. 正文: 如图:在用户编辑列表中,用户名是会自动检测是否已存在的. 具体对应的Html内容如下: <label><e ...
 - 【SVN搭建】搭建SVN服务
			
1.安装 # yum -y install subversion 2.配置 创建仓库 我们这里在/opt下建立一个名为svn的仓库(repository),所有代码都可以放在这个下面,创建成功后在sv ...
 - less 学习笔记
			
一.介绍 Less (Leaner Style Sheets 简洁的样式表) 是一门向后兼容的 CSS 预处理语言,它扩展了CSS 语言. less is more. 好处: 1.具有部分编程语言的功 ...