mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
增加 actuate metrics 示例
This commit is contained in:
@@ -10,10 +10,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RequestMapping("/demo")
|
||||
public class DemoController {
|
||||
|
||||
/**
|
||||
* DEMO 访问次数 Metrics
|
||||
*/
|
||||
// private static final Counter METRICS_DEMO_COUNT = Metrics.counter("demo.visit.count");
|
||||
/**
|
||||
* DEMO 访问次数 Metrics
|
||||
*/
|
||||
@@ -23,6 +19,7 @@ public class DemoController {
|
||||
.baseUnit("次") // 指标的单位
|
||||
.tag("test", "nicai") // 自定义标签
|
||||
.register(Metrics.globalRegistry); // 注册到全局 MeterRegistry 指标注册表
|
||||
// private static final Counter METRICS_DEMO_COUNT = Metrics.counter("demo.visit.count");
|
||||
|
||||
@GetMapping("/visit")
|
||||
public String visit() {
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
package cn.iocoder.springboot.lab34.actuatordemo.controller;
|
||||
|
||||
import io.micrometer.core.annotation.Counted;
|
||||
import io.micrometer.core.annotation.Timed;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
// TODO 暂时没生效 https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-metrics-spring-mvc
|
||||
// 参考 https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-metrics-spring-mvc 文档
|
||||
// 需要设置 management.metrics.web.server.request.autotime.enabled = false
|
||||
@RestController
|
||||
@RequestMapping("/example")
|
||||
@Timed
|
||||
public class ExampleController {
|
||||
|
||||
@GetMapping("/visit")
|
||||
@Counted(value = "example.visit.count", description = "example 访问次数")
|
||||
// @Counted(value = "example.visit.count", description = "example 访问次数"
|
||||
@Timed(value = "all.people", longTask = true)
|
||||
public String visit() {
|
||||
return "Example 示例";
|
||||
}
|
||||
|
||||
@@ -15,11 +15,6 @@ management:
|
||||
# 通用 tag
|
||||
tags:
|
||||
application: demo-application
|
||||
web:
|
||||
server:
|
||||
request:
|
||||
autotime:
|
||||
enabled: false
|
||||
|
||||
endpoints:
|
||||
# Actuator HTTP 配置项,对应 WebEndpointProperties 配置类
|
||||
|
||||
Reference in New Issue
Block a user