mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #12203 from zexi/azure-classic-metrics
feat(cloudmon): support classic vm metrics
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudmon/collectors/common"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -41,37 +42,49 @@ func (self *SAzureCloudReport) collectRegionMetricOfHost(region cloudprovider.IC
|
||||
return err
|
||||
}
|
||||
for _, server := range servers {
|
||||
srvId, _ := server.GetString("id")
|
||||
srvName, _ := server.GetString("name")
|
||||
srvPrefix := srvId + "/" + "srvName"
|
||||
external_id, err := server.GetString("external_id")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
classicKey := "microsoft.classiccompute/virtualmachines"
|
||||
ns := "Microsoft.Compute/virtualMachines"
|
||||
metricSpecs := azureMetricSpecs
|
||||
if strings.Contains(strings.ToLower(external_id), classicKey) {
|
||||
ns = classicKey
|
||||
metricSpecs = azureClassicMetricsSpec
|
||||
}
|
||||
metricNameArr := make([]string, 0)
|
||||
for metricName, _ := range azureMetricSpecs {
|
||||
for metricName := range metricSpecs {
|
||||
metricNameArr = append(metricNameArr, metricName)
|
||||
}
|
||||
metricNames := strings.Join(metricNameArr, ",")
|
||||
rtnMetrics, err := azureReg.GetMonitorData(metricNames, "Microsoft.Compute/virtualMachines", external_id, since, until)
|
||||
azureReg.GetClient().Debug(true)
|
||||
rtnMetrics, err := azureReg.GetMonitorData(metricNames, ns, external_id, since, until)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
log.Errorf("get metrics for server %s error: %v", srvPrefix, err)
|
||||
continue
|
||||
}
|
||||
if rtnMetrics == nil || rtnMetrics.Value == nil {
|
||||
log.Warningf("server %s metrics is nil", srvPrefix)
|
||||
continue
|
||||
}
|
||||
for metricName, influxDbSpecs := range azureMetricSpecs {
|
||||
for metricName, influxDbSpecs := range metricSpecs {
|
||||
for _, value := range *rtnMetrics.Value {
|
||||
if value.Name.LocalizedValue != nil {
|
||||
if metricName == *(value.Name.LocalizedValue) {
|
||||
if metricName == *(value.Name.LocalizedValue) || (value.Name.Value != nil && *value.Name.Value == metricName) {
|
||||
metric, err := common.FillVMCapacity(server.(*jsonutils.JSONDict))
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrapf(err, "fill vm %q capacity", srvPrefix)
|
||||
}
|
||||
dataList = append(dataList, metric)
|
||||
if value.Timeseries != nil {
|
||||
for _, timeserie := range *value.Timeseries {
|
||||
serverMetric, err := self.collectMetricFromThisServer(server, timeserie, influxDbSpecs)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrapf(err, "collect metrics from server %q", srvPrefix)
|
||||
}
|
||||
dataList = append(dataList, serverMetric...)
|
||||
}
|
||||
@@ -82,7 +95,7 @@ func (self *SAzureCloudReport) collectRegionMetricOfHost(region cloudprovider.IC
|
||||
}
|
||||
err = common.SendMetrics(self.Session, dataList, self.Args.Debug, "")
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
log.Errorf("send %q metrics error: %v", srvName, err)
|
||||
}
|
||||
dataList = dataList[:0]
|
||||
}
|
||||
|
||||
@@ -119,13 +119,38 @@ const (
|
||||
KEY_USABLE = "usable"
|
||||
)
|
||||
|
||||
//multiCloud查询指标列表组装
|
||||
// multiCloud查询指标列表组装
|
||||
const (
|
||||
MetricKeyPercentageCPU = "Percentage CPU"
|
||||
MetricKeyNetworkInTotal = "Network In Total"
|
||||
MetricKeyNetworkOutTotal = "Network Out Total"
|
||||
MetricKeyDiskReadBytes = "Disk Read Bytes"
|
||||
MetricKeyDiskWriteBytes = "Disk Write Bytes"
|
||||
MetricKeyDiskReadOPS = "Disk Read Operations/Sec"
|
||||
MetricKeyDiskWriteOPS = "Disk Write Operations/Sec"
|
||||
|
||||
MetricKeyClassicNetworkIn = "Network In"
|
||||
MetricKeyClassicNetworkOut = "Network Out"
|
||||
MetricKeyClassicDiskReadBPS = "Disk Read Bytes/Sec"
|
||||
MetricKeyClassicDiskWriteBPS = "Disk Write Bytes/Sec"
|
||||
)
|
||||
|
||||
var azureMetricSpecs = map[string][]string{
|
||||
"Percentage CPU": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_CPU_USAGE},
|
||||
"Network In Total": {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_NET_BPS_RX},
|
||||
"Network Out Total": {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_NET_BPS_TX},
|
||||
"Disk Read Bytes": {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_DISK_READ_BPS},
|
||||
"Disk Write Bytes": {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_DISK_WRITE_BPS},
|
||||
"Disk Read Operations/Sec": {DEFAULT_STATISTICS, UNIT_COUNT_SEC, INFLUXDB_FIELD_DISK_READ_IOPS},
|
||||
"Disk Write Operations/Sec": {DEFAULT_STATISTICS, UNIT_COUNT_SEC, INFLUXDB_FIELD_DISK_WRITE_BPS},
|
||||
MetricKeyPercentageCPU: {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_CPU_USAGE},
|
||||
MetricKeyNetworkInTotal: {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_NET_BPS_RX},
|
||||
MetricKeyNetworkOutTotal: {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_NET_BPS_TX},
|
||||
MetricKeyDiskReadBytes: {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_DISK_READ_BPS},
|
||||
MetricKeyDiskWriteBytes: {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_DISK_WRITE_BPS},
|
||||
MetricKeyDiskReadOPS: {DEFAULT_STATISTICS, UNIT_COUNT_SEC, INFLUXDB_FIELD_DISK_READ_IOPS},
|
||||
MetricKeyDiskWriteOPS: {DEFAULT_STATISTICS, UNIT_COUNT_SEC, INFLUXDB_FIELD_DISK_WRITE_IOPS},
|
||||
}
|
||||
|
||||
var azureClassicMetricsSpec = map[string][]string{
|
||||
MetricKeyPercentageCPU: {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_CPU_USAGE},
|
||||
MetricKeyClassicNetworkIn: {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_NET_BPS_RX},
|
||||
MetricKeyClassicNetworkOut: {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_NET_BPS_TX},
|
||||
MetricKeyClassicDiskReadBPS: {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_DISK_READ_BPS},
|
||||
MetricKeyClassicDiskWriteBPS: {DEFAULT_STATISTICS, UNIT_MEM, INFLUXDB_FIELD_DISK_WRITE_BPS},
|
||||
MetricKeyDiskReadOPS: {DEFAULT_STATISTICS, UNIT_COUNT_SEC, INFLUXDB_FIELD_DISK_READ_IOPS},
|
||||
MetricKeyDiskWriteOPS: {DEFAULT_STATISTICS, UNIT_COUNT_SEC, INFLUXDB_FIELD_DISK_WRITE_IOPS},
|
||||
}
|
||||
|
||||
@@ -129,14 +129,14 @@ func (self *CloudReportBase) InitProviderInstance() (cloudprovider.ICloudProvide
|
||||
if err == nil {
|
||||
err := options.Unmarshal(&endpoints)
|
||||
if err != nil {
|
||||
log.Errorf("Unmarshal SApsaraEndpoints err:%v", err)
|
||||
log.Errorf("Unmarshal SApsaraEndpoints err: %v", err)
|
||||
}
|
||||
err = options.Unmarshal(&hwendpoints)
|
||||
if err != nil {
|
||||
log.Errorf("Unmarshal SHCSOEndpoints err:%v", err)
|
||||
log.Errorf("Unmarshal SHCSOEndpoints err: %v", err)
|
||||
}
|
||||
} else {
|
||||
log.Errorf("get cloudAccout options err:%v", err)
|
||||
log.Errorf("get cloudAccout options err: %v", err)
|
||||
}
|
||||
cfg := cloudprovider.ProviderConfig{
|
||||
Id: self.SProvider.Id,
|
||||
|
||||
Reference in New Issue
Block a user