-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.支持配置http_proxy代理 2.适配LIVE,L TS,HSS,CloudTable,EG,OBS,DNS服务 3.删除CC服务下的无效指标
- Loading branch information
Showing
62 changed files
with
25,569 additions
and
8,668 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
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
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
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
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,75 @@ | ||
package collector | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" | ||
cesmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model" | ||
clouttable "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cloudtable/v2" | ||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cloudtable/v2/model" | ||
|
||
"github.com/huaweicloud/cloudeye-exporter/logs" | ||
) | ||
|
||
var cloudTableInfo serversInfo | ||
|
||
type CloudTableInfo struct{} | ||
|
||
func getCloudTableClient() *clouttable.CloudTableClient { | ||
return clouttable.NewCloudTableClient(clouttable.CloudTableClientBuilder().WithCredential( | ||
basic.NewCredentialsBuilder().WithAk(conf.AccessKey).WithSk(conf.SecretKey).WithProjectId(conf.ProjectID).Build()). | ||
WithHttpConfig(GetHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)). | ||
WithEndpoint(getEndpoint("cloudtable", "v2")).Build()) | ||
} | ||
|
||
func (ct CloudTableInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.MetricInfoList) { | ||
resourceInfos := map[string]labelInfo{} | ||
cloudTableInfo.Lock() | ||
defer cloudTableInfo.Unlock() | ||
if cloudTableInfo.LabelInfo == nil || time.Now().Unix() > cloudTableInfo.TTL { | ||
clusters := GetClusterInfo() | ||
for _, cluster := range clusters { | ||
info := labelInfo{ | ||
Name: []string{"clusterName"}, | ||
Value: []string{*cluster.ClusterName}, | ||
} | ||
resourceInfos[*cluster.ClusterId] = info | ||
} | ||
allMetrics, err := listAllMetrics("SYS.CloudTable") | ||
if err != nil { | ||
logs.Logger.Errorf("[%s] Get all metrics of SYS.CloudTable error: %s", err.Error()) | ||
return cloudTableInfo.LabelInfo, cloudTableInfo.FilterMetrics | ||
} | ||
for _, metric := range allMetrics { | ||
if info, ok := resourceInfos[metric.Dimensions[0].Value]; ok { | ||
resourceInfos[GetResourceKeyFromMetricInfo(metric)] = info | ||
} | ||
} | ||
cloudTableInfo.LabelInfo = resourceInfos | ||
cloudTableInfo.FilterMetrics = allMetrics | ||
cloudTableInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix() | ||
} | ||
return cloudTableInfo.LabelInfo, cloudTableInfo.FilterMetrics | ||
} | ||
|
||
func GetClusterInfo() []model.ClusterDetail { | ||
cloudTableClusterLimit := int32(100) | ||
cloudTableClusterOffset := int32(0) | ||
request := &model.ListClustersRequest{Limit: &cloudTableClusterLimit, Offset: &cloudTableClusterOffset} | ||
var clusters []model.ClusterDetail | ||
for { | ||
response, err := getCloudTableClient().ListClusters(request) | ||
if err != nil { | ||
logs.Logger.Errorf("list cloud table clusters error: %s, limit: %d, offset: %d", err.Error(), | ||
*request.Limit, *request.Offset) | ||
return clusters | ||
} | ||
tempClusters := *response.Clusters | ||
if len(tempClusters) == 0 { | ||
break | ||
} | ||
clusters = append(clusters, tempClusters...) | ||
*request.Offset += cloudTableClusterLimit | ||
} | ||
return clusters | ||
} |
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,60 @@ | ||
package collector | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/agiledragon/gomonkey/v2" | ||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/def" | ||
cesmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model" | ||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cloudtable/v2/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCloudTableInfo_GetResourceInfo(t *testing.T) { | ||
clusterID := "cls-0001" | ||
clusterName := "cluster1" | ||
respPage1 := model.ListClustersResponse{ | ||
HttpStatusCode: 200, | ||
Clusters: &[]model.ClusterDetail{ | ||
{ClusterId: &clusterID, ClusterName: &clusterName}, | ||
}, | ||
} | ||
respPage2 := model.ListClustersResponse{ | ||
HttpStatusCode: 200, | ||
Clusters: &[]model.ClusterDetail{}, | ||
} | ||
cloudTableClient := getCloudTableClient() | ||
patches := gomonkey.NewPatches() | ||
defer patches.Reset() | ||
patches.ApplyMethodFunc(cloudTableClient.HcClient, "Sync", func(req interface{}, reqDef *def.HttpRequestDef) (interface{}, error) { | ||
request, ok := req.(*model.ListClustersRequest) | ||
if !ok { | ||
return nil, errors.New("test error") | ||
} | ||
if *request.Offset == 0 { | ||
return &respPage1, nil | ||
} | ||
return &respPage2, nil | ||
}) | ||
patches.ApplyFuncReturn(listAllMetrics, []cesmodel.MetricInfoList{ | ||
{ | ||
Namespace: "SYS.CloudTable", | ||
MetricName: "cmdProcessCPU", | ||
Dimensions: []cesmodel.MetricsDimension{ | ||
{ | ||
Name: "cluster_id", | ||
Value: "cls-0001", | ||
}, | ||
{ | ||
Name: "instance_name", | ||
Value: "server-1-1", | ||
}, | ||
}, | ||
}, | ||
}, nil) | ||
var getter CloudTableInfo | ||
resourceInfos, filteredMetrics := getter.GetResourceInfo() | ||
assert.NotNil(t, resourceInfos) | ||
assert.NotNil(t, filteredMetrics) | ||
} |
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,35 @@ | ||
package collector | ||
|
||
import ( | ||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config" | ||
) | ||
|
||
func GetHttpConfig() *config.HttpConfig { | ||
httpConfig := config.DefaultHttpConfig() | ||
if !isProxyValid() { | ||
return httpConfig | ||
} | ||
|
||
global := CloudConf.Global | ||
proxy := config.Proxy{ | ||
Schema: global.HttpSchema, | ||
Host: global.HttpHost, | ||
Port: global.HttpPort, | ||
} | ||
if isUserInfoValid() { | ||
proxy.Username = global.UserName | ||
proxy.Password = global.Password | ||
} | ||
httpConfig.HttpProxy = &proxy | ||
return httpConfig | ||
} | ||
|
||
func isProxyValid() bool { | ||
global := CloudConf.Global | ||
return global.HttpSchema != "" && global.HttpHost != "" && global.HttpPort > 0 | ||
} | ||
|
||
func isUserInfoValid() bool { | ||
global := CloudConf.Global | ||
return global.UserName != "" && global.Password != "" | ||
} |
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.