- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章springboot集成普罗米修斯(Prometheus)的方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
Prometheus 是一套开源的系统监控报警框架。它由工作在 SoundCloud 的 员工创建,并在 2015 年正式发布的开源项目。2016 年,Prometheus 正式加入 Cloud Native Computing Foundation,非常的受欢迎.
简介 。
Prometheus 具有以下特点:
Prometheus 组成及架构 。
声明:该小节参考了文章[Prometheus 入门与实践] 。
Prometheus 生态圈中包含了多个组件,其中许多组件是可选的:
一些其他的工具.
其大概的工作流程是:
1.Prometheus server 定期从配置好的 jobs 或者 exporters 中拉 metrics,或者接收来自 Pushgateway 发过来的 metrics,或者从其他的 Prometheus server 中拉 metrics。 2.Prometheus server 在本地存储收集到的 metrics,并运行已定义好的 alert.rules,记录新的时间序列或者向 Alertmanager 推送警报。 3.Alertmanager 根据配置文件,对接收到的警报进行处理,发出告警。 4.在图形界面中,可视化采集数据.
springboot 集成prometheus 。
在spring boot工程中引入actuator的起步依赖,以及micrometer-registry-prometheus的依赖.
1
2
3
4
5
6
7
8
9
10
11
12
|
<
dependency
>
<
groupId
>org.springframework.boot</
groupId
>
<
artifactId
>spring-boot-starter-web</
artifactId
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework.boot</
groupId
>
<
artifactId
>spring-boot-starter-actuator</
artifactId
>
</
dependency
>
<
dependency
>
<
groupId
>io.micrometer</
groupId
>
<
artifactId
>micrometer-registry-prometheus</
artifactId
>
</
dependency
>
|
暴露prometheus的接口;暴露metrics.tags,和spring.application.name一致.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
server:
port: 8081
spring:
application:
name: my-prometheus
management:
endpoints:
web:
exposure:
include: 'prometheus'
metrics:
tags:
application: ${spring.application.name}
|
写一个API接口,用作测试。代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
@RestController
public
class
TestController {
Logger logger = LoggerFactory.getLogger(TestController.
class
);
@GetMapping
(
"/test"
)
public
String test() {
logger.info(
"test"
);
return
"ok"
;
}
@GetMapping
(
""
)
public
String home() {
logger.info(
"home"
);
return
"ok"
;
}
}
|
在浏览器上访问http://localhost:8081/actuator/prometheus,展示的信息如下,这些信息都是actuator的一些监控信息.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# HELP jvm_gc_max_data_size_bytes Max size of old generation memory pool
# TYPE jvm_gc_max_data_size_bytes gauge
jvm_gc_max_data_size_bytes{application="my-prometheus",} 2.863661056E9
# HELP http_server_requests_seconds
# TYPE http_server_requests_seconds summary
http_server_requests_seconds_count{application="my-prometheus",exception="None",method="GET",outcome="CLIENT_ERROR",status="404",uri="/**",} 1.0
http_server_requests_seconds_sum{application="my-prometheus",exception="None",method="GET",outcome="CLIENT_ERROR",status="404",uri="/**",} 0.018082327
# HELP http_server_requests_seconds_max
# TYPE http_server_requests_seconds_max gauge
http_server_requests_seconds_max{application="my-prometheus",exception="None",method="GET",outcome="CLIENT_ERROR",status="404",uri="/**",} 0.018082327
# HELP jvm_threads_states_threads The current number of threads having NEW state
# TYPE jvm_threads_states_threads gauge
jvm_threads_states_threads{application="my-prometheus",state="waiting",} 12.0
jvm_threads_states_threads{application="my-prometheus",state="runnable",} 8.0
jvm_threads_states_threads{application="my-prometheus",state="timed-waiting",} 2.0
jvm_threads_states_threads{application="my-prometheus",state="terminated",} 0.0
jvm_threads_states_threads{application="my-prometheus",state="blocked",} 0.0
jvm_threads_states_threads{application="my-prometheus",state="new",} 0.0
# HELP process_files_open_files The open file descriptor count
# TYPE process_files_open_files gauge
...省略更多
|
安装Prometheus 。
安装Prometheus很简单,在linux系统上安装,执行以下的安装命令。其他的操作系统,比如windows、mac等在官网上(https://prometheus.io/download/)下载并安装.
1
2
3
|
wget https:
//github
.com
/prometheus/prometheus/releases/download/v2
.19.2
/prometheus-2
.19.2.darwin-amd64.
tar
.gz
tar
xvfz prometheus-*.
tar
.gz
cd
prometheus-*
|
修改Prometheus的配置文件prometheus.yml,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'springboot_prometheus'
scrape_interval: 5s
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['127.0.0.1:8081']
|
使用以下的命令启动prometheus,并通过–config.file指定配置文件 。
1
|
./prometheus --config.file=prometheus.yml
|
多次请求springboot项目的接口http://localhost:8081/test , 并访问prometheus的控制台http://localhost:9090/,展示的界面如下:
prometheus提供了一些可视化图,比如使用柱状图来展示每秒请求数:
安装grafana 。
grafana 是一款采用 go 语言编写的开源应用,主要用于大规模指标数据的可视化展现,是网络架构和应用分析中最流行的时序数据展示工具,目前已经支持绝大部分常用的时序数据库。使用grafana去展示prometheus上的数据。先安装,安装命令如下:
1
2
3
|
wget https:
//dl
.grafana.com
/oss/release/grafana-7
.0.4.darwin-amd64.
tar
.gz
tar
-zxvf grafana-7.0.4.darwin-amd64.
tar
.gz
.
/grafana-server
|
访问http://localhost:3000/,初始密码:admin/admin.
配置数据源,如图:
配置prometheus的地址:http://localhost:9090 ,如图所示:
在dashboard界面新建panel,展示的metrics为http_server_request_seconds_count,即展示了以时间为横轴,请求数为纵轴的请求曲线,如图所示:
参考资料 。
[Prometheus 入门与实践] 。
到此这篇关于springboot集成普罗米修斯(Prometheus)的方法的文章就介绍到这了,更多相关springboot集成普罗米修斯内容请搜索我以前的文章或继续浏览下面的相关文章希望大家以后多多支持我! 。
原文链接:https://blog.csdn.net/forezp/article/details/107465307 。
最后此篇关于springboot集成普罗米修斯(Prometheus)的方法的文章就讲到这里了,如果你想了解更多关于springboot集成普罗米修斯(Prometheus)的方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我想了解 Ruby 方法 methods() 是如何工作的。 我尝试使用“ruby 方法”在 Google 上搜索,但这不是我需要的。 我也看过 ruby-doc.org,但我没有找到这种方法。
Test 方法 对指定的字符串执行一个正则表达式搜索,并返回一个 Boolean 值指示是否找到匹配的模式。 object.Test(string) 参数 object 必选项。总是一个
Replace 方法 替换在正则表达式查找中找到的文本。 object.Replace(string1, string2) 参数 object 必选项。总是一个 RegExp 对象的名称。
Raise 方法 生成运行时错误 object.Raise(number, source, description, helpfile, helpcontext) 参数 object 应为
Execute 方法 对指定的字符串执行正则表达式搜索。 object.Execute(string) 参数 object 必选项。总是一个 RegExp 对象的名称。 string
Clear 方法 清除 Err 对象的所有属性设置。 object.Clear object 应为 Err 对象的名称。 说明 在错误处理后,使用 Clear 显式地清除 Err 对象。此
CopyFile 方法 将一个或多个文件从某位置复制到另一位置。 object.CopyFile source, destination[, overwrite] 参数 object 必选
Copy 方法 将指定的文件或文件夹从某位置复制到另一位置。 object.Copy destination[, overwrite] 参数 object 必选项。应为 File 或 F
Close 方法 关闭打开的 TextStream 文件。 object.Close object 应为 TextStream 对象的名称。 说明 下面例子举例说明如何使用 Close 方
BuildPath 方法 向现有路径后添加名称。 object.BuildPath(path, name) 参数 object 必选项。应为 FileSystemObject 对象的名称
GetFolder 方法 返回与指定的路径中某文件夹相应的 Folder 对象。 object.GetFolder(folderspec) 参数 object 必选项。应为 FileSy
GetFileName 方法 返回指定路径(不是指定驱动器路径部分)的最后一个文件或文件夹。 object.GetFileName(pathspec) 参数 object 必选项。应为
GetFile 方法 返回与指定路径中某文件相应的 File 对象。 object.GetFile(filespec) 参数 object 必选项。应为 FileSystemObject
GetExtensionName 方法 返回字符串,该字符串包含路径最后一个组成部分的扩展名。 object.GetExtensionName(path) 参数 object 必选项。应
GetDriveName 方法 返回包含指定路径中驱动器名的字符串。 object.GetDriveName(path) 参数 object 必选项。应为 FileSystemObjec
GetDrive 方法 返回与指定的路径中驱动器相对应的 Drive 对象。 object.GetDrive drivespec 参数 object 必选项。应为 FileSystemO
GetBaseName 方法 返回字符串,其中包含文件的基本名 (不带扩展名), 或者提供的路径说明中的文件夹。 object.GetBaseName(path) 参数 object 必
GetAbsolutePathName 方法 从提供的指定路径中返回完整且含义明确的路径。 object.GetAbsolutePathName(pathspec) 参数 object
FolderExists 方法 如果指定的文件夹存在,则返回 True;否则返回 False。 object.FolderExists(folderspec) 参数 object 必选项
FileExists 方法 如果指定的文件存在返回 True;否则返回 False。 object.FileExists(filespec) 参数 object 必选项。应为 FileS
我是一名优秀的程序员,十分优秀!