对于最新稳定版本,请使用Spring Boot 4.0.0spring-doc.cadn.net.cn

驱动器

Spring套包含Spring套执行器。 本节回答了使用该词时常出现的问题。spring-doc.cadn.net.cn

更改执行器端点的HTTP端口或地址

在独立应用程序中,执行器的 HTTP 端口默认与主 HTTP 端口相同。 要让应用程序在不同端口监听,请设置外部属性:management.server.port. 如果监听完全不同的网络地址(比如管理用内部网络和用户应用用外部网络),你也可以设置管理服务器.address连接到服务器能够绑定的有效IP地址。spring-doc.cadn.net.cn

更多详情请参见ManagementServerProperties源代码及管理服务器端口定制,见“生产准备功能”部分。spring-doc.cadn.net.cn

个性化净化

要控制消毒过程,定义一个消毒功能豆。 这SanitizableData调用该函数的 能够访问键和值,以及地产来源他们就是从那里来的。 例如,这允许你对来自特定房产来源的每一个价值进行净化。 每消毒功能按顺序调用,直到某个函数改变了可净化数据的值。spring-doc.cadn.net.cn

将健康指标映射到微米级指标

Spring套健康指示器返回地位类型用于表示整体系统健康状况。 如果你想监控或提醒某个应用的健康水平,可以用Micrometer导出这些状态作为指标。 默认情况下,Spring Boot 使用状态代码“UP”、“DOWN”、“OUT_OF_SERVICE”和“UNKNOWN”。 要导出这些数据,你需要将这些状态转换为某种数字,以便与Micrometer配合使用。轨距.spring-doc.cadn.net.cn

以下示例展示了编写此类导出器的一种方法:spring-doc.cadn.net.cn

import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;

import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.actuate.health.Status;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class MyHealthMetricsExportConfiguration {

	public MyHealthMetricsExportConfiguration(MeterRegistry registry, HealthEndpoint healthEndpoint) {
		// This example presumes common tags (such as the app) are applied elsewhere
		Gauge.builder("health", healthEndpoint, this::getStatusCode).strongReference(true).register(registry);
	}

	private int getStatusCode(HealthEndpoint health) {
		Status status = health.health().getStatus();
		if (Status.UP.equals(status)) {
			return 3;
		}
		if (Status.OUT_OF_SERVICE.equals(status)) {
			return 2;
		}
		if (Status.DOWN.equals(status)) {
			return 1;
		}
		return 0;
	}

}
import io.micrometer.core.instrument.Gauge
import io.micrometer.core.instrument.MeterRegistry
import org.springframework.boot.actuate.health.HealthEndpoint
import org.springframework.boot.actuate.health.Status
import org.springframework.context.annotation.Configuration

@Configuration(proxyBeanMethods = false)
class MyHealthMetricsExportConfiguration(registry: MeterRegistry, healthEndpoint: HealthEndpoint) {

	init {
		// This example presumes common tags (such as the app) are applied elsewhere
		Gauge.builder("health", healthEndpoint) { health ->
			getStatusCode(health).toDouble()
		}.strongReference(true).register(registry)
	}

	private fun getStatusCode(health: HealthEndpoint) = when (health.health().status) {
		Status.UP -> 3
		Status.OUT_OF_SERVICE -> 2
		Status.DOWN -> 1
		else -> 0
	}

}