mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
feat(cloudmon): support huaweistack monitor metric
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
_ "yunion.io/x/onecloud/pkg/multicloud/esxi/provider"
|
||||
_ "yunion.io/x/onecloud/pkg/multicloud/google/provider"
|
||||
_ "yunion.io/x/onecloud/pkg/multicloud/huawei/provider"
|
||||
_ "yunion.io/x/onecloud/pkg/multicloud/huaweistack/provider"
|
||||
_ "yunion.io/x/onecloud/pkg/multicloud/qcloud/provider"
|
||||
_ "yunion.io/x/onecloud/pkg/multicloud/zstack/provider"
|
||||
)
|
||||
|
||||
@@ -110,24 +110,30 @@ func (self *CloudReportBase) InitProviderInstance() (cloudprovider.ICloudProvide
|
||||
return nil, errors.Wrap(err, "getCloudAccount error")
|
||||
}
|
||||
endpoints := cloudprovider.SApsaraEndpoints{}
|
||||
hwendpoints := cloudprovider.SHuaweiCloudStackEndpoints{}
|
||||
options, err := cloudAccout.Get("options")
|
||||
if err == nil {
|
||||
err := options.Unmarshal(&endpoints)
|
||||
if err != nil {
|
||||
log.Errorf("Unmarshal SApsaraEndpoints err:%v", err)
|
||||
}
|
||||
err = options.Unmarshal(&hwendpoints)
|
||||
if err != nil {
|
||||
log.Errorf("Unmarshal SHuaweiCloudStackEndpoints err:%v", err)
|
||||
}
|
||||
} else {
|
||||
log.Errorf("get cloudAccout options err:%v", err)
|
||||
}
|
||||
cfg := cloudprovider.ProviderConfig{
|
||||
Id: self.SProvider.Id,
|
||||
Name: self.SProvider.Name,
|
||||
URL: self.SProvider.AccessUrl,
|
||||
Account: self.SProvider.Account,
|
||||
Secret: secretDe,
|
||||
Vendor: self.SProvider.Provider,
|
||||
ProxyFunc: proxyFunc,
|
||||
SApsaraEndpoints: endpoints,
|
||||
Id: self.SProvider.Id,
|
||||
Name: self.SProvider.Name,
|
||||
URL: self.SProvider.AccessUrl,
|
||||
Account: self.SProvider.Account,
|
||||
Secret: secretDe,
|
||||
Vendor: self.SProvider.Provider,
|
||||
ProxyFunc: proxyFunc,
|
||||
SApsaraEndpoints: endpoints,
|
||||
SHuaweiCloudStackEndpoints: hwendpoints,
|
||||
}
|
||||
return cloudprovider.GetProvider(cfg)
|
||||
}
|
||||
@@ -155,7 +161,9 @@ func (self *CloudReportBase) GetAllRegionOfServers(servers []jsonutils.JSONObjec
|
||||
extranleIdMap[region_external_id] = ""
|
||||
region, err := providerInstance.GetIRegionById(region_external_id)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
name, _ := server.GetString("name")
|
||||
log.Errorf("name:%s,region_external_id:%s,err:%v", name, region_external_id, err)
|
||||
continue
|
||||
}
|
||||
regionServerList = append(regionServerList, region)
|
||||
regionServers := make([]jsonutils.JSONObject, 0)
|
||||
|
||||
@@ -67,7 +67,14 @@ type ReportOptions struct {
|
||||
Interval string `help:"interval""`
|
||||
SinceTime string `help:"sinceTime"`
|
||||
EndTime string `help:"endTime"`
|
||||
Provider []string `help:"List objects from the provider" choices:"VMware|Aliyun|Qcloud|Azure|Aws|Huawei|ZStack|Google|Apsara" json:"provider,omitempty"`
|
||||
Provider []string `help:"List objects from the provider" choices:"VMware|Aliyun|Qcloud|Azure|Aws|Huawei|ZStack|Google|Apsara|HuaweiCloudStack" json:"provider,omitempty"`
|
||||
PingProbeOptions
|
||||
}
|
||||
|
||||
type PingProbeOptions struct {
|
||||
Debug bool `help:"debug"`
|
||||
ProbeCount int `help:"probe count, default is 3" default:"3"`
|
||||
TimeoutSecond int `help:"probe timeout in second, default is 1 second" default:"1"`
|
||||
}
|
||||
|
||||
var InstanceProviders = "Aliyun,Azure,Aws,Qcloud,VMWare,Huawei,Openstack,Ucloud,ZStack"
|
||||
|
||||
@@ -12,6 +12,11 @@ import (
|
||||
func init() {
|
||||
factory := SHwCloudReportFactory{}
|
||||
common.RegisterFactory(&factory)
|
||||
|
||||
stackFactory := SHwStackCloudReportFactory{
|
||||
&SHwCloudReportFactory{},
|
||||
}
|
||||
common.RegisterFactory(&stackFactory)
|
||||
}
|
||||
|
||||
type SHwCloudReportFactory struct {
|
||||
@@ -83,3 +88,11 @@ func (self *SHwCloudReport) Report() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SHwStackCloudReportFactory struct {
|
||||
*SHwCloudReportFactory
|
||||
}
|
||||
|
||||
func (self *SHwStackCloudReportFactory) GetId() string {
|
||||
return compute.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK
|
||||
}
|
||||
|
||||
@@ -8,16 +8,17 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudmon/collectors/common"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/huawei"
|
||||
hw_moudules "yunion.io/x/onecloud/pkg/multicloud/huawei/client/modules"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/huaweistack"
|
||||
"yunion.io/x/onecloud/pkg/util/influxdb"
|
||||
)
|
||||
|
||||
func (self *SHwCloudReport) collectRegionMetricOfHost(region cloudprovider.ICloudRegion, servers []jsonutils.JSONObject) error {
|
||||
dataList := make([]influxdb.SMetricData, 0)
|
||||
hwReg := region.(*huawei.SRegion)
|
||||
since, until, err := common.TimeRangeFromArgs(self.Args)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -38,8 +39,7 @@ func (self *SHwCloudReport) collectRegionMetricOfHost(region cloudprovider.IClou
|
||||
hwMeta.Dimensions = append(hwMeta.Dimensions, hw_moudules.SMetricDimension{Name: "instance_id", Value: instanceId})
|
||||
metas = append(metas, hwMeta)
|
||||
}
|
||||
|
||||
metricDatas, err := hwReg.GetMetricsData(metas, since, until)
|
||||
metricDatas, err := self.GetMetricData(region, metas, since, until)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
continue
|
||||
@@ -325,3 +325,16 @@ func (self *SHwCloudReport) collectMetricFromThisServer(server jsonutils.JSONObj
|
||||
self.AddMetricTag(&metric, common.OtherVmTags)
|
||||
return metric, nil
|
||||
}
|
||||
|
||||
func (self *SHwCloudReport) GetMetricData(region cloudprovider.ICloudRegion, metrics []hw_moudules.SMetricMeta,
|
||||
since time.Time, until time.Time) ([]hw_moudules.SMetricData, error) {
|
||||
switch self.SProvider.Provider {
|
||||
case compute.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK:
|
||||
hwReg := region.(*huaweistack.SRegion)
|
||||
return hwReg.GetMetricsData(metrics, since, until)
|
||||
default:
|
||||
hwReg := region.(*huawei.SRegion)
|
||||
return hwReg.GetMetricsData(metrics, since, until)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
hw_mod "yunion.io/x/onecloud/pkg/multicloud/huawei/client/modules"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/huaweistack/client/manager"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/huaweistack/client/requests"
|
||||
)
|
||||
@@ -42,41 +43,8 @@ func NewCloudEyeManager(cfg manager.IManagerConfig) *SCloudEyeManager {
|
||||
}}
|
||||
}
|
||||
|
||||
type SMetricDimension struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type SDatapoint struct {
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Max float64 `json:"max,omitzero"`
|
||||
Min float64 `json:"min,omitzero"`
|
||||
Average float64 `json:"average,omitzero"`
|
||||
Sum float64 `json:"sum,omitzero"`
|
||||
Variance float64 `json:"variance,omitzero"`
|
||||
}
|
||||
|
||||
type SMetricData struct {
|
||||
SMetricMeta
|
||||
|
||||
Datapoints []SDatapoint
|
||||
}
|
||||
|
||||
type SMetricMeta struct {
|
||||
SMetric
|
||||
|
||||
Unit string `json:"unit"`
|
||||
}
|
||||
|
||||
type SMetric struct {
|
||||
MetricName string `json:"metric_name"`
|
||||
Namespace string `json:"namespace"`
|
||||
|
||||
Dimensions []SMetricDimension `json:"dimensions"`
|
||||
}
|
||||
|
||||
func (ces *SCloudEyeManager) ListMetrics() ([]SMetricMeta, error) {
|
||||
metrics := make([]SMetricMeta, 0)
|
||||
func (ces *SCloudEyeManager) ListMetrics() ([]hw_mod.SMetricMeta, error) {
|
||||
metrics := make([]hw_mod.SMetricMeta, 0)
|
||||
next := ""
|
||||
for {
|
||||
marker, data, err := ces.listMetricsInternal(next)
|
||||
@@ -92,7 +60,7 @@ func (ces *SCloudEyeManager) ListMetrics() ([]SMetricMeta, error) {
|
||||
return metrics, nil
|
||||
}
|
||||
|
||||
func (ces *SCloudEyeManager) listMetricsInternal(start string) (string, []SMetricMeta, error) {
|
||||
func (ces *SCloudEyeManager) listMetricsInternal(start string) (string, []hw_mod.SMetricMeta, error) {
|
||||
request := requests.NewResourceRequest(ces.GetEndpoint(), "GET", string(ces.ServiceName), ces.version, ces.Region, ces.ProjectId, ces.ResourceKeyword)
|
||||
request.AddQueryParam("limit", "1000")
|
||||
if len(start) > 0 {
|
||||
@@ -103,7 +71,7 @@ func (ces *SCloudEyeManager) listMetricsInternal(start string) (string, []SMetri
|
||||
return "", nil, errors.Wrap(err, "ces.jsonRequest")
|
||||
}
|
||||
marker, _ := resp.GetString("meta_data", "marker")
|
||||
metrics := make([]SMetricMeta, 0)
|
||||
metrics := make([]hw_mod.SMetricMeta, 0)
|
||||
err = resp.Unmarshal(&metrics, "metrics")
|
||||
if err != nil {
|
||||
return "", nil, errors.Wrap(err, "resp.Unmarshal metrics")
|
||||
@@ -112,7 +80,7 @@ func (ces *SCloudEyeManager) listMetricsInternal(start string) (string, []SMetri
|
||||
}
|
||||
|
||||
type SBatchQueryMetricDataInput struct {
|
||||
Metrics []SMetric `json:"metrics"`
|
||||
Metrics []hw_mod.SMetric `json:"metrics"`
|
||||
|
||||
From int64 `json:"from"`
|
||||
To int64 `json:"to"`
|
||||
@@ -120,11 +88,11 @@ type SBatchQueryMetricDataInput struct {
|
||||
Filter string `json:"filter"`
|
||||
}
|
||||
|
||||
func (ces *SCloudEyeManager) GetMetricsData(metrics []SMetricMeta, since time.Time, until time.Time) ([]SMetricData, error) {
|
||||
func (ces *SCloudEyeManager) GetMetricsData(metrics []hw_mod.SMetricMeta, since time.Time, until time.Time) ([]hw_mod.SMetricData, error) {
|
||||
if len(metrics) > 10 {
|
||||
return nil, errors.Wrap(httperrors.ErrTooLarge, "request more than 10 metrics")
|
||||
}
|
||||
metricReq := make([]SMetric, len(metrics))
|
||||
metricReq := make([]hw_mod.SMetric, len(metrics))
|
||||
for i := range metrics {
|
||||
metricReq[i] = metrics[i].SMetric
|
||||
}
|
||||
@@ -143,7 +111,7 @@ func (ces *SCloudEyeManager) GetMetricsData(metrics []SMetricMeta, since time.Ti
|
||||
return nil, errors.Wrap(err, "ces.jsonRequest")
|
||||
}
|
||||
//log.Debugf("%s", resp)
|
||||
result := make([]SMetricData, 0)
|
||||
result := make([]hw_mod.SMetricData, 0)
|
||||
err = resp.Unmarshal(&result, "metrics")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "resp.Unmarshal")
|
||||
|
||||
@@ -17,7 +17,7 @@ package huaweistack
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/multicloud/huaweistack/client/modules"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/huawei/client/modules"
|
||||
)
|
||||
|
||||
func (r *SRegion) GetMetrics() ([]modules.SMetricMeta, error) {
|
||||
|
||||
Reference in New Issue
Block a user