codingliang 1 rok pred
rodič
commit
55ddf27cec

+ 6 - 0
pom.xml

@@ -447,6 +447,12 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-registry-prometheus</artifactId>
+            <scope>runtime</scope>
+        </dependency>
     </dependencies>
 
     <dependencyManagement>

+ 9 - 0
src/main/java/com/sqx/SqxApplication.java

@@ -1,11 +1,15 @@
 package com.sqx;
 
 import com.sqx.common.utils.MyGlobalThreadPool;
+import io.micrometer.core.instrument.MeterRegistry;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
+import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.ApplicationEvent;
 import org.springframework.context.ApplicationListener;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.event.ContextClosedEvent;
 
 @SpringBootApplication
@@ -36,4 +40,9 @@ public class SqxApplication implements CommandLineRunner, ApplicationListener<Ap
 			MyGlobalThreadPool.shutdown(false);
 		}
 	}
+
+	@Bean
+	MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName, @Value("${spring.profiles.active}") String active) {
+		return (registry) -> registry.config().commonTags("application", applicationName + "-" + active);
+	}
 }

+ 12 - 0
src/main/resources/application.yml

@@ -15,6 +15,8 @@ server:
     context-path: /sqx_fast
 
 spring:
+  application:
+    name: wm-01ll
   main:
     allow-circular-references: true
   # 环境 dev|test|prod
@@ -37,6 +39,7 @@ spring:
 #  resources:
 #    add-mappings: false
 
+# 监控
 management:
   endpoints:
     web:
@@ -44,6 +47,15 @@ management:
       base-path: /my-check
       exposure:
         include: "*"
+  endpoint:
+    prometheus:
+      enabled: true
+    health:
+      show-details: always
+  metrics:
+    export:
+      prometheus:
+        enabled: true
 
 #mybatis
 mybatis-plus: