This topic describes how to connect an application deployed in a virtual private cloud (VPC) in Serverless App Engine (SAE) to Managed Service for Prometheus.
Step 1: Create an application in SAE and obtain the information about the VPC and vSwitch
Create an application in the SAE console and expose metrics through an endpoint or other types of addresses.
On the Applications page in the SAE console, obtain the namespace, VPC, vSwitch, and security group of the application.
Step 2: Create a Prometheus instance for ECS
- Log on to the Managed Service for Prometheus console.
- In the left-side navigation pane, click Monitoring List. The Prometheus Service page appears.
- Click Create Prometheus Instance. On the page that appears, click Prometheus Instance for ECS.
Find the VPC that is obtained in Step 1 and click Install in the Actions column.
In the Install Prometheus Agent dialog box, enter the instance name, select a vSwitch, security group, and Grafana workspace, and then click OK.
NoteVPC: The VPC that you obtained in Step 1 is displayed.
vSwitch and security group: We recommend that you select the vSwitch and security group that you obtained in Step 1.
Security group rules: You must also add security group rules to ensure that the application in SAE can communicate with Managed Service for Prometheus.
After the Prometheus agent is installed, the Status column corresponding to the VPC shows Installed.
Step 3: Configure service discovery
In the top navigation bar of the Instances page, select a region. Find the Prometheus instance created in Step 2, click Settings in the Actions column.
On the Settings page, click Edit Prometheus.yaml. In the Edit Prometheus.yaml dialog box, enter the following code to configure service discovery to discover services in SAE, and click Save.
global: scrape_interval: 30s scrape_timeout: 30s evaluation_interval: 30s scrape_configs: ## job_name: Specify a custom job name. - job_name: sae-test honor_timestamps: true scrape_interval: 30s scrape_timeout: 10s metrics_path: /metrics scheme: http ## Service discovery for applications in SAE aliyun_sae_sd_configs: ## Specify the port that is used by your application. - port: 9913 ## Specify user information. user_id: ********* access_key: ********* access_key_secret: ******** refresh_interval: 30s ## Specify the information obtained in Step 1. region_id: cn-hangzhou vpc_id: vpc-bp156863cbb2z17bhyzav namespace_id: ["cn-hangzhou"] app_name: ["test1","test2"] tag_filters: - key: environment values: ["daily","publish"] - key: owner values: ["zhangshan"] relabel_configs: - source_labels: [__meta_sae_private_ip] regex: (.*) target_label: __address__ ## Specify the port that is used by your application. replacement: $1:9913 - source_labels: [__meta_sae_namespace_id] regex: (.*) target_label: namespace replacement: $1 - source_labels: [__meta_sae_app_name] regex: (.*) target_label: app_name replacement: $1 - source_labels: [__meta_sae_group_name] regex: (.*) target_label: group_name replacement: $1 - source_labels: [__meta_sae_instance_id] regex: (.*) target_label: instance_id replacement: $1 - source_labels: [__meta_sae_status] regex: (.*) target_label: instance_status replacement: $1 ## Specify that tags that you add to your application in the __meta_sae_tag_[tagName] format. - source_labels: [__meta_sae_tag_owner] regex: (.*) target_label: owner replacement: $1
Step 4: View monitoring data
In the left-side navigation pane, click Dashboards. On the page that appears, click the name of a dashboard to go to the Grafana page.
In the left-side navigation pane, click Explore. On the Explore page, select the data source corresponding to the VPC, and then enter the query command for a metric, for example, up{job="sae-test"}. You can check whether the data is collected as expected. If the data is not collected, check the network rules of the security group and the Prometheus.yaml configuration.
NoteUse the job name specified in Step 3 for the job field.