Skip to content

Commit 0ed7dd9

Browse files
authored
Merge pull request #1743 from ioito/automated-cherry-pick-of-#1742-upstream-release-4.0
Automated cherry pick of #1742: fix(meter): vm out metric
2 parents 5f51b79 + ebe8cfe commit 0ed7dd9

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

pkg/cloudprovider/metrics.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ const (
150150
// 虚拟机网络出速率
151151
// 支持平台: huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack, qcloud, volcengine
152152
VM_METRIC_TYPE_NET_BPS_TX TMetricType = "vm_netio.bps_sent"
153+
// 虚拟机外网出带宽使用率
154+
// 支持平台: qcloud, aliyun
155+
VM_METRIC_TYPE_NET_OUT_BANDWIDTH_USAGE TMetricType = "vm_netio.out_bandwidth_usage"
153156

154157
// 虚拟机TCP连接数
155158
// 支持平台: aliyun, apsara, volcengine
@@ -291,8 +294,10 @@ const (
291294
METRIC_TAG_REQUST_4XX = "4xx"
292295
METRIC_TAG_REQUST_5XX = "5xx"
293296

294-
METRIC_TAG_NET_TYPE = "net_type"
297+
METRIC_TAG_NET_TYPE = "net_type"
298+
// 外网
295299
METRIC_TAG_NET_TYPE_INTERNET = "internet"
300+
// 内网
296301
METRIC_TAG_NET_TYPE_INTRANET = "intranet"
297302

298303
METRIC_TAG_TYPE_DISK_TYPE = "disk_type"
@@ -391,6 +396,7 @@ var (
391396

392397
VM_METRIC_TYPE_NET_BPS_RX,
393398
VM_METRIC_TYPE_NET_BPS_TX,
399+
VM_METRIC_TYPE_NET_OUT_BANDWIDTH_USAGE,
394400
VM_METRIC_TYPE_NET_TCP_CONNECTION,
395401

396402
VM_METRIC_TYPE_PROCESS_NUMBER,

pkg/multicloud/aliyun/monitor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ func (self *SAliyunClient) GetEcsMetrics(opts *cloudprovider.MetricListOptions)
345345
"IntranetOutRate": cloudprovider.METRIC_TAG_NET_TYPE_INTRANET,
346346
}
347347
tagKey = cloudprovider.METRIC_TAG_NET_TYPE
348+
case cloudprovider.VM_METRIC_TYPE_NET_OUT_BANDWIDTH_USAGE:
349+
metricTags = map[string]string{
350+
"VPC_PublicIP_InternetOutRate_Percent": cloudprovider.METRIC_TAG_NET_TYPE_INTERNET,
351+
}
352+
tagKey = cloudprovider.METRIC_TAG_NET_TYPE
348353
case cloudprovider.VM_METRIC_TYPE_DISK_IO_READ_BPS:
349354
metricTags = map[string]string{
350355
"DiskReadBPS": "",

pkg/multicloud/aliyun/shell/monitor.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ func init() {
5050
})
5151

5252
shellutils.R(&cloudprovider.MetricListOptions{}, "metric-list", "List metrics in a namespace", func(cli *aliyun.SRegion, args *cloudprovider.MetricListOptions) error {
53+
if args.StartTime.IsZero() {
54+
args.StartTime = time.Now().Add(-time.Minute * 20)
55+
}
56+
if args.EndTime.IsZero() {
57+
args.EndTime = time.Now()
58+
}
5359
metrics, err := cli.GetClient().GetMetrics(args)
5460
if err != nil {
5561
return err
@@ -75,13 +81,17 @@ func init() {
7581
if err != nil {
7682
return err
7783
}
84+
} else {
85+
since = time.Now().Add(-time.Minute * 20)
7886
}
7987
var until time.Time
8088
if len(args.Until) > 0 {
8189
until, err = timeutils.ParseTimeStr(args.Until)
8290
if err != nil {
8391
return err
8492
}
93+
} else {
94+
until = time.Now().Add(-time.Minute * 10)
8595
}
8696
data, err := cli.FetchMetricData(args.METRIC, args.NAMESPACE, since, until)
8797
if err != nil {

pkg/multicloud/qcloud/monitor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ func (self *SQcloudClient) GetEcsMetrics(opts *cloudprovider.MetricListOptions)
166166
"lanIntraffic": cloudprovider.METRIC_TAG_NET_TYPE + ":" + cloudprovider.METRIC_TAG_NET_TYPE_INTRANET,
167167
"WanIntraffic": cloudprovider.METRIC_TAG_NET_TYPE + ":" + cloudprovider.METRIC_TAG_NET_TYPE_INTERNET,
168168
},
169+
cloudprovider.VM_METRIC_TYPE_NET_OUT_BANDWIDTH_USAGE: {
170+
"Outratio": cloudprovider.METRIC_TAG_NET_TYPE + ":" + cloudprovider.METRIC_TAG_NET_TYPE_INTERNET,
171+
},
169172
} {
170173
for metricName, tag := range metricNames {
171174
metrics, err := self.GetMonitorData("QCE/CVM", metricName, 60, opts.StartTime, opts.EndTime, opts.RegionExtId, "InstanceId", opts.ResourceIds)

0 commit comments

Comments
 (0)