springboot监控服务器信息,面试官:聊一聊SpringBoot服务监控机制

目录

前言

任何一个服务如果没有监控,那就是两眼一抹黑,无法知道当前服务的运行情况,也就无法对可能出现的异常状况进行很好的处理,所以对任意一个服务来说,监控都是必不可少的。

就目前而言,大部分微服务应用都是基于 SpringBoot 来构建,所以了解 SpringBoot 的监控特性是非常有必要的,而 SpringBoot 也提供了一些特性来帮助我们监控应用。

本文基于 SpringBoot 2.3.1.RELEASE 版本演示。

SpringBoot 监控

SpringBoot 中的监控可以分为 HTTP 端点和 JMX 两种方式来监控当前应用的运行状况和指标收集

HTTP Endpoints 监控

执行器端点允许您监视应用程序并与之交互。SpringBoot 包括许多内置的端点,并允许我们添加自己的端点。可以通过 HTTP 或 JMX 启用或禁用每个端点,并公开(使其可以远程访问)。每个端点都有一个唯一的 id,访问时可以通过如下地址进行访问:http:ip:port/{id}(SpringBoot 1.x ),而在 SpringBoot 2.x 版本中,默认新增了一个 /actuator 作为基本路,访问地址则对应为 :http:ip:port/actuator/{id}。

使用 HTTP 监控非常简单,在 SpringBoot 项目中,引入如下依赖:

org.springframework.boot

spring-boot-starter-actuator

默认就可以通过地址 http:localhost:8080/actuator/health,访问之后得到如下结果:

658ad056f360a867ade4beb7264a9d9f.png

SpringBoot 中提供了非常多的默认端点监控,但是出于安全考虑,默认情况下有些端点并不是开启状态,如 shutdown 端点就是默认关闭的。

内置端点

SpringBoot 中默认提供的常用内置端点如下:

端点 id

描述

auditevents

公开当前应用程序的审计事件信息,需要 AuditEventRepository Bean。

beans

展示程序中所有的 Bean。

caches

公开可用的缓存。

conditions

展示配置类或者自动装配类中的条件,以及它们匹配或者不匹配的原因。

configprops

显示所有 @ConfigurationProperties 中的配置属性。

env

显示 ConfigurableEnvironment 中的所有环境。

health

显示应用程序运行状况信息。

httptrace

显示 HTTP 跟踪信息(默认情况下统计最近 100 次请求),需要 HttpTraceRepository Bean。

info

显示任意程序信息。

integrationgraph

显示 Spring 集成图,需要依赖 spring-integration-core。

loggers

展示和修改应用中的 loggers 配置。

metrics

展示当前应用监控指标的度量。

mappings

展示所有 @RequestMapping 路径。

scheduledtasks

展示应用中的所有定时任务信息。

sessions

允许从 Spring 会话支持的会话存储中检索和删除用户会话。需要使用基于 Spring Session web应用程序。

shutdown

优雅的关闭程序,默认禁止了该端点的访问。

虽然说这里的大部分端点都是默认开启的,但是默认暴露(允许对外访问)的只有 health 和 info 端点,所以如果需要允许端点对外暴露,可以通过如下配置(如果想要暴露所有的端点,则可以直接配置 "*" ):

management:

endpoints:

web:

exposure:

include: [health,info,mappings] //或者直接配置 "*"

另外,开启或禁用某一个端点,也可以通过通过如下配置进行动态控制:

management.endpoint..enabled=true

接下来我们挑选几个重点的端点来介绍一下。

health 端点

health 断点默认只是展示当前应用健康信息,但是我

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440318.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

0.《Apollo自动驾驶工程师技能图谱》

【新年礼物】开工第一天,送你一份自动驾驶工程师技能图谱! 布道团队 Apollo开发者社区 1月 2日 AI时代到来,人才的缺乏是阻碍行业大步发展的主要因素之一。Apollo平台发布以来,我们接触到非常多的开发者他们并不是专业自动驾驶领…

【HDU - 1116】【POJ - 1386】Play on Words(判断半欧拉图,欧拉通路)

题干: Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us. There is a large number…

11.Pipelines

本教程是ML系列的一部分。 在此步骤中,您将了解如何以及为何使用管道清理建模代码。 What Are Pipelines 管道是保持数据处理和建模代码有序的简单方法。 具体来说,管道捆绑了预处理和建模步骤,因此您可以像使用单个包一样使用整个捆绑包。…

ubuntu服务器创建共享文件夹,Ubuntu samba安装创建共享目录及使用

Ubuntu samba更新了很多版本更新,我本人认为Ubuntu samba是很好使的文件系统,在此向大家推荐。如今技术不断更新,各种使用文件都已经淘汰。我认为还是有很不错的如Ubuntu samba值得大家来运用。一. Ubuntu samba的安装:sudo apt-get insall s…

