prometheus metrics is different from that for v2.0. On v1.5, the default address is /prometheus, i.e., http://localhost:8080/prometheus.management API by default, so you need to set management.security.enabled=false.bootstrap.yml is used to configure parameters in the project, modifying management in it will not work, which should be modified in application.yml due to the Spring Boot start and load sequence.metric common tag through YML; instead, you can add it only by adding a bean to the code.spring-boot-starter-web is already imported in this project, add the actuator/prometheus Maven dependency to the pom.xml file.<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-registry-prometheus</artifactId></dependency>
application.yml file in the resources directory and modify the actuator configuration to expose the metric data in the Prometheus protocol.management:endpoints:web:exposure:include: prometheus # Web access path for opening Prometheusmetrics:# We recommend you enable the following options to monitor P99 and P95 latencies of HTTP requests. You can set the specific time distribution based on the actual conditionsdistribution:sla:http:server:requests: 1ms,5ms,10ms,50ms,100ms,200ms,500ms,1s,5s# Add special labels to Prometheustags:# You must add the corresponding application name, as the corresponding monitoring information needs to be viewed by applicationapplication: spring-boot-mvc-demo
mvn spring-boot:run. If you can access the metric data of the Prometheus protocol through http://localhost:8080/actuator/prometheus, the relevant dependency configuration is correct.Dockerfile in the root directory of the project. You can add it by referring to the following sample code and modify Dockerfile based on your actual project:FROM openjdk:8-jdkWORKDIR /spring-boot-demoADD target/spring-boot-demo-*.jar /spring-boot-demo/spring-boot-demo.jarCMD ["java","-jar","spring-boot-demo.jar"]
namespace, ImageName, and image tag as needed in your actual project.mvn clean packagedocker build . -t ccr.ccs.tencentyun.com/[namespace]/[ImageName]:[image tag]docker push ccr.ccs.tencentyun.com/[namespace]/[ImageName]:[image tag]
mvn clean packagedocker build . -t ccr.ccs.tencentyun.com/prom_spring_demo/spring-boot-demo:latestdocker push ccr.ccs.tencentyun.com/prom_spring_demo/spring-boot-demo:latest



apiVersion: v1kind: Servicemetadata:labels: # Add the corresponding labels based on the actual conditionsk8sapp: spring-mvc-demoname: spring-mvc-demonamespace: spring-demospec:ports:- name: 8080-8080-tcp # Corresponding `port` value in the ServiceMonitor scrape taskport: 8080protocol: TCPtargetPort: 8080selector:k8s-app: spring-mvc-demoqcloud-app: spring-mvc-demosessionAffinity: Nonetype: ClusterIP
port value is the spec/ports/name value in the Service YAML configuration file.apiVersion: monitoring.coreos.com/v1kind: ServiceMonitormetadata:name: spring-mvc-demo # Enter a unique namenamespace: cm-prometheus # The namespace is fixed. Do not change itspec:endpoints:- interval: 30sport: 8080-8080-tcp # Enter the name of the corresponding port of the Prometheus exporter in the Service YAML configuration filepath: /actuator/prometheus # Enter the value of the corresponding path of the Prometheus exporter. If it is not specified, it will be `/metrics` by defaultnamespaceSelector: # Select the namespace where the Service to be monitored residesmatchNames:- spring-demoselector: # Enter the label value of the Service to be monitored to locate the target ServicematchLabels:k8sapp: spring-mvc-demo

Feedback