refactor: use Woodpecker CI and simplify monitoring to Spring Boot Actuator only
This commit is contained in:
@@ -2,22 +2,16 @@ management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info,metrics,prometheus
|
||||
include: health,info,metrics
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
metrics:
|
||||
enabled: true
|
||||
info:
|
||||
env:
|
||||
enabled: true
|
||||
metrics:
|
||||
export:
|
||||
prometheus:
|
||||
simple:
|
||||
enabled: true
|
||||
tags:
|
||||
application: ${spring.application.name}
|
||||
environment: ${spring.profiles.active:default}
|
||||
distribution:
|
||||
percentiles-histogram:
|
||||
http.server.requests: true
|
||||
percentiles:
|
||||
http.server.requests: 0.5,0.95,0.99
|
||||
sla:
|
||||
http.server.requests: 100ms,200ms,500ms,1s,2s
|
||||
enable:
|
||||
jvm: true
|
||||
process: true
|
||||
system: true
|
||||
@@ -59,18 +59,6 @@
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
package cn.novalon.manage.common.monitoring;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class MetricsAspect {
|
||||
|
||||
private final MetricsCollector metricsCollector;
|
||||
|
||||
public MetricsAspect(MetricsCollector metricsCollector) {
|
||||
this.metricsCollector = metricsCollector;
|
||||
}
|
||||
|
||||
@Pointcut("within(cn.novalon.manage..*) && " +
|
||||
"@annotation(org.springframework.web.bind.annotation.GetMapping || " +
|
||||
"@annotation(org.springframework.web.bind.annotation.PostMapping || " +
|
||||
"@annotation(org.springframework.web.bind.annotation.PutMapping || " +
|
||||
"@annotation(org.springframework.web.bind.annotation.DeleteMapping)")
|
||||
public void apiMethods() {}
|
||||
|
||||
@Around("apiMethods()")
|
||||
public Object monitorApiCall(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
String className = joinPoint.getTarget().getClass().getSimpleName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
String module = extractModule(className);
|
||||
String endpoint = className.replace("Handler", "").toLowerCase() + "/" + methodName;
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
boolean success = true;
|
||||
String errorType = null;
|
||||
|
||||
try {
|
||||
Object result = joinPoint.proceed();
|
||||
|
||||
if (result instanceof Mono) {
|
||||
return ((Mono<?>) result)
|
||||
.doOnError(error -> {
|
||||
success = false;
|
||||
errorType = error.getClass().getSimpleName();
|
||||
metricsCollector.recordError(module, errorType, error.getMessage());
|
||||
})
|
||||
.doOnSuccess(v -> {
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
metricsCollector.recordApiCall(module, endpoint, "GET", duration, true);
|
||||
});
|
||||
}
|
||||
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
metricsCollector.recordApiCall(module, endpoint, "GET", duration, true);
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
success = false;
|
||||
errorType = e.getClass().getSimpleName();
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
metricsCollector.recordApiCall(module, endpoint, "GET", duration, false);
|
||||
metricsCollector.recordError(module, errorType, e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private String extractModule(String className) {
|
||||
if (className.contains("Notify")) return "notify";
|
||||
if (className.contains("File")) return "file";
|
||||
if (className.contains("User")) return "user";
|
||||
if (className.contains("Role")) return "role";
|
||||
if (className.contains("Config")) return "config";
|
||||
if (className.contains("Log")) return "log";
|
||||
return "system";
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
package cn.novalon.manage.common.monitoring;
|
||||
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.Timer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class MetricsCollector {
|
||||
|
||||
private final MeterRegistry meterRegistry;
|
||||
|
||||
public MetricsCollector(MeterRegistry meterRegistry) {
|
||||
this.meterRegistry = meterRegistry;
|
||||
}
|
||||
|
||||
public Counter buildCounter(String name, String description, String... tags) {
|
||||
return Counter.builder(name)
|
||||
.description(description)
|
||||
.tags(tags)
|
||||
.register(meterRegistry);
|
||||
}
|
||||
|
||||
public Timer buildTimer(String name, String description, String... tags) {
|
||||
return Timer.builder(name)
|
||||
.description(description)
|
||||
.tags(tags)
|
||||
.register(meterRegistry);
|
||||
}
|
||||
|
||||
public void recordApiCall(String module, String endpoint, String method, long duration, boolean success) {
|
||||
Timer.builder("api.call.duration")
|
||||
.description("API call duration")
|
||||
.tag("module", module)
|
||||
.tag("endpoint", endpoint)
|
||||
.tag("method", method)
|
||||
.register(meterRegistry)
|
||||
.record(duration, TimeUnit.MILLISECONDS);
|
||||
|
||||
Counter.builder("api.call.count")
|
||||
.description("API call count")
|
||||
.tag("module", module)
|
||||
.tag("endpoint", endpoint)
|
||||
.tag("method", method)
|
||||
.tag("status", success ? "success" : "failure")
|
||||
.register(meterRegistry)
|
||||
.increment();
|
||||
}
|
||||
|
||||
public void recordDatabaseQuery(String module, String operation, long duration, boolean success) {
|
||||
Timer.builder("db.query.duration")
|
||||
.description("Database query duration")
|
||||
.tag("module", module)
|
||||
.tag("operation", operation)
|
||||
.register(meterRegistry)
|
||||
.record(duration, TimeUnit.MILLISECONDS);
|
||||
|
||||
Counter.builder("db.query.count")
|
||||
.description("Database query count")
|
||||
.tag("module", module)
|
||||
.tag("operation", operation)
|
||||
.tag("status", success ? "success" : "failure")
|
||||
.register(meterRegistry)
|
||||
.increment();
|
||||
}
|
||||
|
||||
public void recordCacheHit(String module, String cacheName, boolean hit) {
|
||||
Counter.builder("cache.access")
|
||||
.description("Cache access count")
|
||||
.tag("module", module)
|
||||
.tag("cache", cacheName)
|
||||
.tag("result", hit ? "hit" : "miss")
|
||||
.register(meterRegistry)
|
||||
.increment();
|
||||
}
|
||||
|
||||
public void recordError(String module, String errorType, String message) {
|
||||
Counter.builder("error.count")
|
||||
.description("Error count")
|
||||
.tag("module", module)
|
||||
.tag("type", errorType)
|
||||
.tag("message", message)
|
||||
.register(meterRegistry)
|
||||
.increment();
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package cn.novalon.manage.common.monitoring;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MetricsConfig {
|
||||
|
||||
@Bean
|
||||
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
|
||||
return registry -> registry.config().commonTags(
|
||||
"application", "novalon-manage-api",
|
||||
"environment", System.getenv().getOrDefault("ENV", "development")
|
||||
);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MetricsCollector metricsCollector(MeterRegistry meterRegistry) {
|
||||
return new MetricsCollector(meterRegistry);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user