1、Prometheus介绍

Prometheus使用Go语言开发,中文名称叫:普罗 米修斯。Prometheus是一个开源系统最初在SoundCloud构建的监控和警报工具包。自 2012 年成立以来,许多公司和组织已经采用了 Prometheus,它现在是一个独立的开源项目并独立于任何公司进行维护。Prometheus于2016年加入云原生计算基金会作为继 Kubernetes之后的第二个托管项目。Prometheus主要用于抓取目标数据,并记录所有抓取的目标数据。

官网地址

https://prometheus.io/

Github地址

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监控的更多相关文章

  1. zabbix监控windows主机网卡流量

    监控windows主机网卡流量 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.     欢迎加入:高级运维工程师之路 598432640 客户端配置:(172.30.1.120,wi ...

  2. Cacti监控Windows主机,Windows主机的正确配置

    使用cacti监控Windows主机的时候经常遇到无法获取Windows主机的snmp信息和Windows主机的硬件信息,主要原因是Windows主机没有正确配置snmp,以下是正确的配置步骤:1.安 ...

  3. nagios系列(八)之nagios通过nsclient监控windows主机

    nagios通过nsclient监控windows主机 1.下载NSClient -0.3.8-Win32.rar安装在需要被监控的windows主机中 可以设置密码,此处密码留空 2.通过在nagi ...

  4. 基于Spring Boot、Spring Cloud、Docker的微服务系统架构实践

    由于最近公司业务需要,需要搭建基于Spring Cloud的微服务系统.遍访各大搜索引擎,发现国内资料少之又少,也难怪,国内Dubbo正统治着天下.但是,一个技术总有它的瓶颈,Dubbo也有它捉襟见肘 ...

  5. 基于Spring Boot和Spring Cloud实现微服务架构学习

    转载自:http://blog.csdn.net/enweitech/article/details/52582918 看了几周Spring相关框架的书籍和官方demo,是时候开始总结下这中间的学习感 ...

  6. 基于Spring Boot和Spring Cloud实现微服务架构学习--转

    原文地址:http://blog.csdn.net/enweitech/article/details/52582918 看了几周spring相关框架的书籍和官方demo,是时候开始总结下这中间的学习 ...

  7. Spring Boot 2.X(十七):应用监控之 Spring Boot Admin 使用及配置

    Admin 简介 Spring Boot Admin 是 Spring Boot 应用程序运行状态监控和管理的后台界面.最新UI使用vue.js重写里. Spring Boot Admin 为已注册的 ...

  8. 基于Spring Boot和Spring Cloud实现微服务架构

    官网的技术导读真的描述的很详细,虽然对于我们看英文很费劲,但如果英文不是很差,请选择沉下心去读,你一定能收获好多.我的学习是先从Spring boot开始的,然后接触到微服务架构,当然,这一切最大的启 ...

  9. maven 聚合工程 用spring boot 搭建 spring cloud 微服务 模块式开发项目

    项目的简单介绍: 项目采用maven聚合工程 用spring boot 搭建 spring cloud的微服务 模块式开发 项目的截图: 搭建开始: 能上图 我少打字 1.首先搭建maven的聚合工程 ...

  10. Spring Boot 是 Spring 的一套快速配置脚手架,可以基于Spring Boot 快速开发单个微服务

    Spring Boot 是 Spring 的一套快速配置脚手架,可以基于Spring Boot 快速开发单个微服务,Spring Cloud是一个基于Spring Boot实现的云应用开发工具:Spr ...

随机推荐

  1. 【技术积累】Vue.js中的事件【一】

    Vue中的事件是什么 在Vue.js中,事件是用于处理用户交互的重要机制.Vue.js提供了一系列的事件处理方法和指令,使开发者能够方便地处理用户的各种操作. 1. 事件绑定:Vue.js通过v-on ...

  2. Robot Framework 自动化测试随笔(一)

    一.安装Robot Framework步骤(安装目录避免中文和特殊字符,建议以管理员身份进行全部安装过程): 1.查看ride最新支持的python版本,据此下载对应python版本: https:/ ...

  3. QTextEdit的使用

    import sys from PyQt5.QtWidgets import QApplication, QWidget, QTextEdit,QVBoxLayout, QPushButton cla ...

  4. [nginx]借助nginx实现自动获取本机IP

    前言 在用脚本自动化部署应用时,有的应用需要指定本机IP,网上找到的方案大多是过滤ifconfig或者ip命令的结果,这里提供一种通过nginx获取本机ip的方法.大致思路为客户端向nginx发起请求 ...

  5. fastapi之helloworld

    简介 以下简介来自官网描述: FastAPI是一个用于构建API的现代.快速(高性能)的web框架,使用Python3.6+并基于标准的Python类型提示. 关键特性: 快速:可与NodeJS和Go ...

  6. DateTime 相关的操作汇总【C# 基础】

    〇.前言 在日常开发中,日期值当然是不可或缺的,能够清晰的在脑海中梳理出最快捷的实现也非常重要,那么今天就来汇总一下. 一.C# 中的本机时间以及格式化 如何取当前(本机)时间?很简单,一句话解决: ...

  7. 3、Spring之入门案例

    3.1.创建module 3.1.1.右击project,创建新module 3.1.2.选择maven 3.1.3.设置module名称和路径 3.1.4.module初始状态 3.1.5.配置打包 ...

  8. KIOPTRIX: LEVEL 1.1 (#2) 常规命令注入+内核提权

    0×02 Vulnhub靶机渗透总结之 KIOPTRIX: LEVEL 1.1 (#2) 系列专栏:Vulnhub靶机渗透系列 欢迎大佬:点赞️收藏关注 首发时间: 2023年8月20日 如有错误 还 ...

  9. 简述Spring Cache缓存策略

    一.简介 Spring框架提供了一种名为Spring Cache的缓存策略.Spring Cache是一种抽象层,它提供了一种方便的方式来管理缓存,并与Spring应用程序中的各种缓存实现(如EhCa ...

  10. Solution -「香港网络赛 2016」A+B Problem

    Description Link. 给出一个长度为 \(n\) 的序列 \(a\),问有序三元组 \((a_{i},a_{j},a_{k})\) 使得 \(i\neq j\neq k\) 且 \(a_ ...