Prometheus+Grafana实现服务性能监控:windows主机监控、Spring Boot监控、Spring Cloud Alibaba Seata监控
1、Prometheus介绍
Prometheus使用Go语言开发,中文名称叫:普罗 米修斯。Prometheus是一个开源系统最初在SoundCloud构建的监控和警报工具包。自 2012 年成立以来,许多公司和组织已经采用了 Prometheus,它现在是一个独立的开源项目并独立于任何公司进行维护。Prometheus于2016年加入云原生计算基金会作为继 Kubernetes之后的第二个托管项目。Prometheus主要用于抓取目标数据,并记录所有抓取的目标数据。
官网地址:
https://prometheus.io/
https://github.com/prometheus/prometheus
2、下载Prometheus并启动
官网下载:
https://prometheus.io/download/
Github下载:
https://github.com/prometheus/prometheus/releases
通过访问上面的地址,可以选择下载Prometheus的版本。这里选择下载windows版本:

下载成功后,解压压缩包,进入prometheus-2.44.0-rc.0.windows-386目录我们就可以启动程序了。
启动程序:prometheus.exe
程序启动成功后,访问端口9090进入系统:
http://localhost:9090/graph
成功进入系统后,我们可以访问Targets来查看接入的目标数据,由于我们还没有配置其他目标数据采集,目前只能检测到自己的信息:


3、安装可视化工具Grafana
通过上面启动Prometheus,会发现上面的展示信息都是数据而不是通过图表展示出来,这个看起来非常费力。所以需要通过第三方工具通过图表的方式用来把Prometheus收集的数据展现出来。
官网地址:
https://grafana.com/
进入官网后,可以在下载里面进行下载程序或者直接点击链接下载:
https://grafana.com/grafana/download?pg=get&plcmt=selfmanaged-box1-cta1
Github地址:
https://github.com/grafana/grafana
Github ChangeLog:
https://github.com/grafana/grafana/blob/main/CHANGELOG.md

选择版本和操作系统进行下载,下载成功后进入grafana文件里面进入/bin目录,启动程序:
启动程序:grafana-server.exe
等待窗口加载完毕,访问地址:http://localhost:3000 默认账号密码:admin/admin 就可以登录系统了,首次登录需要修改admin密码。

在grafana中添加数据源

点击添加数据源,选择Prometheus:

配置连接信息:

配置成功后点击保存,这样我们的数据源就配置成功了。
4、Grafana官网模板
在grafana中我们可以自己配置仪表盘展示信息也可以通过引入官方模板进行展示。模板地址:
https://grafana.com/grafana/dashboards/
记录一下常用模板信息:
模板编号ID:
9276:主机基础监控(cpu,内存,磁盘,网络)
12900:SpringBoot Dashboard
4701:JVM模板
10467:windows_exporter-Windows Server监控模板导入
11587:OhmGraphite-0.21.0-Ohm Windows Desktop
5、使用Prometheus+Grafana实现windows主机监控
要想监控windows系统,首先我们需要一个windows监控工具,然后把这个监控地址的连接集成到Prometheus中,最后在通过Grafana进行展示出来。这里介绍两个window监控工具
第一个windows_exporter下载地址:
https://github.com/prometheus-community/windows_exporter/releases
选择版本进行下载,下载windows运行程序就可以了,直接启动即可。启动完成端口为:9182,如果启动成功访问:http://localhost:9182/metrics 就可以以数据的格式展示出我们当前主机的配置信息。

接下来就需要把地址配入到Prometheus中,让Prometheus进行管理。进入Prometheus目录,修改Prometheus配置文件prometheus.yml并重新启动Prometheus

重新启动Prometheus后,再次查看Targets标签,发现windows_exporter接入成功,状态为 UP(正常)

最后我们就需要把数据通过Grafana以图表形式展现出来,首先登录我们安装成功的grafana系统,点击+号导入官方提供的模板。

输入模板ID:10467,点击Load:

选择数据源为Prometheus

点击导入,我们就可以查看到windows系统的配置信息

