天天看点

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

1.prometheus搭建

1)下载:

下载地址:https://prometheus.io/download/

选择prometheus,linux-amd64复制链接地址wget即可。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

2)解压

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

3)启动

日志滚完后见到“Server is ready to receive web requests.”且无报错信息则prometheus启动成功。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

4)验证

浏览器输入ip+port(默认端口9090)验证。web页面成功加载则启动成功。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

2.安装mysql-exporter

prometheus-exporter实质上是一个符合prometheus数据模型的接口,其负责采集某业务的监控数据并将监控数据暴露出来供prometheus抓取。

1)下载

下载地址:https://prometheus.io/download/

选择mysqld_exporter,linux-amd64复制链接地址wget即可。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

2)解压

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

3)设置监控mysql的地址

mysql_exporter通过环境变量来获取mysql地址,因此设置如下环境变量:

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus
export DATA_SOURCE_NAME="username:[email protected](xx.xx.xx.xx:3306)/"
           

4)启动

日志滚完,见到“Listening on :9104”且无其它报错信息则启动成功。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

关于修改启动端口等其它启动参数设置,请参考官方文档:https://github.com/prometheus/mysqld_exporter

5)修改prometheus配置文件并重新启动prometheus

在解压后的prometheus文件夹找到prometheus.yml并编辑:

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus
centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

在prometheus.yml中添加自己的exporter,其中:

job_name自己随便起就可以。static_configs中的targets是一个数组,加入自己的exporter即可,mysql_exporter的默认端口为9104,在此加入。prometheus会默认定时去targets下的/metrics接口拉取监控数据。

接下来重启prometheus即可。

6)验证

同样打开prometheus的web界面,点击上方导航条中的status->targets,看到自己的exporter且state处于up状态则证明配置成功。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

也可去graph处查看下上面配置的mysql监控,以select命令执行数量为例:

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

3.grafana搭建

grafana提供了多种安装方式,具体安装方式请见:https://grafana.com/grafana/download

本教程以yum为例:

1)下载

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

2)安装

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

3)启动

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

4)验证

浏览器输入ip+port(默认端口3000)验证即可。默认用户名和密码为admin、admin

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

4.在grafana配置prometheus

1)添加prometheus数据源

选择左侧导航按钮中的configuration按钮,之后选择data sources。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

点击add data source后,选择prometheus数据源。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

填入prometheus地址。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

点击下方save&test后,出现绿色data source is working则配置没问题。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

2)验证

选择左侧导航按钮的create,之后选择dashboard。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus

选择add panel后,在panel内选择prometheus数据源,输入查询语句即可出图。

centos搭建prometheus+配置exporter+使用grafana实现监控1.prometheus搭建2.安装mysql-exporter3.grafana搭建4.在grafana配置prometheus