fix(cloudmon): 飞天云监控中拉取metadata信息

This commit is contained in:
zhaoxiangchun
2021-12-17 11:22:49 +08:00
parent 4eb1f866f0
commit 488f7d30b2
9 changed files with 41 additions and 12 deletions

View File

@@ -164,11 +164,6 @@ func (self *SAliCloudReport) collectMetricFromThisServer(server jsonutils.JSONOb
Key: pairsKey,
Value: strconv.FormatFloat(fieldValue, 'E', -1, 64),
})
if common.MonType(self.Operator) == common.SERVER {
self.AddMetricTag(&metric, common.OtherVmTags)
} else {
self.AddMetricTag(&metric, common.OtherTags)
}
metric.Name = measurement
return metric, nil
}

View File

@@ -27,6 +27,7 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudmon/collectors/common"
"yunion.io/x/onecloud/pkg/cloudprovider"
iden_modules "yunion.io/x/onecloud/pkg/mcclient/modules/identity"
"yunion.io/x/onecloud/pkg/multicloud/apsara"
"yunion.io/x/onecloud/pkg/util/influxdb"
)
@@ -92,6 +93,24 @@ func (self *SApsaraCloudReport) collectRegionMetricOfHost(region cloudprovider.I
log.Errorf("collect %s error: %v", metricName, err)
continue
}
project, err := self.GetResourceById(server.ProjectId, &iden_modules.Projects)
if err != nil {
log.Errorf("server: %s getProject: %s err: %v", server.Name, server.ProjectId, err)
continue
}
metaMap, _ := project.GetMap("metadata")
if len(metaMap) > 0 {
for key, valObj := range metaMap {
if strings.Contains(key, "user:") {
val, _ := valObj.GetString()
serverMetric.Tags = append(serverMetric.Tags, influxdb.SKeyValue{
Key: key,
Value: val,
})
}
}
}
dataList = append(dataList, serverMetric)
}
}
@@ -301,7 +320,6 @@ func (self *SApsaraCloudReport) collectMetricFromThisServer(server jsonutils.JSO
Key: pairsKey,
Value: strconv.FormatFloat(fieldValue, 'E', -1, 64),
})
self.AddMetricTag(&metric, common.OtherVmTags)
metric.Name = measurement
return metric, nil
}

View File

@@ -150,7 +150,6 @@ func (self *SAzureCloudReport) collectMetricFromThisServer(server jsonutils.JSON
Key: pairsKey,
Value: strconv.FormatFloat(fieldValue, 'E', -1, 64),
})
self.AddMetricTag(&metric, common.OtherVmTags)
datas = append(datas, metric)
}
}

View File

@@ -165,7 +165,12 @@ func (self *CloudReportBase) InitProviderInstance() (cloudprovider.ICloudProvide
Secret: secretDe,
Vendor: self.SProvider.Provider,
ProxyFunc: proxyFunc,
Options: options.(*jsonutils.JSONDict),
}
if options != nil {
cfg.Options = options.(*jsonutils.JSONDict)
defaultRegion, _ := options.GetString("default_region")
cfg.DefaultRegion = defaultRegion
}
return cloudprovider.GetProvider(cfg)
}

View File

@@ -422,6 +422,22 @@ func JsonToMetric(obj *jsonutils.JSONDict, name string, tags map[string]string,
Key: k, Value: val,
})
}
//if k == "metadata" {
// mValMap, err := v.GetMap()
// if err != nil {
// log.Errorf("get metadata value err: %v", err)
// continue
// }
// for mKey, mValObj := range mValMap {
// if strings.Contains(mKey, "sys") {
// mVal, _ := mValObj.GetString()
// tagPairs = append(tagPairs, influxdb.SKeyValue{
// Key: mKey,
// Value: mVal,
// })
// }
// }
//}
}
metric.Tags = tagPairs
metric.Metrics = metricPairs

View File

@@ -336,7 +336,6 @@ func (self *SHwCloudReport) collectMetricFromThisServer(server jsonutils.JSONObj
Value: strconv.FormatFloat(fieldValue, 'E', -1, 64),
})
metric.Name = measurement
self.AddMetricTag(&metric, common.OtherVmTags)
return metric, nil
}

View File

@@ -132,7 +132,6 @@ func (self *SJdCloudReport) collectMetricFromThisServer(server jsonutils.JSONObj
Value: strconv.FormatFloat(fieldValue, 'E', -1, 64),
})
metric.Name = measurement
self.AddMetricTag(&metric, common.OtherVmTags)
datas = append(datas, metric)
}
}

View File

@@ -186,7 +186,6 @@ func (self *SQCloudReport) collectMetricFromThisServer(server jsonutils.JSONObje
Key: pairsKey,
Value: strconv.FormatFloat(fieldValue, 'E', -1, 64),
})
self.AddMetricTag(&metric, common.OtherVmTags)
datas = append(datas, metric)
}
return datas, nil

View File

@@ -227,7 +227,6 @@ func (self *SEsxiCloudReport) collectMetricFromThisServer_(server jsonutils.JSON
if monType == common.TYPE_HOSTSYSTEM {
self.AddMetricTag(&metric, common.OtherHostTag)
} else {
self.AddMetricTag(&metric, common.OtherVmTags)
}
datas = append(datas, metric)
}