Metrics,Prometheus监控
1.Metics
Metrics收集器从服务端收集数据,查询引擎会统计流量和时间,在Dashboard中显示。
2.Prometheus
Prometheus收集数据,交给Granfana显示,或者将警告发给微信。
3.启动eureka导入示例项目actuatordemo,并运行
项目中做监控需要添加promrtheus依赖,并添加启动类方法
这里监控的数据会发到promrtheus数据库,设定actuator-demo标签。
demo启动后访问8080端口
访问prometheus会返回监控数据
4.安装Prometheus
拷贝prometheus.yml到prometheus根目录中(yml中已经配置好了三个端点)
配置文件yml
5秒收集一次刚demo运行的项目
5.Dos下执行prometueus.exe
访问9090端口
6.查看prometheus中的status为up
7.查看prometheus具体监控指标
用jemeter发送请求
选择count
当前指标为30
jmeter连接成功后,进行压测
可观察到如下变化
但是这样只能观察一个指标不太方面,工作中使用grafana
7.安装grafana。安装完后默认会启动。端口号为3000。登录用户名密码为admin
添加数据源
选择prometheus
输入需要监控微服务的prometheus的端口,不是项目启动端口,这里是9090
导入仪表盘模板
模板地址官网提供
https://grafana.com/fdashboards
例如搜索boot
找下载量最高的 copyid
如何使用,监控信息都会在下面有描述
然后在prometheus上点击加号“+”输入id
选择放设置的数据源
结果如图
利用此方法可以发现问题,然后利用链路跟踪来解决问题。