通过上面的步骤,我们就成功配置成功了一个监控信息了。下面介绍windows的另一个监控软件:OhmGraphite,下载地址:
https://github.com/nickbabcock/OhmGraphite/releases
需要下载压缩包文件,下载成功后进行解压。解压成功后需要进入OhmGraphite-0.21.0目录,编辑OhmGraphite.exe.config文件,增加prometheus作为接收数据源。支持Graphite、InfluxDB、Prometheus、Timescale / Postgres。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="host" value="localhost" />
<add key="port" value="2003" />
<add key="interval" value="5" />
<!--开启prometheus-->
<add key="type" value="prometheus" />
<add key="prometheus_port" value="4000" />
<add key="prometheus_host" value="*" />
</appSettings>
</configuration>

通过cmd命令行执行:
OhmGraphite.exe install
启动:
OhmGraphite.exe start
启动成功后访问:http://127.0.0.1:4000/metrics 就可以访问的监控数据。后面步骤就和第一次集成一致修改Prometheus配置文件在scrape_configs中添加新的路径,导入Grafana。导入模板ID:11587:OhmGraphite-0.21.0-Ohm Windows Desktop
#被监控端的配置,目前只有一个节点,就是prometheus本身
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "windows_exporter"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9182"]
- job_name: "windows_ohm_graphite"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:4000"]

6、SpringBoot监控
首先在SpringBoot项目中导入依赖
<!--prometheus 监控平台 集成micrometer,将监控数据存储到 prometheus-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!--监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
在配置文件bootstrap.yml或application.yml中加入配置暴露端点
#暴露端点
management:
endpoints:
web:
exposure:
include: '*'
配置成功后,启动项目访问地址:http://IP:PORT/actuator/prometheus
http://localhost:8810/actuator/prometheus
就可以查看到监控数据

数据获取成功后,后面就和原来的步骤一样了,修改Prometheus配置文件在scrape_configs中添加新的路径,导入Grafana。
- job_name: "spring-boot-order-8810"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
metrics_path: "/actuator/prometheus" #路径变了,记得要更改访问路径
static_configs:
- targets: ["localhost:8810"]
这里还是使用官方提供的模板,模板ID:12900:SpringBoot Dashboard

7、Spring Cloud Alibaba Seata事务监控
Seata支持在TC开启Metrics数据采集并输出到Prometheus监控系统中。默认是关闭状态,需要开启 metrics 的采集配置。进入\seata\conf,修改或新增metrics
## metrics configuration, only used in server side
metrics {
enabled = true
registryType = "compact"
# multi exporters use comma divided
exporterList = "prometheus"
exporterPrometheusPort = 9898
registry-type: compact
}
修改成功后,重新启动seata。输入http://IP:9898/metrics,即可获得最新的Metrics数据
http://localhost:9898/metrics
修改Prometheus配置文件添加seata:

查看Targets

在Grafana中点击新建控制台,添加seata信息:

选择数据源

搜索seata_transactional

点击Run queries查询,就可以成功获取seata信息数据

