This topic describes how to view the traffic data of an Elastic Compute Service (ECS) instance in a virtual private cloud (VPC) by using flow logs.
Prerequisites
A VPC is created and two vSwitches are created in the VPC. In this example, the vSwitches are named vSwitch 1 and vSwitch 2. For more information, see Create a VPC with an IPv4 CIDR block.
ECS 1 and ECS 2 are created in vSwitch 1. ECS 3 and ECS 4 are created in vSwitch 2. Applications are deployed on ECS 2 and ECS 4. For more information, see Create an instance by using the wizard.
Background information
The following scenario is used in this topic. ECS 2 and ECS 4 are connected to different vSwitches that belong to the same VPC. Large amounts of data are exchanged between ECS 2 and ECS 4. The IT department wants to view the traffic data in detail.
Procedure
Step 1: Create a flow log
- Log on to the VPC console.
- In the left-side navigation pane, choose .
If you use the flow log feature for the first time, perform the following operations:
Click Authorize Now and click Confirm Authorization Policy. You must complete the authorization to ensure that the flow log can be imported to Simple Log Service.
Click Activate Now to enable the flow log feature.
In the top navigation bar, select the region where you want to create the flow log.
In this example, select the region where the VPC is deployed.
On the Flow Log page, click Create a flow log.
In the Create a flow log dialog box, set the following parameters and click OK.
Parameter | Description |
Flow Log Name | Enter a name for the flow log. In this example, ECS2_to_ECS4 is used. |
Resource Type | Select the type of resource for which you want to capture traffic. In this example, ENI is selected. |
Resource Instance | Select an ENI.
|
Data Transfer Type | Data Transfer Type: Select the type of traffic data that you want to capture. In this example, All is selected. |
Project | Select the type of project to manage the captured traffic. In this example, Create Project is selected. |
Logstore | Select the type of Logstore to store the captured traffic. In this example, Create Logstore is selected. |
Enable Log Analysis Report | In this example, this feature is enabled. After you turn on the switch, Simple Log Service indexing is enabled and a dashboard for the Logstore is created. Then, you can consume the log data by using SQL queries and analyze the log data on the dashboard. Simple Log Service dashboards are free of charge. However, Simple Log Service indexing is billed based on data usage. For more information, see Simple Log Service billing. |
Sampling Interval (Minutes) | Specify the sampling interval. You can specify 1 minute, 5 minutes, or 10 minutes. In this example, the sampling interval is 10 minutes. |
Description | Enter a description for the flow log. |
Step 2: View the flow log
View the traffic data generated when ECS 2 accesses ECS 4.
On the Flow Log page, find the flow log and click the name of the Logstore in the Simple Log Service column.
Query the traffic data generated when ECS 2 accesses ECS 4 by performing the steps in the following figure.
Number
Description
1
Enter the following SQL statement to aggregate and sort the traffic data generated when ECS 2 accesses ECS 4:
eni-id: eni-hp3g87********po6zpp and dstaddr: "10.X.X.231" | select date_format(from_unixtime(__time__ - __time__% 60), '%H:%i:%S') as time, dstaddr,sum(bytes*8/("end"-start)) as bandwidth group by time,dstaddr order by time asc limit 1000
The SQL statement specifies the following parameters: time, bandwidth (bit/s), and dstaddr (destination address). time and dstaddr are aggregate columns and are sorted in ascending order of time. In this case, 1,000 log entries are retrieved. The following section describes the parameters:
eni-id: the ENI ID of ECS 2.
dstaddr: the private IP address of ECS 4.
Set other parameters to the values shown in this example.
NoteTo retrieve traffic data generated when ECS 4 accesses ECS 2, select ENI and then select ECS 4 when you create the flow log. When you enter an SQL statement, set
eni-id
to the ENI ID of ECS4 and setdstaddr
to the private IP address of ECS2. Do not change other operations.2
Select the time period that you want to query.
3
Click the Graph tab and click to select a chart type.
4
In the Common Settings section, set the following parameters:
Axis X Field: Set the value to time.
Axis Y Field: Set the value to bandwidth.
Aggregate Column: Set the value to dstaddr.
Format: Set the value to bps, Kbps, Mbps.
Keep the default settings for other parameters.
5
Click Add to New Dashboard and set the following parameters in the dialog box that appears:
Operation: Create Dashboard is used in this example.
Layout Mode: Grid Layout is used in this example.
Dashboard Name: Enter a name for the dashboard. In this case, ECS2_to_ECS4 is entered.
You can view information about the flow log on the dashboard.
6
Click Search & Analyze to view the traffic data generated when ECS 2 accesses ECS 4.