centos搭建prometheus+配置exporter+使用grafana实现监控

tech2022-12-06  87

1.prometheus搭建

1)下载: 下载地址:https://prometheus.io/download/ 选择prometheus,linux-amd64复制链接地址wget即可。 2)解压 3)启动 日志滚完后见到“Server is ready to receive web requests.”且无报错信息则prometheus启动成功。 4)验证 浏览器输入ip+port(默认端口9090)验证。web页面成功加载则启动成功。

2.安装mysql-exporter

prometheus-exporter实质上是一个符合prometheus数据模型的接口,其负责采集某业务的监控数据并将监控数据暴露出来供prometheus抓取。 1)下载 下载地址:https://prometheus.io/download/ 选择mysqld_exporter,linux-amd64复制链接地址wget即可。 2)解压 3)设置监控mysql的地址 mysql_exporter通过环境变量来获取mysql地址,因此设置如下环境变量:

export DATA_SOURCE_NAME="username:password@tcp(xx.xx.xx.xx:3306)/"

4)启动 日志滚完,见到“Listening on :9104”且无其它报错信息则启动成功。 关于修改启动端口等其它启动参数设置,请参考官方文档:https://github.com/prometheus/mysqld_exporter

5)修改prometheus配置文件并重新启动prometheus 在解压后的prometheus文件夹找到prometheus.yml并编辑: 在prometheus.yml中添加自己的exporter,其中: job_name自己随便起就可以。static_configs中的targets是一个数组,加入自己的exporter即可,mysql_exporter的默认端口为9104,在此加入。prometheus会默认定时去targets下的/metrics接口拉取监控数据。 接下来重启prometheus即可。 6)验证 同样打开prometheus的web界面,点击上方导航条中的status->targets,看到自己的exporter且state处于up状态则证明配置成功。 也可去graph处查看下上面配置的mysql监控,以select命令执行数量为例:

3.grafana搭建

grafana提供了多种安装方式,具体安装方式请见:https://grafana.com/grafana/download 本教程以yum为例: 1)下载 2)安装 3)启动 4)验证 浏览器输入ip+port(默认端口3000)验证即可。默认用户名和密码为admin、admin

4.在grafana配置prometheus

1)添加prometheus数据源 选择左侧导航按钮中的configuration按钮,之后选择data sources。 点击add data source后,选择prometheus数据源。 填入prometheus地址。 点击下方save&test后,出现绿色data source is working则配置没问题。 2)验证 选择左侧导航按钮的create,之后选择dashboard。 选择add panel后,在panel内选择prometheus数据源,输入查询语句即可出图。

超级战斗王 认证博客专家 Go/GoLang Spring 分布式 python,golang,java,c,IOS,Android,html,云计算,大数据,深度学习,机器学习,图像识别,vue
最新回复(0)