获取成功保存图表即可。我们点击图表下面的颜色标签,也可以查看不同状态下seata事务的使用情况以及事务提交状况。好了,本次关于Prometheus+Grafana的学习就到这里,以后如果会遇到其他使用情况也会做相关的记录,方便以后再次遇到相同的问题时再次快速查找。最后感谢阅读本篇的读友,让我们一起成长、共同进步。
Prometheus+Grafana实现服务性能监控:windows主机监控、Spring Boot监控、Spring Cloud Alibaba Seata监控的更多相关文章
- zabbix监控windows主机网卡流量
监控windows主机网卡流量 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入:高级运维工程师之路 598432640 客户端配置:(172.30.1.120,wi ...
- Cacti监控Windows主机,Windows主机的正确配置
使用cacti监控Windows主机的时候经常遇到无法获取Windows主机的snmp信息和Windows主机的硬件信息,主要原因是Windows主机没有正确配置snmp,以下是正确的配置步骤:1.安 ...
- nagios系列(八)之nagios通过nsclient监控windows主机
nagios通过nsclient监控windows主机 1.下载NSClient -0.3.8-Win32.rar安装在需要被监控的windows主机中 可以设置密码,此处密码留空 2.通过在nagi ...
- 基于Spring Boot、Spring Cloud、Docker的微服务系统架构实践
由于最近公司业务需要,需要搭建基于Spring Cloud的微服务系统.遍访各大搜索引擎,发现国内资料少之又少,也难怪,国内Dubbo正统治着天下.但是,一个技术总有它的瓶颈,Dubbo也有它捉襟见肘 ...
- 基于Spring Boot和Spring Cloud实现微服务架构学习
转载自:http://blog.csdn.net/enweitech/article/details/52582918 看了几周Spring相关框架的书籍和官方demo,是时候开始总结下这中间的学习感 ...
- 基于Spring Boot和Spring Cloud实现微服务架构学习--转
原文地址:http://blog.csdn.net/enweitech/article/details/52582918 看了几周spring相关框架的书籍和官方demo,是时候开始总结下这中间的学习 ...
- Spring Boot 2.X(十七):应用监控之 Spring Boot Admin 使用及配置
Admin 简介 Spring Boot Admin 是 Spring Boot 应用程序运行状态监控和管理的后台界面.最新UI使用vue.js重写里. Spring Boot Admin 为已注册的 ...
- 基于Spring Boot和Spring Cloud实现微服务架构
官网的技术导读真的描述的很详细,虽然对于我们看英文很费劲,但如果英文不是很差,请选择沉下心去读,你一定能收获好多.我的学习是先从Spring boot开始的,然后接触到微服务架构,当然,这一切最大的启 ...
- maven 聚合工程 用spring boot 搭建 spring cloud 微服务 模块式开发项目
项目的简单介绍: 项目采用maven聚合工程 用spring boot 搭建 spring cloud的微服务 模块式开发 项目的截图: 搭建开始: 能上图 我少打字 1.首先搭建maven的聚合工程 ...
- Spring Boot 是 Spring 的一套快速配置脚手架,可以基于Spring Boot 快速开发单个微服务
Spring Boot 是 Spring 的一套快速配置脚手架,可以基于Spring Boot 快速开发单个微服务,Spring Cloud是一个基于Spring Boot实现的云应用开发工具:Spr ...
随机推荐
- Hexo博客Yilia主题添加相册功能,丰富博客内容,Next等其他主题可以参考
实现思路 1.在主页上必须有一个可供点击的相册连接 2.要用 hexo 生成一个photos.html文件 3.photos.html中的图片数据来源?因为这是一个静态页面所有要有一个 json文件 ...
- Centos7安装JDK1.8(详解版)
一.检查并卸载OpenJDK 1.卸载centos原本自带的openjdk 运行命令如下: rpm -qa | grep java 2.然后通过 rpm -e --nodeps 后面跟系统自 ...
- 代码随想录贪心专题-day1
35. 分发糖果 n 个孩子站成一排.给你一个整数数组 ratings 表示每个孩子的评分. 你需要按照以下要求,给这些孩子分发糖果: 每个孩子至少分配到 1 个糖果. 相邻两个孩子评分更高的孩子会获 ...
- salesforce零基础学习(一百二十九)Lead Convertion 有趣的经历
本篇参考:https://help.salesforce.com/s/articleView?id=000382564&type=1 Lead Convertion 是salesforce中s ...
- Redis 集群偶数节点跨地域部署之高可用测试
笔者目前所在公司存在多套 Redis 集群: A 集群 主 + 从 共 60 个分片,部署在 3 + 3 台物理机上,每台机器各承载 10 个端口 主库 30 个端口在广州,从库 30 个端口在中山 ...
- shell: xcall
#!/bin/bash ips=( 1.1.1.2 1.1.1.1 ) port= user= passwd= for i in ${ips[@]} do echo "== $i ==&qu ...
- 关于在modelsim中 仿真 ROM IP核 读取不了 mif文件 的解决方法
在modelsim中 仿真 ROM IP核 读取不了 mif文件 . 出现状况: 显示无法打开 rom_8x256.mif 文件 .点开modelsim下面文件的内存列表,可看到内存全为0. 查看自身 ...
- Go函数可以返回多个值
1 package main 2 3 import "fmt" 4 5 func swap(x, y string) (string, string){ 6 return y,x ...
- 微信小程序+web数据库的开发实践
前言 生活中使用微信小程序的场景越来越多,它实现了用户对于应用"触手可及.用完即走"的理想需求.微信小程序的开发难度也低于APP的开发制作,使用它会更便利.低成本.高经济效益. 但 ...
- pandas读取mysql并导出为excel
前言 业务需要从数据库导出数据为excel,并设置成自动化.这里用pandas写的数据导入导出,还算方便.配合crontab + shell脚本使用,每天晚上自动生成excel,然后cp到指定目录.s ...