【POJ - 2337】Catenyms(欧拉图相关,欧拉通路输出路径,tricks)

题干: A catenym is a pair of words separated by a period such that the last letter of the first word is the same as the last letter of the second. For example, the following are catenyms: dog.gophergopher.ratrat.tigeraloha.alohaarachnid.dog A…

12.Cross-Validation

本教程是ML系列的一部分。 在此步骤中,您将学习如何使用交叉验证来更好地衡量模型性能。 What is Cross Validation 机器学习是一个迭代过程。 您将面临关于要使用的预测变量,要使用的模型类型,提供这些模型的参数等的选择。我们通过测量各…

服务器不显示u盘,服务器不读u盘启动

服务器不读u盘启动 内容精选换一换介绍使用Atlas 200 DK前需要准备的配件及开发服务器。Atlas 200 DK使用需要用户提前自购如表1所示配件。准备一个操作系统为Ubuntu X86架构的服务器,用途如下:为Atlas 200 DK制作SD卡启动盘。读卡器或者Atlas 200 DK会通…

【FZU - 2039】Pets(二分图匹配,水题)

题干: 有n个人,m条狗,然后会给出有一些人不喜欢一些狗就不会购买,问最多能卖多少狗。。 Input There is a single integer T in the first line of the test data indicating that there are T(T≤100) test cases. In the fir…

Leetcode刷题实战(1):Two Sum

Leetcode不需要过多介绍了,今天一边开始刷题一边开始总结: 官网链接如下:https://leetcode.com/problemset/all/ 题1描述: 1Two Sum38.80%Easy Given an array of integers, return indices of the two numbers such that they…

信息服务器为什么选择在贵州,为啥云服务器在贵州

为啥云服务器在贵州 内容精选换一换当用户已在ECS服务购买GPU加速型云服务器,并且想在该云服务器上运行应用时,可以通过纳管的方式将该云服务器纳入VR云渲游平台管理。登录控制台,在服务列表中选择“计算 > VR云渲游平台”。在左侧导航栏&…

LeetCode刷题实战(2):Add Two Numbers

题2描述: 2Add Two Numbers29.10%Medium You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a…

【BZOJ - 1305】dance跳舞(拆点网络流,建图,最大流,残留网络上跑最大流)

题干: 一次舞会有n个男孩和n个女孩。每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞。每个男孩都不会和同一个女孩跳两首(或更多)舞曲。有一些男孩女孩相互喜欢,而其他相互不喜欢(不会“单向喜欢”&am…

《TCP/IP详解》学习笔记(四):ICMP 协议、ping 和 Traceroute

ICMP 协议介绍 前面讲到了,IP 协议并不是一个可靠的协议,它不保证数据被成功送达,那么自然的,保证数据送达的工作应该由其他的模块来完 成。其中一个重要的模块就是 ICMP(网络控制报文)协议。 当传送 IP 数据包发生错误--比如主机…

【HDU - 1530】Maximum Clique(最大团问题,图论)

题干: Given a graph G(V, E), a clique is a sub-graph g(v, e), so that for all vertex pairs v1, v2 in v, there exists an edge (v1, v2) in e. Maximum clique is the clique that has maximum number of vertex. Input Input contains multiple tests. …

Apollo自动驾驶入门课程第①讲—无人驾驶概览

目录 1. 全面了解自动驾驶主要模块 2. 了解无人车的运作方式 3. 开放式软件栈 4. 本节其他重点 本文转自微信公众号:Apollo开发者社区 原创: 阿波君 Apollo开发者社区 8月1日 在Apollo 3.0发布的同时,我们面向更多对自动驾驶感兴趣的开发…

【CF - 699C】 Vacations (日程安排 dp)

题干: Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day…

《TCP/IP详解》学习笔记(五):IP选路、动态选路

静态 IP 选路 1一个简单的路由表 选路是 IP 层最重要的功能之一。前面的部分已经简单的讲过路由器是如何根据 IP 数据包的 IP 地址来选择路由的。 这里就不重复了。首先来看看一个简单的系统路由表: 对于一个给定的路由器,可以打印出五种不同的 flag: …

LeetCode刷题实战(43):Multiply Strings

题目描述: 43Multiply Strings28.7%Medium Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Example 1: Input: num1 "2", num2 "3" Output…

【2018山东省赛 - A】Anagram(贪心,费用流,KM算法)

题干: Problem Description Orz has two strings of the same length: A and B. Now she wants to transform A into an anagram of B (which means, a rearrangement of B) by changing some of its letters. The only operation the girl can make is to “incr…

【2018ACM山东省赛 - B】Bullet(二分 + 二分图匹配,匈牙利算法,卡常)

题干: Problem Description In GGO, a world dominated by gun and steel, players are fighting for the honor of being the strongest gunmen. Player Shino is a sniper, and her aimed shot kills one monster at a time. Now she is in an nnn \times nnn m…