-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.适配广域网质量监控指标 2.适配ANC,cc,dli,vpc, 3.补充FunctionGraph,APIC,AS,CC,DLI,DRS,GaussDB,GaussDB Redis,NAT服务grafana模板 4.修改kafka模板样式
- Loading branch information
Showing
38 changed files
with
26,696 additions
and
3,446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package collector | ||
|
||
import ( | ||
"time" | ||
|
||
cesmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model" | ||
|
||
"github.com/huaweicloud/cloudeye-exporter/logs" | ||
) | ||
|
||
var ( | ||
ancInfo serversInfo | ||
dimConfigMap = map[string]map[string]string{ | ||
"anc_anc_id": { | ||
"resourceType": "ancs", | ||
"providerId": "anc", | ||
"nameInSubResource": "anc_name", | ||
}, | ||
"anc_service_id": { | ||
"resourceType": "services", | ||
"providerId": "anc", | ||
"nameInSubResource": "anc_service_name", | ||
}, | ||
"anc_membergroup_id": { | ||
"resourceType": "member-groups", | ||
"providerId": "anc", | ||
"nameInSubResource": "member_group_name", | ||
}, | ||
} | ||
) | ||
|
||
type ANCInfo struct{} | ||
|
||
func (getter ANCInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.MetricInfoList) { | ||
|
||
ancInfo.Lock() | ||
defer ancInfo.Unlock() | ||
if ancInfo.LabelInfo == nil || time.Now().Unix() > ancInfo.TTL { | ||
resourceInfos := map[string]labelInfo{} | ||
filteredMetrics, err := listAllMetrics("SYS.ANC") | ||
if err != nil { | ||
logs.Logger.Errorf("Get all anc metrics: %s", err.Error()) | ||
return ancInfo.LabelInfo, ancInfo.FilterMetrics | ||
} | ||
ancResourceMetricMap := getAncSubResourceMetrics(filteredMetrics) | ||
getAncResourceInfoFromRms("anc_anc_id", resourceInfos, ancResourceMetricMap) | ||
getAncResourceInfoFromRms("anc_service_id", resourceInfos, ancResourceMetricMap) | ||
getAncResourceInfoFromRms("anc_membergroup_id", resourceInfos, ancResourceMetricMap) | ||
ancInfo.LabelInfo = resourceInfos | ||
ancInfo.FilterMetrics = filteredMetrics | ||
ancInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix() | ||
} | ||
return ancInfo.LabelInfo, ancInfo.FilterMetrics | ||
} | ||
|
||
func getAncResourceInfoFromRms(dimName string, resourceInfos map[string]labelInfo, allMetricMap map[string][]cesmodel.MetricInfoList) { | ||
dimConfig, ok := dimConfigMap[dimName] | ||
if !ok { | ||
return | ||
} | ||
rmsResourceInfos, err := getResourcesBaseInfoFromRMS(dimConfig["providerId"], dimConfig["resourceType"], "global") | ||
if err != nil { | ||
return | ||
} | ||
metricNames, ok := getMetricConfigMap("SYS.ANC")[dimName] | ||
if !ok { | ||
return | ||
} | ||
for _, rmsResourceInfo := range rmsResourceInfos { | ||
metrics := buildSingleDimensionMetrics(metricNames, "SYS.ANC", dimName, rmsResourceInfo.ID) | ||
info := labelInfo{ | ||
Name: []string{"name", "epId"}, | ||
Value: []string{rmsResourceInfo.Name, rmsResourceInfo.EpId}, | ||
} | ||
keys, values := getTags(rmsResourceInfo.Tags) | ||
info.Name = append(info.Name, keys...) | ||
info.Value = append(info.Value, values...) | ||
resourceInfos[GetResourceKeyFromMetricInfo(metrics[0])] = info | ||
|
||
// 设置子维度指标资源关联 | ||
subMetricList, ok := allMetricMap[rmsResourceInfo.ID] | ||
if !ok { | ||
continue | ||
} | ||
for _, subMetric := range subMetricList { | ||
resourceInfos[GetResourceKeyFromMetricInfo(subMetric)] = labelInfo{ | ||
Name: []string{dimConfig["nameInSubResource"], "epId"}, | ||
Value: []string{rmsResourceInfo.Name, rmsResourceInfo.EpId}, | ||
} | ||
} | ||
} | ||
} | ||
|
||
func getAncSubResourceMetrics(allMetrics []cesmodel.MetricInfoList) map[string][]cesmodel.MetricInfoList { | ||
resultMap := make(map[string][]cesmodel.MetricInfoList) | ||
for _, metric := range allMetrics { | ||
// 只操作多维度的指标,将其第一维度值映射到指标对象 | ||
if len(metric.Dimensions) < 2 { | ||
continue | ||
} | ||
firstDimValue := metric.Dimensions[0].Value | ||
subMetricList, ok := resultMap[firstDimValue] | ||
if ok { | ||
subMetricList = append(subMetricList, metric) | ||
} else { | ||
subMetricList = []cesmodel.MetricInfoList{metric} | ||
} | ||
resultMap[firstDimValue] = subMetricList | ||
} | ||
return resultMap | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package collector | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/agiledragon/gomonkey/v2" | ||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestANCInfo_GetResourceInfo(t *testing.T) { | ||
metricConf = map[string]MetricConf{ | ||
"SYS.ANC": { | ||
Resource: "rms", | ||
DimMetricName: map[string][]string{ | ||
"anc_anc_id": {"network_incoming_bits_rate"}, | ||
"anc_anc_id,anc_clientassociation_id": {"vpc_connections"}, | ||
"anc_anc_id,anc_serviceassociation_id": {"service_inbound_traffic"}, | ||
"anc_service_id": {"service_inbound_traffic"}, | ||
"anc_service_id,anc_serviceregion_id": {"service_inbound_traffic"}, | ||
"anc_membergroup_id": {"total_server_count"}, | ||
}, | ||
}, | ||
} | ||
patches := gomonkey.ApplyFuncReturn(listAllMetrics, []model.MetricInfoList{ | ||
{ | ||
MetricName: "network_incoming_bits_rate", | ||
Dimensions: []model.MetricsDimension{ | ||
{Name: "anc_anc_id", Value: "0cbcebbf-7732-4d50-8186-45cdf2fec1f3"}, | ||
}, | ||
}, | ||
{ | ||
MetricName: "service_inbound_traffic", | ||
Dimensions: []model.MetricsDimension{ | ||
{Name: "anc_service_id", Value: "440a1bf6-68cc-4a6a-b286-e89811a99b61"}, | ||
}, | ||
}, | ||
{ | ||
MetricName: "total_server_count", | ||
Dimensions: []model.MetricsDimension{ | ||
{Name: "anc_membergroup_id", Value: "139c8a1c-3b5d-4a97-8095-1b8aeed2b93e"}, | ||
}, | ||
}, | ||
{ | ||
MetricName: "vpc_connections", | ||
Dimensions: []model.MetricsDimension{ | ||
{Name: "anc_anc_id", Value: "0cbcebbf-7732-4d50-8186-45cdf2fec1f3"}, | ||
{Name: "anc_clientassociation_id", Value: "2da0f177-3294-4b52-ae8b-719e899ab5a5"}, | ||
}, | ||
}, | ||
{ | ||
MetricName: "service_inbound_traffic", | ||
Dimensions: []model.MetricsDimension{ | ||
{Name: "anc_anc_id", Value: "0cbcebbf-7732-4d50-8186-45cdf2fec1f3"}, | ||
{Name: "anc_serviceassociation_id", Value: "04c73e29-848a-4a45-8dd2-6dc1b79c2832"}, | ||
}, | ||
}, | ||
{ | ||
MetricName: "service_inbound_traffic", | ||
Dimensions: []model.MetricsDimension{ | ||
{Name: "anc_service_id", Value: "440a1bf6-68cc-4a6a-b286-e89811a99b61"}, | ||
{Name: "anc_serviceregion_id", Value: "440a1bf6-68cc-4a6a-b286-e89811a99b61_cn-southwest-242"}, | ||
}, | ||
}, | ||
}, nil) | ||
defer patches.Reset() | ||
outputs := []gomonkey.OutputCell{ | ||
{ | ||
Values: gomonkey.Params{[]ResourceBaseInfo{ | ||
{ | ||
ID: "0cbcebbf-7732-4d50-8186-45cdf2fec1f3", | ||
Name: "demo-anc", | ||
EpId: "0", | ||
}, | ||
}, nil}, | ||
}, | ||
{ | ||
Values: gomonkey.Params{[]ResourceBaseInfo{ | ||
{ | ||
ID: "440a1bf6-68cc-4a6a-b286-e89811a99b61", | ||
Name: "demo-anc-service", | ||
EpId: "0", | ||
}, | ||
}, nil}, | ||
}, | ||
{ | ||
Values: gomonkey.Params{[]ResourceBaseInfo{ | ||
{ | ||
ID: "139c8a1c-3b5d-4a97-8095-1b8aeed2b93e", | ||
Name: "demo-anc-member-group", | ||
EpId: "0", | ||
}, | ||
}, nil}, | ||
}, | ||
} | ||
patches.ApplyFuncSeq(getResourcesBaseInfoFromRMS, outputs) | ||
var ancInfo ANCInfo | ||
labels, metrics := ancInfo.GetResourceInfo() | ||
assert.Equal(t, 6, len(labels)) | ||
assert.Equal(t, 6, len(metrics)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.