Configuring Average Latency and Connectivity Rate Metrics to Monitor the Enterprise Router Network Connectivity Quality
You can perform the following operations to configure the average latency and connectivity rate metrics for the enterprise router network. After the configuration is complete, you can view the real-time monitoring data on the Cloud Eye console to monitor the network connectivity quality of the enterprise router. The monitoring metrics are as follows:
- Average latency (avg_latency): average response time of all requests in a single test. It reflects the network transmission speed, link congestion, and network smoothness.
- Connectivity rate (connectivity_rate): the percentage of requests that successfully establish connections and complete data exchange in a test. It reflects the network link connectivity and stability and the overall network availability.
Solution Architecture
In this solution, enterprise router (er-x) enables communications between vpc-web (192.168.0.0/16) and vpc-client (172.16.0.0/16) in the same region. ecs-web is deployed in vpc-web as the server, and ecs-client is deployed in vpc-client as the client. Based on this networking, configure average latency and connectivity rate metrics to monitor the network communication quality between the client and the server in real time.
Network Planning
Figure 1 and Table 1 show the network planning and its description for communications among two VPCs attached to an enterprise router in the same region.
| Resource | Description |
|---|---|
| VPC |
|
| Enterprise router | After Default Route Table Association and Default Route Table Propagation are enabled and the VPC attachments are created, the system will automatically:
|
| ECS | Two ECSs are in different VPCs. If the ECSs are in different security groups, add rules to the security groups to allow access to each other. |
| Destination | Next Hop | Route Type |
|---|---|---|
| Fixed CIDR block: 10.0.0.0/8 | Enterprise router er-x | Static route (custom) |
| Fixed CIDR block: 172.16.0.0/12 | Enterprise router er-x | Static route (custom) |
| Fixed CIDR block: 192.168.0.0/16 | Enterprise router er-x | Static route (custom) |
| Destination | Next Hop | Route Type |
|---|---|---|
| vpc-web CIDR block: 192.168.0.0/16 | VPC 1 attachment: er-attach-web | Propagated route |
| vpc-client CIDR block: 172.16.0.0/16 | VPC 2 attachment: er-attach-client | Propagated route |
Resource Planning
The following resource details are only examples. You can modify them as required.
| Resource | Quantity | Description |
|---|---|---|
| VPC | 2 | Two VPCs are required. One is used to deploy the ECS as the server, and the other is used to deploy the ECS as the client. Both VPCs need to be attached to the enterprise router.
|
| Enterprise router | 1 |
|
| ECS | 2 | Two ECSs are required. One acts as the server, and the other acts as the client.
In this example, only one client ECS is deployed for demonstration. In practice, you are advised to deploy one client ECS in each AZ of the enterprise router to comprehensively monitor the network status. |
Step 1: Obtain Environment Information
Prepare the environment information required for 3.c in advance. For details about the environment information to be obtained and how to obtain it, see Table 5.
| Environment | Example Value | How to Obtain |
|---|---|---|
| Project corresponding to the region where the resource is located: {project_name} | cn-east-x | Obtaining Account, IAM User, Group, Project, Region, and Agency Information |
| Project ID corresponding to the region where the resource is located: {project_id} | 15289aca74exxxxxx37dea0315d99 | |
| Name of the account used to create the IAM user | IAM-er-test | |
| IAM username | er-test | |
| Private IP address of the server ECS | 192.168.0.164 |
|
| Custom listening port | 8000 | Listening port configured in 3.c. You can customize it. |
| Enterprise router ID | cd711600-xxxx-xxxx-938f-e41eb64f5e25 |
|
Step 2: Create Resources
For details about the resource planning in this example, see Table 4.
- Create an enterprise router in region A.
For details, see Creating an Enterprise Router.
- Create two VPCs in region A.
For details, see Creating a VPC with a Subnet.
- Create two ECSs in region A.
In this example, bind an EIP to ecs-web for deploying the Nginx service.
For details, see Purchasing an ECS in Custom Config Mode.
Step 3: Create VPC Attachments to the Enterprise Router
- Attach the two VPCs to the enterprise router.
When creating the VPC attachment, enable Auto Add Routes.
If this option is enabled, routes with this enterprise router as the next hop and 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 as the destinations will be automatically added to all route tables of the VPC.
For details, see Creating VPC Attachments for the Enterprise Router.
- Check the routes with destinations set to the VPC CIDR blocks in the enterprise router route tables.
In this example, Default Route Table Association and Default Route Table Propagation are enabled for the enterprise router, and routes with destinations set to VPC CIDR blocks are automatically added when you attach the VPCs to the enterprise router.
For enterprise router route details, see Table 3.
To view enterprise routes, see Viewing Routes.
- Log in to any ECS and take the following steps to check the network connectivity:
Multiple methods are available for logging in to an ECS. For details, see Logging In to an ECS.
In this example, use VNC provided on the management console to log in to an ECS.
For example, log in to ecs-web and run the following command to check whether the two VPCs can communicate with each other:
ping Private IP address of ecs-client
Example command:
ping 172.16.0.60
If information similar to the following is displayed, the two VPCs can communicate with each other.[root@ecs-web ~]# ping 172.16.0.60 PING 172.16.0.60 (172.16.0.60) 56(84) bytes of data. 64 bytes from 172.16.0.60: icmp_seq=1 ttl=63 time=2.02 ms 64 bytes from 172.16.0.60: icmp_seq=2 ttl=63 time=1.86 ms ^C --- 172.16.0.60 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1000ms rtt min/avg/max/mdev = 1.859/1.941/2.023/0.082 ms
Step 4: Deploy Nginx on the Server ECS
- Log in to the server ECS (ecs-web) as the root user.
Multiple methods are available for logging in to an ECS. For details, see Logging In to an ECS.
In this example, use VNC provided on the management console to log in to an ECS.
- Run the following command to install Nginx: If information similar to the following is displayed, the installation is complete:
[root@ecs-web ~]# yum install nginx Last metadata expiration check: 0:24:32 ago on Thu 11 Jun 2026 02:01:16 PM CST. Dependencies resolved. ... Complete!
- Perform the following steps to configure a custom listening port:
- Run the following command to open the /etc/nginx/nginx.conf file:
vim /etc/nginx/nginx.conf
- Press i to enter the editing mode.
- Locate the server { ... } configuration information in the file and change the default value in listen 80; and listen [::]:80; to the custom port. In this example, the port is changed to 8000.
server { listen 8000; # Modify the value. listen [::]:8000; # Modify the value. (IPv6 listening, optional) server_name _; root /usr/share/nginx/html; ... } - Press ESC to exit the editing mode and enter :wq! to save the configuration.
- Run the following command to open the /etc/nginx/nginx.conf file:
- Run the following command to check whether the syntax of the Nginx configuration file is correct: If information similar to the following is displayed, the configuration is correct:
[root@ecs-web ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
- Run the following command to start Nginx:
Step 5: Deploy the Configuration Script on the Client ECS
- Log in to the client ECS (ecs-client).
Multiple methods are available for logging in to an ECS. For details, see Logging In to an ECS.
In this example, use VNC provided on the management console to log in to an ECS.
- Perform the following steps to create an automatic configuration script for monitoring metrics:
- Run the following command to create the ces.py script file:
vim ces.py
- Press i to enter the editing mode.
- Add the configuration information to the ces.py file:
import asyncio import sys from urllib.parse import urlparse import requests import time import concurrent.futures import yaml def load_parameter(file_path): with open(file_path, 'r', encoding='utf-8') as file: parameter = yaml.safe_load(file) return parameter def check_connectivity_with_curl(url): parsed_url = urlparse(url) host = parsed_url.hostname port = parsed_url.port or (443 if parsed_url.scheme == "https" else 80) path = parsed_url.path or "/" if parsed_url.query: path += f"?{parsed_url.query}" async def _raw_socket_request(): start_time = time.perf_counter() reader, writer = None, None try: if parsed_url.scheme == "https": import ssl ssl_context = ssl._create_unverified_context() reader, writer = await asyncio.wait_for( asyncio.open_connection(host, port, ssl=ssl_context), timeout=5.0 ) else: reader, writer = await asyncio.wait_for( asyncio.open_connection(host, port), timeout=5.0 ) request_header = ( f"GET {path} HTTP/1.1\r\n" f"Host: {host}\r\n" f"User-Agent: curl/7.29.0\r\n" f"Connection: close\r\n\r\n" ) writer.write(request_header.encode('utf-8')) await writer.drain() response_line = await asyncio.wait_for(reader.readline(), timeout=5.0) duration_ms = (time.perf_counter() - start_time) * 1000 status_code = int(response_line.split()[1]) return status_code, duration_ms except Exception: duration_ms = (time.perf_counter() - start_time) * 1000 return -1, duration_ms finally: if writer: writer.close() try: await writer.wait_closed() except Exception: pass try: loop = asyncio.get_event_loop() except RuntimeError: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) return loop.run_until_complete(_raw_socket_request()) def get_connectivity_stats(url, total_requests=100, max_workers=100): latencies = [] success_count = 0 with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor: futures = [executor.submit(check_connectivity_with_curl, url) for _ in range(total_requests)] for future in concurrent.futures.as_completed(futures): status_code, latency = future.result() if status_code == 200: success_count += 1 latencies.append(latency) connectivity_rate = (success_count / total_requests) * 100 avg_latency = sum(latencies) / len(latencies) if latencies else 0 return connectivity_rate, avg_latency def get_connectivity_rate(parameter, rate): return { "metric": { "namespace": parameter['namespace'], "dimensions": [{ "name": parameter['dimensions_name'], "value": parameter['dimensions_value'] }], "metric_name": parameter['metric_name_connectivity_rate'] }, "ttl": int(parameter['ttl']), "collect_time": int(time.time() * 1000), "value": rate, "unit": parameter['unit_connectivity_rate'], "type": parameter['type'] } def get_avg_latency(parameter, latency): return { "metric": { "namespace": parameter['namespace'], "dimensions": [{ "name": parameter['dimensions_name'], "value": parameter['dimensions_value'] }], "metric_name": parameter['metric_name_avg_latency'] }, "ttl": int(parameter['ttl']), "collect_time": int(time.time() * 1000), "value": latency, "unit": parameter['unit_avg_latency'], "type": parameter['type'] } class TokenManager: def __init__(self, parameter): self.token = None self.auth_url = parameter['auth_url'] self.auth_body = {"auth": {"identity": {"methods": ["password"], "password": { "user": {"name": parameter['iam_user'], "domain": {"name": parameter['iam_domain']}, "password": parameter['iam_password']}}}, "scope": {"project": {"name": parameter['iam_project']}}}} self.refresh_token() def refresh_token(self): headers = {'Content-Type': 'application/json'} try: response = requests.post(self.auth_url, json=self.auth_body, headers=headers, verify=False) new_token = response.headers.get('X-Subject-Token') if new_token: self.token = new_token else: print("not found X-Subject-Token") except Exception as e: print(f"get Token failed: {e}") def create_metric_data(create_metric_data_url, token, data): headers = {'X-Auth-Token': token} try: res = requests.post(create_metric_data_url, json=data, headers=headers, verify=False, timeout=5) return res.status_code except Exception as e: print(f"error: {e}") def main_job(parameter, token_manager): while True: rate, latency = get_connectivity_stats(parameter['target_url'], int(parameter['total_requests']), int(parameter['max_workers'])) data = [get_connectivity_rate(parameter, rate), get_avg_latency(parameter, latency)] for i in range(3): status = create_metric_data(parameter['create_metric_data_url'], token_manager.token, data) if status == 401: token_manager.refresh_token() continue break time.sleep(10) if __name__ == "__main__": parameter = load_parameter(sys.argv[1].strip()) parameter['iam_password'] = sys.argv[2].strip() manager = TokenManager(parameter) main_job(parameter, manager) - Press ESC to exit the editing mode and enter :wq! to save the configuration.
- Run the following command to create the ces.py script file:
- Perform the following steps to add the environment information required for running the script:
- Run the following command to create the parameter.yml file:
vim parameter.yml
- Press i to enter the editing mode.
- Add the configuration information to the parameter.yml file: Review the comments and replace the examples with the environment information obtained in Step 1: Obtain Environment Information.
# URL for obtaining the token. Replace {project_name} with the project corresponding to the region where the resource is located. auth_url: https://iam.{project_name}.myhuaweicloud.com/v3/auth/tokens # URL for reporting monitoring data. Replace {project_name} and {project_id} with the project name and project ID corresponding to the region where the resource is located. create_metric_data_url: https://ces.{project_name}.myhuaweicloud.com/V1.0/{project_id}/metric-data # Name of the account used to create the IAM user. The following is only an example. Replace it with the actual name. iam_domain: IAM-er-test # IAM username. The following is only an example. Replace it with the actual username. iam_user: er-test # Project of the account used to create the IAM user, that is, the project corresponding to the region where the resource is located. Replace it with the actual value. iam_project: {project_name} # Server URL. The following is only an example. Replace the IP address with the private IP address of the server ECS and the port number with the custom listening port. target_url: http://172.16.0.245:8000 # Number of requests sent in a single test. The recommended value is 100 or set it based on the site requirements. total_requests: 100 # Maximum number of concurrent requests in a single test. The recommended value is 100 or set it based on the site requirements. max_workers: 100 # Service namespace. The value is in the format of service.item, where service and item are separated by a period (.). # service and item each must start with a letter. They can contain letters, digits, and underscores (_). The value allows 3 to 32 characters. # Example: TEST.ER namespace: "TEST.ER" # Data validity period, in seconds. If the validity period expires, data will be automatically deleted. The value is an integer ranging from 1 to 604800. ttl: 172800 # Metric resource dimension name, which can be fixed to er_instance_id. dimensions_name: er_instance_id # Metric resource dimension value, that is, the enterprise router ID. The following is only an example. Replace it with the actual value. dimensions_value: eb97488a-070c-4db8-a719-ee5e66490e8d # Connectivity rate metric ID, which can be fixed to connectivity_rate. metric_name_connectivity_rate: connectivity_rate # Latency metric ID, which can be fixed to avg_latency. metric_name_avg_latency: avg_latency # Connectivity rate metric unit, which can be fixed to %. unit_connectivity_rate: "%" # Latency metric unit, which can be fixed to ms. unit_avg_latency: ms # Metric data type, which can be fixed to float. type: float - Press ESC to exit the editing mode and enter :wq! to save the configuration.
- Run the following command to create the parameter.yml file:
- Run the following command to start ces.py and parameter.yml:
nohup python3 ces.py parameter.yml Password &
Replace the password in the command with the actual password of the current account.
- After the scripts are executed, perform the following steps to view the monitoring metrics on the Cloud Eye console:
- Go to the Cloud Eye console and choose Custom Monitoring.
You can view the service namespace set in 3.c. In this example, the namespace is TEST.ER.
Figure 2 TEST.ER
- Locate the row that contains the enterprise router to be monitored and click View Metric in the Operation column. On the displayed page, you can view the monitoring metric data reported in real time.
- Average latency (avg_latency): average response time of all requests in a single test. It reflects the network transmission speed, link congestion, and network smoothness.
- Connectivity rate (connectivity_rate): the percentage of requests that successfully establish connections and complete data exchange in a test. It reflects the network link connectivity and stability and the overall network availability.
Figure 3 Monitoring metric details
- Go to the Cloud Eye console and choose Custom Monitoring.
What is your overall rating for this page?
Thank 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
