mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix(region): volcengine monitor (#18557)
This commit is contained in:
@@ -83,7 +83,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231101115834-178d1dcb6b32
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231103051422-72246278640e
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
|
||||
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19
|
||||
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
|
||||
|
||||
@@ -1179,8 +1179,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231101115834-178d1dcb6b32 h1:NfV/gBRqYsyuG7cdGZcsLDfVFnRprD8e1LqhekPHHOo=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231101115834-178d1dcb6b32/go.mod h1:McRjoG2gaOUisB+Qa41kLCNZhr0lsCu4apEjTiphXVY=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231103051422-72246278640e h1:qQ0xQBJADMkUYcxlKbnpNtXZjrjvJAebtP19MlkyeY8=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231103051422-72246278640e/go.mod h1:McRjoG2gaOUisB+Qa41kLCNZhr0lsCu4apEjTiphXVY=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package providerdriver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/util/influxdb"
|
||||
)
|
||||
|
||||
type VolcEngineCollect struct {
|
||||
SBaseCollectDriver
|
||||
}
|
||||
|
||||
func (self *VolcEngineCollect) GetProvider() string {
|
||||
return api.CLOUD_PROVIDER_VOLCENGINE
|
||||
}
|
||||
|
||||
func (self *VolcEngineCollect) IsSupportMetrics() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(&VolcEngineCollect{})
|
||||
}
|
||||
|
||||
func (self *VolcEngineCollect) CollectAccountMetrics(ctx context.Context, account api.CloudaccountDetail) (influxdb.SMetricData, error) {
|
||||
metric := influxdb.SMetricData{
|
||||
Name: string(cloudprovider.METRIC_RESOURCE_TYPE_CLOUD_ACCOUNT),
|
||||
Timestamp: time.Now(),
|
||||
Tags: []influxdb.SKeyValue{},
|
||||
Metrics: []influxdb.SKeyValue{},
|
||||
}
|
||||
for k, v := range account.GetMetricTags() {
|
||||
metric.Tags = append([]influxdb.SKeyValue{
|
||||
{
|
||||
Key: k,
|
||||
Value: v,
|
||||
},
|
||||
}, metric.Tags...)
|
||||
}
|
||||
for k, v := range account.GetMetricPairs() {
|
||||
metric.Metrics = append([]influxdb.SKeyValue{
|
||||
{
|
||||
Key: k,
|
||||
Value: v,
|
||||
},
|
||||
}, metric.Metrics...)
|
||||
}
|
||||
return metric, nil
|
||||
}
|
||||
|
||||
func (self *VolcEngineCollect) CollectServerMetrics(ctx context.Context, manager api.CloudproviderDetails, provider cloudprovider.ICloudProvider, res map[string]api.ServerDetails, start, end time.Time) error {
|
||||
metrics := []influxdb.SMetricData{}
|
||||
regionServers := map[string][]api.ServerDetails{}
|
||||
for i := range res {
|
||||
regionId := res[i].RegionExtId
|
||||
_, ok := regionServers[regionId]
|
||||
if !ok {
|
||||
regionServers[regionId] = []api.ServerDetails{}
|
||||
}
|
||||
regionServers[regionId] = append(regionServers[regionId], res[i])
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
var mu sync.Mutex
|
||||
for regionId, servers := range regionServers {
|
||||
wg.Add(1)
|
||||
go func(regionId string, servers []api.ServerDetails) {
|
||||
defer func() {
|
||||
wg.Done()
|
||||
}()
|
||||
data := []cloudprovider.MetricValues{}
|
||||
for i := 0; i < (len(servers)+9)/10; i++ {
|
||||
for _, metricType := range cloudprovider.ALL_VM_METRIC_TYPES {
|
||||
opts := &cloudprovider.MetricListOptions{
|
||||
ResourceType: cloudprovider.METRIC_RESOURCE_TYPE_SERVER,
|
||||
RegionExtId: regionId,
|
||||
MetricType: metricType,
|
||||
StartTime: start,
|
||||
EndTime: end,
|
||||
}
|
||||
last := (i + 1) * 10
|
||||
if last > len(servers) {
|
||||
last = len(servers)
|
||||
}
|
||||
for i := range servers[i*10 : last] {
|
||||
opts.ResourceIds = append(opts.ResourceIds, servers[i].ExternalId)
|
||||
}
|
||||
part, err := provider.GetMetrics(opts)
|
||||
if err != nil {
|
||||
if errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
|
||||
log.Errorf("get server %s(%s) error: %v", strings.Join(opts.ResourceIds, ","), regionId, err)
|
||||
continue
|
||||
}
|
||||
continue
|
||||
}
|
||||
data = append(data, part...)
|
||||
}
|
||||
}
|
||||
for _, value := range data {
|
||||
server, ok := res[value.Id]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
tags := []influxdb.SKeyValue{}
|
||||
for k, v := range server.GetMetricTags() {
|
||||
tags = append(tags, influxdb.SKeyValue{
|
||||
Key: k,
|
||||
Value: v,
|
||||
})
|
||||
}
|
||||
pairs := []influxdb.SKeyValue{}
|
||||
for k, v := range server.GetMetricPairs() {
|
||||
pairs = append(pairs, influxdb.SKeyValue{
|
||||
Key: k,
|
||||
Value: v,
|
||||
})
|
||||
}
|
||||
for _, v := range value.Values {
|
||||
metric := influxdb.SMetricData{
|
||||
Name: value.MetricType.Name(),
|
||||
Timestamp: v.Timestamp,
|
||||
Tags: []influxdb.SKeyValue{},
|
||||
Metrics: []influxdb.SKeyValue{
|
||||
{
|
||||
Key: value.MetricType.Key(),
|
||||
Value: strconv.FormatFloat(v.Value, 'E', -1, 64),
|
||||
},
|
||||
},
|
||||
}
|
||||
for k, v := range v.Tags {
|
||||
metric.Tags = append(metric.Tags, influxdb.SKeyValue{
|
||||
Key: k,
|
||||
Value: v,
|
||||
})
|
||||
}
|
||||
metric.Metrics = append(metric.Metrics, pairs...)
|
||||
metric.Tags = append(metric.Tags, tags...)
|
||||
mu.Lock()
|
||||
metrics = append(metrics, metric)
|
||||
mu.Unlock()
|
||||
}
|
||||
}
|
||||
}(regionId, servers)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
return self.sendMetrics(ctx, manager, "server", len(res), metrics)
|
||||
}
|
||||
@@ -884,7 +884,7 @@ func (drv *SManagedVirtualizedGuestDriver) RequestUndeployGuestOnHost(ctx contex
|
||||
|
||||
for _, disk := range disks {
|
||||
storage, _ := disk.GetStorage()
|
||||
if disk.AutoDelete && !utils.IsInStringArray(storage.StorageType, api.STORAGE_LOCAL_TYPES) {
|
||||
if !disk.AutoDelete && !utils.IsInStringArray(storage.StorageType, api.STORAGE_LOCAL_TYPES) && disk.DiskType != api.DISK_TYPE_SYS {
|
||||
idisk, err := disk.GetIDisk(ctx)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
|
||||
Vendored
+1
-1
@@ -1438,7 +1438,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231101115834-178d1dcb6b32
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231103051422-72246278640e
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+13
-13
@@ -121,10 +121,10 @@ const (
|
||||
RDS_METRIC_TYPE_INNODB_WRITE_BPS TMetricType = "rds_innodb.write_bps"
|
||||
|
||||
// 虚拟机CPU使用率
|
||||
// 支持平台: kvm, huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack, qcloud
|
||||
// 支持平台: kvm, huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack, qcloud, volcengine
|
||||
VM_METRIC_TYPE_CPU_USAGE TMetricType = "vm_cpu.usage_active"
|
||||
// 虚拟机内存使用率
|
||||
// 支持平台: kvm, aliyun, apsara, azure, esxi, bingocloud, jdcloud, ecloud, qcloud
|
||||
// 支持平台: kvm, aliyun, apsara, azure, esxi, bingocloud, jdcloud, ecloud, qcloud, volcengine
|
||||
VM_METRIC_TYPE_MEM_USAGE TMetricType = "vm_mem.used_percent"
|
||||
// 虚拟机磁盘使用率
|
||||
// 支持平台: aliyun, apsara, jdcloud, azure
|
||||
@@ -132,27 +132,27 @@ const (
|
||||
VM_METRIC_TYPE_DISK_USAGE TMetricType = "vm_disk.used_percent"
|
||||
|
||||
// 虚拟机磁盘读速率
|
||||
// 支持平台: huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack
|
||||
// 支持平台: huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack, volcengine
|
||||
VM_METRIC_TYPE_DISK_IO_READ_BPS TMetricType = "vm_diskio.read_bps"
|
||||
// 虚拟机磁盘写速率
|
||||
// 支持平台: huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack
|
||||
// 支持平台: huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack, volcengine
|
||||
VM_METRIC_TYPE_DISK_IO_WRITE_BPS TMetricType = "vm_diskio.write_bps"
|
||||
// 虚拟机磁盘读IOPS
|
||||
// 支持平台: huawei, aliyun, apsara, azure, google, bingocloud, aws, jdcloud, ecloud, zstack
|
||||
// 支持平台: huawei, aliyun, apsara, azure, google, bingocloud, aws, jdcloud, ecloud, zstack, volcengine
|
||||
VM_METRIC_TYPE_DISK_IO_READ_IOPS TMetricType = "vm_diskio.read_iops"
|
||||
// 虚拟机磁盘写IOPS
|
||||
// 支持平台: huawei, aliyun, apsara, azure, google, bingocloud, aws, jdcloud, ecloud, zstack
|
||||
// 支持平台: huawei, aliyun, apsara, azure, google, bingocloud, aws, jdcloud, ecloud, zstack, volcengine
|
||||
VM_METRIC_TYPE_DISK_IO_WRITE_IOPS TMetricType = "vm_diskio.write_iops"
|
||||
|
||||
// 虚拟机网络入速率
|
||||
// 支持平台: huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack, qcloud
|
||||
// 支持平台: huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack, qcloud, volcengine
|
||||
VM_METRIC_TYPE_NET_BPS_RX TMetricType = "vm_netio.bps_recv"
|
||||
// 虚拟机网络出速率
|
||||
// 支持平台: huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack, qcloud
|
||||
// 支持平台: huawei, aliyun, apsara, azure, esxi, google, bingocloud, aws, jdcloud, ecloud, zstack, qcloud, volcengine
|
||||
VM_METRIC_TYPE_NET_BPS_TX TMetricType = "vm_netio.bps_sent"
|
||||
|
||||
// 虚拟机TCP连接数
|
||||
// 支持平台: aliyun, apsara
|
||||
// 支持平台: aliyun, apsara, volcengine
|
||||
VM_METRIC_TYPE_NET_TCP_CONNECTION TMetricType = "vm_netio.tcp_connections"
|
||||
// 虚拟机进程监控
|
||||
// 支持平台: aliyun, apsara
|
||||
@@ -268,16 +268,16 @@ const (
|
||||
// 支持平台: huawei, aliyun, apsara
|
||||
BUCKET_METRYC_TYPE_REQ_COUNT TMetricType = "oss_req.req_count"
|
||||
// 服务端请求错误数量
|
||||
// 支持平台: aliyun, apsara
|
||||
// 支持平台: aliyun, apsara, volcengine
|
||||
BUCKET_METRIC_TYPE_REQ_5XX_COUNT TMetricType = "oss_req.5xx_count"
|
||||
// 服务端请求错误数量
|
||||
// 支持平台: aliyun, apsara
|
||||
// 支持平台: aliyun, apsara, volcengine
|
||||
BUCKET_METRIC_TYPE_REQ_4XX_COUNT TMetricType = "oss_req.4xx_count"
|
||||
// 重定向数量
|
||||
// 支持平台: aliyun, apsara
|
||||
// 支持平台: aliyun, apsara, volcengine
|
||||
BUCKET_METRIC_TYPE_REQ_3XX_COUNT TMetricType = "oss_req.3xx_count"
|
||||
// 正常请求数量
|
||||
// 支持平台: aliyun, apsara
|
||||
// 支持平台: aliyun, apsara, volcengine
|
||||
BUCKET_METRIC_TYPE_REQ_2XX_COUNT TMetricType = "oss_req.2xx_count"
|
||||
// 存储总容量(bit)
|
||||
// 支持平台: aliyun, apsara
|
||||
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
// Copyright 2023 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package volcengine
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/pkg/errors"
|
||||
)
|
||||
|
||||
func (self *SVolcEngineClient) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
switch opts.ResourceType {
|
||||
case cloudprovider.METRIC_RESOURCE_TYPE_SERVER:
|
||||
return self.GetEcsMetrics(opts)
|
||||
//case cloudprovider.METRIC_RESOURCE_TYPE_BUCKET:
|
||||
// return self.GetOssMetrics(opts)
|
||||
//case cloudprovider.METRIC_RESOURCE_TYPE_EIP:
|
||||
// return self.GetEipMetrics(opts)
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "%s", opts.ResourceType)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SVolcEngineClient) GetEcsMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
metricName, namespace, subNamespace := "", "VCM_ECS", "Instance"
|
||||
switch opts.MetricType {
|
||||
case cloudprovider.VM_METRIC_TYPE_CPU_USAGE:
|
||||
metricName = "CpuTotal"
|
||||
case cloudprovider.VM_METRIC_TYPE_NET_BPS_RX:
|
||||
metricName = "NetworkInRate"
|
||||
case cloudprovider.VM_METRIC_TYPE_NET_BPS_TX:
|
||||
metricName = "NetworkOutRate"
|
||||
case cloudprovider.VM_METRIC_TYPE_DISK_IO_READ_BPS:
|
||||
metricName, subNamespace = "DiskReadBytes", "Storage"
|
||||
case cloudprovider.VM_METRIC_TYPE_DISK_IO_WRITE_BPS:
|
||||
metricName, subNamespace = "DiskWriteBytes", "Storage"
|
||||
case cloudprovider.VM_METRIC_TYPE_DISK_IO_READ_IOPS:
|
||||
metricName, subNamespace = "DiskReadIOPS", "Storage"
|
||||
case cloudprovider.VM_METRIC_TYPE_DISK_IO_WRITE_IOPS:
|
||||
metricName, subNamespace = "DiskWriteIOPS", "Storage"
|
||||
case cloudprovider.VM_METRIC_TYPE_MEM_USAGE:
|
||||
metricName = "MemoryUsedUtilization"
|
||||
case cloudprovider.VM_METRIC_TYPE_DISK_USAGE:
|
||||
//metricName = "DiskUsageUtilization"
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "%s", opts.MetricType)
|
||||
case cloudprovider.VM_METRIC_TYPE_NET_TCP_CONNECTION:
|
||||
metricName = "NetTcpConnectionStatus"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "%s", opts.MetricType)
|
||||
}
|
||||
ret := []cloudprovider.MetricValues{}
|
||||
result, err := self.GetMetricData(opts.RegionExtId, opts.StartTime, opts.EndTime, namespace, subNamespace, metricName, opts.ResourceIds)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetMetricData")
|
||||
}
|
||||
for i := range result {
|
||||
id := ""
|
||||
for _, dim := range result[i].Dimensions {
|
||||
if dim.Name == "ResourceID" {
|
||||
id = dim.Value
|
||||
}
|
||||
}
|
||||
if len(id) == 0 {
|
||||
continue
|
||||
}
|
||||
values := []cloudprovider.MetricValue{}
|
||||
for _, v := range result[i].DataPoints {
|
||||
values = append(values, cloudprovider.MetricValue{
|
||||
Timestamp: time.Unix(v.Timestamp, 0),
|
||||
Value: v.Value,
|
||||
})
|
||||
}
|
||||
ret = append(ret, cloudprovider.MetricValues{
|
||||
Id: id,
|
||||
MetricType: opts.MetricType,
|
||||
Values: values,
|
||||
})
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
type SMetricData struct {
|
||||
Legend string
|
||||
Dimensions []struct {
|
||||
Name string
|
||||
Value string
|
||||
}
|
||||
DataPoints []struct {
|
||||
Timestamp int64
|
||||
Value float64
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SVolcEngineClient) GetMetricData(regionId string, start, end time.Time, namespace, subNamespace, metricName string, ids []string) ([]SMetricData, error) {
|
||||
instances := []interface{}{}
|
||||
for _, id := range ids {
|
||||
instances = append(instances, map[string]interface{}{
|
||||
"Dimensions": []map[string]interface{}{
|
||||
{
|
||||
"Name": "ResourceID",
|
||||
"Value": id,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
params := map[string]interface{}{
|
||||
"StartTime": start.UTC().Unix(),
|
||||
"EndTime": end.UTC().Unix(),
|
||||
"MetricName": metricName,
|
||||
"Namespace": namespace,
|
||||
"SubNamespace": subNamespace,
|
||||
"Period": "1m",
|
||||
"Instances": instances,
|
||||
}
|
||||
resp, err := self.monitorRequest(regionId, "GetMetricData", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetMetricData")
|
||||
}
|
||||
ret := []SMetricData{}
|
||||
err = resp.Unmarshal(&ret, "Data", "MetricDataResults")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SVolcEngineClient) GetOssMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
metricName, namespace, subNamespace := "", "VCM_TOS", ""
|
||||
switch opts.MetricType {
|
||||
case cloudprovider.BUCKET_METRIC_TYPE_REQ_2XX_COUNT:
|
||||
metricName, subNamespace = "2xxQPS", "bucket_status_code"
|
||||
case cloudprovider.BUCKET_METRIC_TYPE_REQ_3XX_COUNT:
|
||||
metricName, subNamespace = "3xxQPS", "bucket_status_code"
|
||||
case cloudprovider.BUCKET_METRIC_TYPE_REQ_4XX_COUNT:
|
||||
metricName, subNamespace = "4xxQPS", "bucket_status_code"
|
||||
case cloudprovider.BUCKET_METRIC_TYPE_REQ_5XX_COUNT:
|
||||
metricName, subNamespace = "5xxQPS", "bucket_status_code"
|
||||
case cloudprovider.BUCKET_METRIC_TYPE_STORAGE_SIZE:
|
||||
metricName, subNamespace = "BucketTotalStorage", "bucket_overview"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "%s", opts.MetricType)
|
||||
}
|
||||
ret := []cloudprovider.MetricValues{}
|
||||
result, err := self.GetMetricData(opts.RegionExtId, opts.StartTime, opts.EndTime, namespace, subNamespace, metricName, opts.ResourceIds)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetMetricData")
|
||||
}
|
||||
for i := range result {
|
||||
id := ""
|
||||
for _, dim := range result[i].Dimensions {
|
||||
if dim.Name == "ResourceID" {
|
||||
id = dim.Value
|
||||
}
|
||||
}
|
||||
if len(id) == 0 {
|
||||
continue
|
||||
}
|
||||
values := []cloudprovider.MetricValue{}
|
||||
for _, v := range result[i].DataPoints {
|
||||
values = append(values, cloudprovider.MetricValue{
|
||||
Timestamp: time.Unix(v.Timestamp, 0),
|
||||
Value: v.Value,
|
||||
})
|
||||
}
|
||||
ret = append(ret, cloudprovider.MetricValues{
|
||||
Id: id,
|
||||
MetricType: opts.MetricType,
|
||||
Values: values,
|
||||
})
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
+2
-3
@@ -73,12 +73,11 @@ func (subnet *SNetwork) GetStatus() string {
|
||||
}
|
||||
|
||||
func (subnet *SNetwork) Refresh() error {
|
||||
log.Debugf("Subnet refresh %s", subnet.SubnetId)
|
||||
new, err := subnet.wire.zone.region.GetSubnetAttributes(subnet.SubnetId)
|
||||
net, err := subnet.wire.zone.region.GetSubnetAttributes(subnet.SubnetId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jsonutils.Update(subnet, new)
|
||||
return jsonutils.Update(subnet, net)
|
||||
}
|
||||
|
||||
func (subnet *SNetwork) GetIWire() cloudprovider.ICloudWire {
|
||||
|
||||
+4
@@ -197,3 +197,7 @@ func (self *SVolcEngineProvider) GetSubAccounts() ([]cloudprovider.SSubAccount,
|
||||
func (self *SVolcEngineProvider) GetVersion() string {
|
||||
return volcengine.VOLCENGINE_API_VERSION
|
||||
}
|
||||
|
||||
func (self *SVolcEngineProvider) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
return self.client.GetMetrics(opts)
|
||||
}
|
||||
|
||||
+29
-13
@@ -40,20 +40,22 @@ const (
|
||||
CLOUD_PROVIDER_VOLCENGINE_CN = "火山云"
|
||||
CLOUD_PROVIDER_VOLCENGINE_EN = "VolcEngine"
|
||||
|
||||
VOLCENGINE_API_VERSION = "2020-04-01"
|
||||
VOLCENGINE_IAM_API_VERSION = "2021-08-01"
|
||||
VOLCENGINE_API_VERSION = "2020-04-01"
|
||||
VOLCENGINE_IAM_API_VERSION = "2021-08-01"
|
||||
VOLCENGINE_OBSERVE_API_VERSION = "2018-01-01"
|
||||
|
||||
VOLCENGINE_API = "open.volcengineapi.com"
|
||||
VOLCENGINE_IAM_API = "iam.volcengineapi.com"
|
||||
VOLCENGINE_TOS_API = "tos-cn-beijing.volces.com"
|
||||
|
||||
VOLCENGINE_SERVICE_ECS = "ecs"
|
||||
VOLCENGINE_SERVICE_VPC = "vpc"
|
||||
VOLCENGINE_SERVICE_NAT = "natgateway"
|
||||
VOLCENGINE_SERVICE_STORAGE = "storage_ebs"
|
||||
VOLCENGINE_SERVICE_IAM = "iam"
|
||||
VOLCENGINE_SERVICE_TOS = "tos"
|
||||
VOLCENGINE_DEFAULT_REGION = "cn-beijing"
|
||||
VOLCENGINE_SERVICE_ECS = "ecs"
|
||||
VOLCENGINE_SERVICE_VPC = "vpc"
|
||||
VOLCENGINE_SERVICE_NAT = "natgateway"
|
||||
VOLCENGINE_SERVICE_STORAGE = "storage_ebs"
|
||||
VOLCENGINE_SERVICE_IAM = "iam"
|
||||
VOLCENGINE_SERVICE_TOS = "tos"
|
||||
VOLCENGINE_SERVICE_OBSERVICE = "Volc_Observe"
|
||||
VOLCENGINE_DEFAULT_REGION = "cn-beijing"
|
||||
)
|
||||
|
||||
type VolcEngineClientConfig struct {
|
||||
@@ -267,14 +269,25 @@ func (self *sCred) Do(req *http.Request) (*http.Response, error) {
|
||||
return cli.Do(req)
|
||||
}
|
||||
|
||||
func (client *SVolcEngineClient) jsonRequest(cred sdk.Credentials, domain string, apiVersion string, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (client *SVolcEngineClient) monitorRequest(regionId, apiName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
cred := client.getSdkCredential(regionId, VOLCENGINE_SERVICE_OBSERVICE, "")
|
||||
return client.jsonRequest(cred, VOLCENGINE_API, VOLCENGINE_OBSERVE_API_VERSION, apiName, params)
|
||||
}
|
||||
|
||||
func (client *SVolcEngineClient) jsonRequest(cred sdk.Credentials, domain string, apiVersion string, apiName string, params interface{}) (jsonutils.JSONObject, error) {
|
||||
|
||||
query := url.Values{
|
||||
"Action": []string{apiName},
|
||||
"Version": []string{apiVersion},
|
||||
}
|
||||
for k, v := range params {
|
||||
query.Set(k, v)
|
||||
|
||||
var body interface{} = nil
|
||||
if _params, ok := params.(map[string]string); ok {
|
||||
for k, v := range _params {
|
||||
query.Set(k, v)
|
||||
}
|
||||
} else {
|
||||
body = params
|
||||
}
|
||||
|
||||
u := url.URL{
|
||||
@@ -301,8 +314,11 @@ func (client *SVolcEngineClient) jsonRequest(cred sdk.Credentials, domain string
|
||||
method = httputils.DELETE
|
||||
}
|
||||
}
|
||||
if cred.Service == VOLCENGINE_SERVICE_OBSERVICE {
|
||||
method = httputils.POST
|
||||
}
|
||||
|
||||
req := httputils.NewJsonRequest(method, u.String(), nil)
|
||||
req := httputils.NewJsonRequest(method, u.String(), body)
|
||||
vErr := &sVolcError{}
|
||||
_cli := &sCred{
|
||||
client: client,
|
||||
|
||||
Reference in New Issue
Block a user