prometheus+grafana 对于现在这个时间点来说,相信很多同行都应该已经开始玩起来了,当仍然可能有一部分人可能还不知道prometheus+grafana 的存在,也可能还有一部分人虽然知道它的存在,但却懒于动手,如果是这样,那后面的内容你可得打起精神来了,因为可能你会被grafana炫酷的视觉效果惊艳到。

让我们一起了解一下吧。

首先,简单介绍下prometheus+grafana 这对鸳鸯到底是什么:

prometheus 是由 SoundCloud 开发的开源监控报警系统和时序列数据库(TSDB),prometheus是一个监控采集与数据存储框架(监控server端),具体采集什么数据依赖于具体的exporter(监控client端),例如:采集MySQL的数据需要使用到mysql_exporter,prometheus调用mysql_expoter采集到mysql的监控指标之后,把mysql_exporter采集到的数据存放到prometheus所在服务器的磁盘数据文件中保存。它的各个组件基本都是用 golang 编写,对编译和部署十分友好.并且没有特殊依赖,基本都是独立工作。以下是prometheus架构图(图片来源:https://prometheus.io/docs/introduction/overview/)

grafana是一个高颜值的监控绘图程序,也是一个可视化面板(Dashboard),grafana的厉害之处除了高颜值,还支持多种数据源(支持Graphite、zabbix、InfluxDB、Prometheus和OpenTSDB作为数据源)、支持灵活丰富的dashboard配置选项(例如:可以把多个实例的相同采集项配置在一个展示框里),使得相较于其他开源监控系统来说更易用性,学习成本更低。从视觉上来说,比以往的任何开源的监控系统都看起来要养眼很多,下面先看两张监控效果图:

相信审美还算正常的人都不会说上面两张图很丑吧,那么问题来了,我们该如何玩起来呢?下面就简单为大家介绍如何快速搭建起来!

这里方便演示过程,我们准备了如下两台测试服务器prometheus+grafana server端主机:10.10.30.165

MySQL 客户端主机:10.10.20.14

1、安装prometheus

1.1. 下载安装包

对于prometheus,假设我们需要监控MySQL,那么我们需要下载至少3个组件,如下:prometheus程序包

node_exporter:监控主机磁盘、内存、CPU等硬件性能指标的采集程序包

mysql_exporter: 监控mysql各种性能指标的采集程序包下载prometheus下载node_exporter下载mysqld_exporterPS:如果你还需要配置监控告警,需要下载alertmanager程序包

1.2. 解压程序包

解压prometheus

[root@localhost ~]# mkdir /data

[root@localhost ~]# tar xvf prometheus-2.1.0.linux-amd64.tar.gz -C /data/

解压exporter:由于prometheus主机自身也需要监控,所以也至少需要解压node_exporter包

[root@localhost ~]# tar xf node_exporter-0.15.2.linux-amd64.tar -C /root/

# 如果需要监控mysql,则继续解压mysql_exporter

[root@localhost ~]# tar xf mysqld_exporter-0.10.0.linux-amd64.tar -C /root/

1.3. 启动prometheus

进入prometheus的工作目录

[root@localhost ~]# cd /data/

[root@localhost data]# mv prometheus-2.1.0.linux-amd64/ prometheus

[root@localhost ~]# cd /data/prometheus

配置 prometheus.yml配置文件

[root@localhost data]# 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:- file_sd_configs:- files:- host.ymljob_name: Hostmetrics_path: /metricsrelabel_configs:- source_labels: [__address__]regex: (.*)target_label: instancereplacement: $1- source_labels: [__address__]regex: (.*)target_label: __address__replacement: $1:9100- file_sd_configs:files:- mysql.ymljob_name: MySQLmetrics_path: /metricsrelabel_configs:- source_labels: [__address__]regex: (.*)target_label: instancereplacement: $1- source_labels: [__address__]regex: (.*)target_label: __address__replacement: $1:9104- job_name: prometheusstatic_configs:- targets:- localhost:9090

启动prometheus进程,30d表示prometheus只保留30天以内的数据

[root@localhost prometheus]# /data/prometheus/prometheus --storage.tsdb.retention=30d &

如果是7.x系统,可以按照如下方式配置service启动脚本

# 修改WorkingDirectory参数为你的prometheus的工作目录

[root@localhost prometheus]# cat /usr/lib/systemd/system/prometheus.service

[Unit]

Description=Prometheus instance

Wants=network-online.target

After=network-online.target

After=postgresql.service mariadb.service mysql.service

[Service]

User=root

Group=root

Type=simple

Restart=on-failure

WorkingDirectory=/data/prometheus/

RuntimeDirectory=prometheus

RuntimeDirectoryMode=0750

ExecStart=/data/prometheus/prometheus --storage.tsdb.retention=30d --config.file=/data/prometheus/prometheus.ymlLimitNOFILE=10000

TimeoutStopSec=20

[Install]

WantedBy=multi-user.target

PS:prometheus默认的web访问端口为9090,可以使用如下地址访问http://10.10.30.165:9090

2、安装grafana

前面说过,grafana是一个出图展示框架,grafana根据grafana-dashboards来进行展示,grafana-dashboards就类似于grafana的出图配置文件,根据在grafana-dashboards中的定义来确定在页面中需要展示什么指标,需要如何展示等,需要分别对这两个组件进行下载与安装。

2.1. 下载安装包

对于grafana来说,需要下载一个程序包,一个grafana-dashboards包

下载链接

2.2. 解压程序包

解压grafana

[root@localhost ~]# tar xf grafana-4.6.3.linux-x64.tar.gz -C /data/prometheus/

[root@localhost ~]# cd /data/prometheus

[root@localhost prometheus]# mv grafana-4.6.3/ grafana

2.3. 启动grafana

进入grafana工作目录,并启动

[root@localhost ]# cd /data/prometheus/grafana

[root@localhost ]# ./bin/grafana-server

如果是7.x系统,可以按照如下方式配置service启动脚本

[root@localhost service]# 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

After=postgresql.service mariadb.service mysql.service

[Service]

User=root

Group=root

Type=simple

Restart=on-failure

WorkingDirectory=/data/prometheus/grafana

RuntimeDirectory=grafana

RuntimeDirectoryMode=0750

ExecStart=/data/prometheus/grafana/bin/grafana-server

LimitNOFILE=10000

TimeoutStopSec=20

[Install]

WantedBy=multi-user.target

打开grafana页面(默认帐号和密码:admin/admin,默认的端口为3000,通过地址:http://10.10.30.165:3000 访问),配置数据来源。

指定prometheus地址,这里我们把grafana装在了同一台机器,直接使用127.0.0.1的地址配置即可,如下图

2.4. 在grafana中导入grafana-dashboards

解压grafana-dashboards包,该包中提供了大量的json格式文件的grafana dashboards,根据需要自行选择,我们这里需要监控主机和MySQL,就选择如下一些json文件。

[root@localhost ~]# tar xvf grafana-dashboards-1.6.1.tar.gz

[root@localhost ~]# cd grafana-dashboards-1.6.1

[root@localhost grafana-dashboards-1.6.1]# updatedb

[root@localhost grafana-dashboards-1.6.1]# locate json |grep dashboards/

............

/root/grafana-dashboards-1.6.1/dashboards/CPU_Utilization_Details_Cores.json

/root/grafana-dashboards-1.6.1/dashboards/Disk_Performance.json

/root/grafana-dashboards-1.6.1/dashboards/Disk_Space.json

............

/root/grafana-dashboards-1.6.1/dashboards/MySQL_InnoDB_Metrics.json

/root/grafana-dashboards-1.6.1/dashboards/MySQL_InnoDB_Metrics_Advanced.json

............

/root/grafana-dashboards-1.6.1/dashboards/MySQL_Overview.json

/root/grafana-dashboards-1.6.1/dashboards/MySQL_Performance_Schema.json

............

/root/grafana-dashboards-1.6.1/dashboards/MySQL_Replication.json

/root/grafana-dashboards-1.6.1/dashboards/MySQL_Table_Statistics.json

............

/root/grafana-dashboards-1.6.1/dashboards/Summary_Dashboard.json

/root/grafana-dashboards-1.6.1/dashboards/System_Overview.json

............

在grafana页面中,导入需要的json文件

在弹出的窗口中选择你需要导入的json文件

然后,如果你的grafana中已经添加过主机,此时,就可以看到相应的json dashboard监控数据

至此,prometheus+grafana的基础架构(server端)已经搭建好了,现在,你可以去给他们添加监控节点了(client端)

3、监控节点部署

3.1. 添加主机监控

以添加prometheus主机(10.10.30.165)为例进行说明

解压exporter压缩包

[root@localhost ~]# tar xf node_exporter-0.15.2.linux-amd64.tar

[root@localhost ~]# mv node_exporter-0.15.2.linux-amd64 node_exporter

启动node_exporter程序

[root@localhost ~]# cd node_exporter

[root@localhost node_exporter]# nohup ./node_exporter &

配置prometheus主机监控配置列表文件,由于之前主配置文件prometheus.yml 中已经定义了监控主机的配置文件host.yml,这里只需要把主机IP信息填入即可动态生效

[root@localhost node_exporter]# cat /data/prometheus/host.yml

- labels:

service: test

targets:

- 10.10.30.165

然后,在grafana页面中就可以看到你配置的主机

PS:如果该文件中已经配置过lables且不需要使用独立的service标签进行标记,则新添加的实例的IP可以直接放在同一个targets下,如下:

[root@localhost mysqld_exporter]# cat /data/prometheus/host.yml

- labels:

service: test

targets:

- 10.10.30.165

- 10.10.20.14

3.2. 添加MySQL监控

添加MySQL监控主机,这里以添加10.10.20.14为例进行说明

解压exporter压缩包

[root@localhost ~]# tar xf mysqld_exporter-0.10.0.linux-amd64.tar

[root@localhost ~]# mv mysqld_exporter-0.10.0.linux-amd64 mysqld_exporter

配置监控数据库需要的主机IP、数据库端口、数据库账号和密码的环境变量(注意:该账号需要单独创建,需要对所有库所有表至少具有PROCESS, REPLICATION CLIENT, SELECT权限)

[root@luoxiaobo-01 ~]# export DATA_SOURCE_NAME='admin:password@(10.10.20.14:3306)/'

[root@luoxiaobo-01 ~]# echo "export DATA_SOURCE_NAME='admin:password@(10.10.20.14:3306)/'" >> /etc/profile

启动exporter

# 由于目前最新的版本默认关闭了大量的mysql采集项,需要显式使用相应的选项开启(截止到写稿时间,最新的开发版本可以通过prometheus端的配置项让exporter端生效,而无需再exporter中使用大量的启动选项开启)

[root@localhost ~]# cd mysqld_exporter

[root@localhost mysqld_exporter]# nohup ./mysqld_exporter --collect.info_schema.processlist --collect.info_schema.innodb_tablespaces --collect.info_schema.innodb_metrics --collect.perf_schema.tableiowaits --collect.perf_schema.indexiowaits --collect.perf_schema.tablelocks --collect.engine_innodb_status --collect.perf_schema.file_events --collect.info_schema.processlist --collect.binlog_size --collect.info_schema.clientstats --collect.perf_schema.eventswaits &

配置prometheus MySQL监控配置列表文件,由于之前主配置文件prometheus.yml 中已经定义了监控主机的配置文件mysql.yml,这里只需要把主机IP信息填入即可动态生效

[root@localhost mysqld_exporter]# cat /data/prometheus/host.yml

- labels:

service: test

targets:

- 10.10.30.165

- 10.10.20.14

然后,在grafana页面中就可以看到你配置的MySQL实例

PS:如果该文件中已经配置过lables且不需要使用独立的service标签进行标记,则新添加的实例的IP可以直接放在同一个targets下,如下:

[root@localhost mysqld_exporter]# cat /data/prometheus/mysql.yml

- labels:

service: test

targets:

- 10.10.30.165

- 10.10.20.14

3.3. grafana页面dashboard切换

根据需要切换监控模板

然后,就能看到你想要的数据

到这里,本文也接近尾声了,相信大家按照本文介绍的步骤操作一翻,已经一睹了grafana炫酷界面的芳容了,谢谢大家阅读!

| 作者简介

罗小波·沃趣科技高级数据库技术专家

IT从业多年,历任运维工程师,高级运维工程师,运维经理,数据库工程师,曾参与版本发布系统,轻量级监控系统,运维管理平台,数据库管理平台的设计与编写,熟悉MySQL的体系结构时,InnoDB存储引擎,喜好专研开源技术,追求完美。

口碑好的mysql数据监控平台_构建狂拽炫酷屌的 MySQL 监控平台相关推荐

  1. (升级版)构建狂拽炫酷屌的MySQL监控平台

    作者:罗小波,<千金良方--MySQL性能优化金字塔法则>作者之一. 熟悉MySQL体系结构,擅长数据库的整体调优,喜好专研开源技术,并热衷于开源技术的推广,在线上线下做过多次公开的数据库 ...

  2. 构建狂拽炫酷屌的 MySQL 监控平台

    prometheus+grafana 对于现在这个时间点来说,相信很多同行都应该已经开始玩起来了,当仍然可能有一部分人可能还不知道prometheus+grafana 的存在,也可能还有一部分人虽然知 ...

  3. 大数据不是你想有就能有,如何才能“狂拽炫酷吊炸天”

    如今,大数据正成为了各大企业都争相推拥的热词,其发展的如火如荼,迅疾如风,猛烈似火.从互联网领域的BAT到各类智能硬件,几乎所有的企业都正在谈大数据. 在这样一股大数据的洪流之下,专门做大数据分析的公 ...

  4. 打造炫酷的Proxmox VE 监控界面

    打造炫酷的Proxmox VE 监控界面 今天终于把Proxmox VE(简称PVE)从6.1版本升级到PVE 6.4版本,在Web管理后台对比PVE 6.4与 PVE 6.1,看新增哪些功能?在数据 ...

  5. 易语言mysql数据同步程序_易语言mssql和mysql数据自动同步源码

    易语言mssql和mysql数据自动同步源码 易语言mssql和mysql数据自动同步源码 系统结构:RefreshTask,ComputeEndTime,ComputeOneTime,Compute ...

  6. mysql 数据库命令大全_常用的MySQL数据库命令大全

    飞信2017V5.6.8860.0 官方正式版 类型:聊天其它大小:69.1M语言:中文 评分:9.6 标签: 立即下载 常用的MySQL命令大全 一.连接MySQL 格式: mysql -h主机地址 ...

  7. mysql数据存储方式_数据存储在mysql的两种方式

    数据存储在mysql的两种方式 发布时间:2020-05-12 16:16:25 来源:亿速云 阅读:250 作者:三月 下文主要给大家带来数据存储在mysql的两种方式,希望这些内容能够带给大家实际 ...

  8. nodejs mysql数据推送_使用Nodejs实现实时推送MySQL数据库最新信息到客户端

    下面我们要做的就是把MySQL这边一张表数据的更新实时的推送到客户端,比如MySQL这边表的数据abc变成123了,那使用程序就会把最新的123推送到每一个连接到服务器的客户端.如果服务器的连接的客户 ...

  9. mysql 数据增量抽取_通过Maxwell实时增量抽取MySQL binlog并通过stdout展示

    下载,解压Maxwell 修改MySQL的配置文件my.cnf [root@hadoop000 etc]# vi my.cnf [mysqld] server-id = 1binlog_format= ...

最新文章

  1. 设置Sysctl.conf用以提高Linux的性能(最完整的sysctl.conf优化方案)
  2. Anaconda 默认环境
  3. Spring3.0 AOP 详解
  4. 进程间通信--命名管道(fifo)
  5. [转载] 杜拉拉升职记——20 两位同僚
  6. Effective C++学习第一天
  7. OpenSSH 密钥管理:RSA/DSA 认证(转载)
  8. JS生成数字下拉列表
  9. 面对Mission Impossible,你会怎么做?
  10. 字符函数、字符串函数、内存函数用法及其模拟实现
  11. 03-es6语法 Promise 和 es8语法 async await 的了解和基本使用
  12. vscode配置python2和python3_VS Code中配置python版本以及Python多版本
  13. 8位十六进制转换32位十六进制_网络中的数制系统--二进制十六进制与十进制之间的相互转换...
  14. 数字证书是什么原理,有什么作用?
  15. 微信小程序地图实现多个位置标记marker
  16. 科学计算机sd mode使用方法,科学计算器使用方法
  17. ddqn玩flappybird
  18. oracle闪回空间满的原因,处理Oracle数据库闪回区空间满的问题
  19. selenium报错:find_element() argument after * must be an iterable, not bool
  20. 长沙理工大学教务管理系统模拟登陆

热门文章

  1. python50种算法_收藏 | 一文洞悉Python必备50种算法(附解析)
  2. 【zookeeper+Dubbo】Dubbo与SpringBoot整合的三种方式
  3. overflow encountered in exp
  4. python过滤后缀
  5. pytorch 过采样
  6. ImportError: dynamic module does not define module export function
  7. pytorch 测试 darknet
  8. Django 无法加载静态文件(js,css,image)解决办法
  9. 树莓派 ubuntu 安装Python+OpenCV
  10. python KeyError: 4