Bu sayfa henüz yerel dilinizde mevcut değildir. Daha fazla dil seçeneği eklemek için yoğun bir şekilde çalışıyoruz. Desteğiniz için teşekkür ederiz.
- Service Overview
- Billing
- Getting Started
-
User Guide
- Overview
- Permissions Management
- Environment Management
- Application Management
- Component Management
- Instance Management
- Component Configurations
- Component O&M
- System Settings
- Key Operations Recorded by CTS
-
Best Practices
- CAE Best Practices
- Using CAE to Host Nginx Static File Servers
- Interconnecting GitLab with Jenkins for Automatic Build and Deployment on CAE
- Deploying Components Based on the Dependency Sequence Using the Jenkins Pipeline
- Deploying Spring Cloud Applications to CAE to Automatically Connect to the Nacos Engine
- Graceful Startup of a Spring Cloud Application
- Health Check
- Lifecycle Management
- Sending Event Alarms to WeCom
-
Connecting to the CodeArts Pipeline to Automatically Upgrade CAE Components
- Overview
- Upgrading a CAE Component After Uploading a Software Package Built Using the Pipeline to a CodeArts Release Repo
- Upgrading a CAE Component After Uploading a Software Package Built Using the Pipeline to the OBS Bucket
- Upgrading a CAE Component After Uploading an Image Built Using the Pipeline to the SWR Image Repository
- Configuring PromQL to Implement Custom Auto Scaling
- Configuring the Interconnection Between CAE and DEW to Help Applications Obtain Encrypted Secrets from DEW
- Deploying ASP.NET Core Applications to CAE
- Connecting the Network Through Enterprise Routes
- API Reference
-
FAQs
- Component Management FAQs
- Environment Management
-
Component Configuration FAQs
- Is Manual Scaling Still Effective When a Scaling Policy Is Configured?
- Can Components Be Scaled Without a Scaling Policy?
- Why Is My Instance Abnormal After Cloud Storage Is Configured?
- What Do I Do If a Component Becomes Not Ready?
- How Does CAE Support Dark Launch?
- How Do I Provide Prometheus Metrics for a Java Application?
- System Configuration FAQs
- Service Resources FAQs
- General Reference
Copied.
How Do I Provide Prometheus Metrics for a Java Application?
Context
Prometheus is built in CAE to collect monitoring metrics of components. The default monitoring metrics are limited. To customize more metrics, define the corresponding structure (Exporter) in the program, expose the API, deploy the structure on CAE, and configure it. This section uses the Spring Boot backend component in Getting Started as an example to describe how to customize Prometheus metrics. It exposes Prometheus metrics through HTTP and customizes the metric structure as required.
Adding the POM Dependency
Add the following dependency to the src/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>
Modifying the Configuration File
Modify the actuator configuration in the application.yml file in the resources directory to expose Prometheus metric data.
management: endpoints: web: exposure: include: prometheus
After configuration, the Spring Boot project exposes Prometheus monitoring metrics through port 9090 in the /actuator/prometheus path.
Customizing Monitoring Metrics in the Spring Boot Project
Define a metric of the Counter type: The value increases by 1 each time a frontend click calls the backend API.
In src\main\java\com\huawei\cae\controller\UserDataController.java, define the following fields and methods and import required classes:
The function is to define monitoring metric click_operated_total of the Counter type.
import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.MeterRegistry; import javax.annotation.PostConstruct; ... @Autowired private MeterRegistry registry; private Counter visitCounter; @PostConstruct private void init() { visitCounter = registry.counter("click_operated_total", "click_operated_total",""); }
Add the following code to the first line of the clientTest() method called by the frontend:
visitCounter.increment();
In this way, each time the method is accessed, the value of click_ operated_total defined above increases by 1.
The modified project can be deployed on CAE to monitor the customized Prometheus metrics.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot