Skip to content

Commit

Permalink
发布2.0.11版本 (#68)
Browse files Browse the repository at this point in the history
1.适配广域网质量监控指标
2.适配ANC,cc,dli,vpc,
3.补充FunctionGraph,APIC,AS,CC,DLI,DRS,GaussDB,GaussDB Redis,NAT服务grafana模板
4.修改kafka模板样式
  • Loading branch information
cxl123156 authored Sep 10, 2024
1 parent afa39bf commit ca08db9
Show file tree
Hide file tree
Showing 38 changed files with 26,696 additions and 3,446 deletions.
6 changes: 6 additions & 0 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Prometheus是用于展示大型测量数据的开源可视化工具,在工业
|湖仓构建服务|SYS.LakeFormation ||RMS/云服务|
|智能数据湖运营平台|SYS.DAYU ||云服务|
|云防火墙|SYS.CFW ||RMS|
|广域网质量监控|SYS.WANQMonitor ||云服务|

注:自定义标签时,key只能包含大写字母、小写字母以及中划线

Expand Down Expand Up @@ -129,6 +130,11 @@ $huaweiCloud_AK $huaweiCloud_SK
EOF)
```
5. 指标配置
cloudeye-exporter支持的指标可在 [支持监控的服务列表](https://support.huaweicloud.com/usermanual-ces/zh-cn_topic_0202622212.html)中查看。若发现您需要的指标没有获取到,可查阅该文档将对应的指标填入metric.yml中。
## 安装配置prometheus接入cloudeye
1. 下载Prometheus (https://prometheus.io/download/)
```
Expand Down
111 changes: 111 additions & 0 deletions collector/anc.go
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
}
101 changes: 101 additions & 0 deletions collector/anc_test.go
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))
}
32 changes: 16 additions & 16 deletions collector/cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

var (
ccInfo serversInfo
limit = int32(2000)
limit = int32(500)
)

const (
Expand Down Expand Up @@ -65,29 +65,29 @@ func buildResourceInfoAndMetrics(metricNames []string, connections map[string]mo
resourceInfos := map[string]labelInfo{}
filterMetrics := make([]cesmodel.MetricInfoList, 0)
for _, bandwidth := range bandwidths {
if *bandwidth.CloudConnectionId == "" || *bandwidth.BandwidthPackageId == "" {
if bandwidth.CloudConnectionId == "" || bandwidth.BandwidthPackageId == "" {
continue
}
metrics := buildDimensionMetrics(metricNames, CCNamespace,
[]cesmodel.MetricsDimension{{Name: "cloud_connect_id", Value: *bandwidth.CloudConnectionId},
{Name: "bwp_id", Value: *bandwidth.BandwidthPackageId},
{Name: "region_bandwidth_id", Value: *bandwidth.Id}})
[]cesmodel.MetricsDimension{{Name: "cloud_connect_id", Value: bandwidth.CloudConnectionId},
{Name: "bwp_id", Value: bandwidth.BandwidthPackageId},
{Name: "region_bandwidth_id", Value: bandwidth.Id}})
filterMetrics = append(filterMetrics, metrics...)

var info labelInfo
connectionName, connectionValue := getConnectionInfo(connections, *bandwidth.CloudConnectionId)
connectionName, connectionValue := getConnectionInfo(connections, bandwidth.CloudConnectionId)
info.Name = append(info.Name, connectionName...)
info.Value = append(info.Value, connectionValue...)

pkgName, pkgValue := getBandwidthPackageInfo(packages, *bandwidth.BandwidthPackageId)
pkgName, pkgValue := getBandwidthPackageInfo(packages, bandwidth.BandwidthPackageId)
info.Name = append(info.Name, pkgName...)
info.Value = append(info.Value, pkgValue...)

if bandwidth.InterRegions != nil && len(*bandwidth.InterRegions) != 0 {
info.Name = append(info.Name, "interRegions", "bandwidthName")
info.Value = append(info.Value, fmt.Sprintf("%s<->%s",
getDefaultString((*bandwidth.InterRegions)[0].LocalRegionId), getDefaultString((*bandwidth.InterRegions)[0].RemoteRegionId)),
getDefaultString(bandwidth.Name))
getDefaultString(&bandwidth.Name))
}
resourceInfos[GetResourceKeyFromMetricInfo(metrics[0])] = info
}
Expand All @@ -97,7 +97,7 @@ func buildResourceInfoAndMetrics(metricNames []string, connections map[string]mo
func getConnectionInfo(connections map[string]model.CloudConnection, connectionId string) ([]string, []string) {
connection, ok := connections[connectionId]
if ok {
return []string{"connectionName", "connectionEpId"}, []string{*connection.Name, *connection.EnterpriseProjectId}
return []string{"connectionName", "connectionEpId"}, []string{connection.Name, *connection.EnterpriseProjectId}
}
return nil, nil
}
Expand All @@ -108,7 +108,7 @@ func getBandwidthPackageInfo(packages map[string]model.BandwidthPackage, connect
return nil, nil
}
name := []string{"packageName", "packageEpId"}
vale := []string{getDefaultString(pkg.Name), getDefaultString(pkg.EnterpriseProjectId)}
vale := []string{getDefaultString(&pkg.Name), getDefaultString(pkg.EnterpriseProjectId)}
if pkg.Tags != nil {
keys, values := getTags(fmtTags(pkg.Tags))
name = append(name, keys...)
Expand All @@ -126,8 +126,8 @@ func listCCConnections() (map[string]model.CloudConnection, error) {
if err != nil {
return connections, err
}
for _, connection := range *response.CloudConnections {
connections[*connection.Id] = connection
for _, connection := range response.CloudConnections {
connections[connection.Id] = connection
}
if response.PageInfo.NextMarker == nil {
break
Expand All @@ -147,8 +147,8 @@ func listBandwidthPackages() (map[string]model.BandwidthPackage, error) {
logs.Logger.Errorf("Failed to list BandwidthPackages, error: %s", err.Error())
return bandwidthPackages, err
}
for _, bandwidthPackage := range *response.BandwidthPackages {
bandwidthPackages[*bandwidthPackage.Id] = bandwidthPackage
for _, bandwidthPackage := range response.BandwidthPackages {
bandwidthPackages[bandwidthPackage.Id] = bandwidthPackage
}
if response.PageInfo.NextMarker == nil {
break
Expand All @@ -163,7 +163,7 @@ func getCCClient() *cc.CcClient {
}

func getCCClientBuilder() *http_client.HcHttpClientBuilder {
builder := cc.CcClientBuilder().WithCredential(global.NewCredentialsBuilder().WithAk(conf.AccessKey).WithSk(conf.SecretKey).Build()).
builder := cc.CcClientBuilder().WithCredential(global.NewCredentialsBuilder().WithAk(conf.AccessKey).WithSk(conf.SecretKey).WithDomainId(conf.DomainID).Build()).
WithHttpConfig(config.DefaultHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify))
if endpoint, ok := endpointConfig["cc"]; ok {
builder.WithEndpoint(endpoint)
Expand All @@ -183,7 +183,7 @@ func listInterRegionBandwidths() ([]model.InterRegionBandwidth, error) {
logs.Logger.Errorf("Failed to list InterRegionBandwidths, error: %s", err.Error())
return resources, err
}
resources = append(resources, *response.InterRegionBandwidths...)
resources = append(resources, response.InterRegionBandwidths...)
if response.PageInfo.NextMarker == nil {
break
}
Expand Down
26 changes: 14 additions & 12 deletions collector/cc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ package collector
import (
"testing"

"github.com/agiledragon/gomonkey/v2"
cc "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cc/v3"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cc/v3/model"
"github.com/stretchr/testify/assert"

"github.com/huaweicloud/cloudeye-exporter/logs"
)

func TestCCGetResourceInfo(t *testing.T) {
sysConfig := map[string][]string{CCConfigDimNames: {"network_incoming_bits_rate"}}
patches := gomonkey.ApplyFuncReturn(getMetricConfigMap, sysConfig)

patches := getPatches()
patches.ApplyFuncReturn(getMetricConfigMap, sysConfig)
logs.InitLog("")
defaultEpId := "0"
id := "connection-0001"
name := "connection1"
connectionsPage := model.ListCloudConnectionsResponse{
HttpStatusCode: 200,
CloudConnections: &[]model.CloudConnection{
{Id: &id, Name: &name, EnterpriseProjectId: &defaultEpId},
CloudConnections: []model.CloudConnection{
{Id: id, Name: name, EnterpriseProjectId: &defaultEpId},
},
PageInfo: &model.PageInfo{},
}
Expand All @@ -32,8 +34,8 @@ func TestCCGetResourceInfo(t *testing.T) {

packagesPage := model.ListBandwidthPackagesResponse{
HttpStatusCode: 200,
BandwidthPackages: &[]model.BandwidthPackage{
{Id: &id, Name: &name, EnterpriseProjectId: &defaultEpId},
BandwidthPackages: []model.BandwidthPackage{
{Id: id, Name: name, EnterpriseProjectId: &defaultEpId},
},
PageInfo: &model.PageInfo{},
}
Expand All @@ -46,12 +48,12 @@ func TestCCGetResourceInfo(t *testing.T) {
remoteRegionId := "cn-test-02"
bandwidthsPage := model.ListInterRegionBandwidthsResponse{
HttpStatusCode: 200,
InterRegionBandwidths: &[]model.InterRegionBandwidth{
InterRegionBandwidths: []model.InterRegionBandwidth{
{
Id: &id,
Name: &name,
CloudConnectionId: &id,
BandwidthPackageId: &id,
Id: id,
Name: name,
CloudConnectionId: id,
BandwidthPackageId: id,
InterRegions: &[]model.InterRegion{
{LocalRegionId: &localRegionId, RemoteRegionId: &remoteRegionId},
}},
Expand Down
Loading

0 comments on commit ca08db9

Please sign in to comment.