update etcd metrics

Signed-off-by: huanggze <loganhuang@yunify.com>
This commit is contained in:
huanggze
2019-04-25 15:21:06 +08:00
committed by zryfish
parent ebd681770e
commit d8117e567c
2 changed files with 53 additions and 19 deletions

View File

@@ -750,7 +750,39 @@ func MonitorAllMetrics(monitoringRequest *client.MonitoringRequestParams, resour
go func(metricName string) {
queryType, params := AssembleComponentRequestInfo(monitoringRequest, metricName)
metricsStr := client.SendMonitoringRequest(client.SecondaryPrometheusEndpoint, queryType, params)
ch <- ReformatJson(metricsStr, metricName, map[string]string{"resource_name": monitoringRequest.ComponentName})
formattedJson := ReformatJson(metricsStr, metricName, map[string]string{"resource_name": monitoringRequest.ComponentName})
if metricName == "etcd_server_list" {
nodeMap := make(map[string]string, 0)
nodeAddress := GetNodeAddressInfo()
for nodeName, nodeInfo := range *nodeAddress {
var nodeIp string
for _, item := range nodeInfo {
if item.Type == v1.NodeInternalIP {
nodeIp = item.Address
break
}
}
nodeMap[nodeIp] = nodeName
}
// add node_name label to metrics
for i := 0; i < len(formattedJson.Data.Result); i++ {
metricDesc := formattedJson.Data.Result[i][ResultItemMetric]
metricDescMap, ensure := metricDesc.(map[string]interface{})
if ensure {
if nodeIp, exist := metricDescMap[ResultItemMetricNodeIp]; exist {
metricDescMap[ResultItemMetricNodeName] = nodeMap[nodeIp.(string)]
}
}
}
}
ch <- formattedJson
wg.Done()
}(metricName)
}