Skip to content

Commit

Permalink
发布2.0.12 (#70)
Browse files Browse the repository at this point in the history
1.支持配置http_proxy代理
2.适配LIVE,L TS,HSS,CloudTable,EG,OBS,DNS服务
3.删除CC服务下的无效指标
  • Loading branch information
cxl123156 authored Nov 6, 2024
1 parent ca08db9 commit e5f2243
Show file tree
Hide file tree
Showing 62 changed files with 25,569 additions and 8,668 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ global:
metrics_conf_path: "/root/metrics.yml" # This is optional. We recommend that you use an absolute path for the metrics configuration file path. If this line is absent, the program will use configuration file in the directory where the startup command is executed by default.
endpoints_conf_path: "/root/endpoints.yml" # This is optional. We recommend that you use an absolute path for the service endpoints configuration file path. If this line is absent, the program will use configuration file in the directory where the startup command is executed by default.
ignore_ssl_verify: false # This is optional. The SSL certificate is verified by default when the exporter queries resources or indicators. If the exporter is abnormal due to SSL certificate verification, you can set this configuration to true to skip SSL certificate verification.
# This is optional. You can replace the proxy schema, host and port in the example below according to actual situation.
proxy_schema: "http"
proxy_host: "proxy.huaweicloud.com"
proxy_port: 8080
# This is optional. If the proxy requires authentication, please configure the username and password
proxy_username: "username"
proxy_password: "password"
auth:
auth_url: "https://iam.{region_id}.myhuaweicloud.com/v3"
project_name: "{project_name}"
Expand Down
16 changes: 16 additions & 0 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ Prometheus是用于展示大型测量数据的开源可视化工具,在工业
|智能数据湖运营平台|SYS.DAYU ||云服务|
|云防火墙|SYS.CFW ||RMS|
|广域网质量监控|SYS.WANQMonitor ||云服务|
|云日志服务|SYS.LTS |×|云服务|
|视频直播|SYS.LIVE |×|云服务|
|云原生应用网络|SYS.ANC||RMS|
|企业主机安全|SYS.HSS|×|云服务|
|表格存储服务|SYS.CloudTable|×|云服务|
|事件网格|SYS.EG||RMS|
|对象存储服务|SYS.OBS||RMS|
|云解析服务|SYS.DNS||云服务|

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

Expand Down Expand Up @@ -90,6 +98,14 @@ global:
metrics_conf_path: "/root/metric.yml" # 可选配置,指定指标配置文件路径,建议使用绝对路径。若未指定,程序将默认使用执行启动命令所在目录下的指标配置文件。
endpoints_conf_path: "/root/endpoints.yml" # 可选配置,指定服务域名配置文件路径,建议使用绝对路径。若未指定,程序将默认使用执行启动命令所在目录下的服务域名配置文件。
ignore_ssl_verify: false # 可选配置,exporter查询资源/指标时默认校验ssl证书;若用户因ssl证书校验导致功能异常,可将该配置项配置为true跳过ssl证书校验
# 可选配置,根据实际情况替换示例中的代理协议、地址和端口号
proxy_schema: "http"
proxy_host: "proxy.huaweicloud.com"
proxy_port: 8080
# 可选配置,如果代理需要认证,请配置用户名和密码
proxy_username: "username"
proxy_password: "password"
auth:
auth_url: "https://iam.{region_id}.myhuaweicloud.com/v3"
project_name: "cn-north-1" # 华为云项目名称,可以在“华为云->统一身份认证服务->项目”中查看
Expand Down
5 changes: 5 additions & 0 deletions clouds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ global:
scrape_batch_size: 300
resource_sync_interval_minutes: 180
ignore_ssl_verify: false
proxy_schema: ""
proxy_host: ""
proxy_port: 0
proxy_username: ""
proxy_password: ""
auth:
auth_url: "https://iam.xxx.yyy.com/v3"
project_name: "{project_name}"
Expand Down
3 changes: 1 addition & 2 deletions collector/apic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
apig "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/apig/v2"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/apig/v2/model"
cesmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"
Expand Down Expand Up @@ -174,6 +173,6 @@ func showDetailsOfInstanceV2(instanceID string) (*model.ShowDetailsOfInstanceV2R
func getAPICSClient() *apig.ApigClient {
return apig.NewApigClient(apig.ApigClientBuilder().WithCredential(
basic.NewCredentialsBuilder().WithAk(conf.AccessKey).WithSk(conf.SecretKey).WithProjectId(conf.ProjectID).Build()).
WithHttpConfig(config.DefaultHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithHttpConfig(GetHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithEndpoint(getEndpoint("apig", "v2")).Build())
}
3 changes: 1 addition & 2 deletions collector/apig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/def"
apig "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/apig/v2"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"
Expand Down Expand Up @@ -122,6 +121,6 @@ func getAllAPIGAppsInstances() ([]APIGAppsInfo, error) {
func getAPIGSClient() *apig.ApigClient {
return apig.NewApigClient(apig.ApigClientBuilder().WithCredential(
basic.NewCredentialsBuilder().WithAk(conf.AccessKey).WithSk(conf.SecretKey).WithProjectId(conf.ProjectID).Build()).
WithHttpConfig(config.DefaultHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithHttpConfig(GetHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithEndpoint(getEndpoint("apig", "v1.0")).Build())
}
3 changes: 1 addition & 2 deletions collector/cbr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
cbr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1"
cbrmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1/model"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"
Expand Down Expand Up @@ -89,6 +88,6 @@ func getAllCbrInstancesFromCBR() ([]ResourceBaseInfo, error) {
func getCBRClient() *cbr.CbrClient {
return cbr.NewCbrClient(cbr.CbrClientBuilder().WithCredential(
basic.NewCredentialsBuilder().WithAk(conf.AccessKey).WithSk(conf.SecretKey).WithProjectId(conf.ProjectID).Build()).
WithHttpConfig(config.DefaultHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithHttpConfig(GetHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithEndpoint(getEndpoint("cbr", "v3")).Build())
}
3 changes: 1 addition & 2 deletions collector/cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

http_client "github.com/huaweicloud/huaweicloud-sdk-go-v3/core"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
cc "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cc/v3"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cc/v3/model"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cc/v3/region"
Expand Down Expand Up @@ -164,7 +163,7 @@ func getCCClient() *cc.CcClient {

func getCCClientBuilder() *http_client.HcHttpClientBuilder {
builder := cc.CcClientBuilder().WithCredential(global.NewCredentialsBuilder().WithAk(conf.AccessKey).WithSk(conf.SecretKey).WithDomainId(conf.DomainID).Build()).
WithHttpConfig(config.DefaultHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify))
WithHttpConfig(GetHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify))
if endpoint, ok := endpointConfig["cc"]; ok {
builder.WithEndpoint(endpoint)
} else {
Expand Down
3 changes: 1 addition & 2 deletions collector/cdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
cdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1/model"
cesmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"
Expand Down Expand Up @@ -49,7 +48,7 @@ func (getter CDMInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.Metric
func getCDMClient() *cdm.CdmClient {
return cdm.NewCdmClient(cdm.CdmClientBuilder().WithCredential(
basic.NewCredentialsBuilder().WithAk(conf.AccessKey).WithSk(conf.SecretKey).WithProjectId(conf.ProjectID).Build()).
WithHttpConfig(config.DefaultHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithHttpConfig(GetHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithEndpoint(getEndpoint("cdm", "v1.1")).Build())
}

Expand Down
75 changes: 75 additions & 0 deletions collector/cloudtable.go
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
}
60 changes: 60 additions & 0 deletions collector/cloudtable_test.go
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)
}
35 changes: 35 additions & 0 deletions collector/common.go
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 != ""
}
10 changes: 8 additions & 2 deletions collector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"

"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
v3 "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/model"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -42,6 +41,13 @@ type Global struct {
LogsConfPath string `yaml:"logs_conf_path"`
EndpointsConfPath string `yaml:"endpoints_conf_path"`
IgnoreSSLVerify bool `yaml:"ignore_ssl_verify"`

// 用户配置的proxy信息
HttpSchema string `yaml:"proxy_schema"`
HttpHost string `yaml:"proxy_host"`
HttpPort int `yaml:"proxy_port"`
UserName string `yaml:"proxy_username"`
Password string `yaml:"proxy_password"`
}

type CloudConfig struct {
Expand Down Expand Up @@ -233,7 +239,7 @@ func getProjectInfo() (*model.KeystoneListProjectsResponse, error) {
WithAk(conf.AccessKey).
WithSk(conf.SecretKey).
Build()).
WithHttpConfig(config.DefaultHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithHttpConfig(GetHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
Build())
return iamclient.KeystoneListProjects(&model.KeystoneListProjectsRequest{Name: &conf.ProjectName})
}
Expand Down
3 changes: 1 addition & 2 deletions collector/ddms.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"
ddm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ddm/v1"
ddmmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ddm/v1/model"
Expand Down Expand Up @@ -114,6 +113,6 @@ func getDdmsInstanceNodes(instanceId string) ([]ddmmodel.ShowNodeResponse, error
func getDDMSClient() *ddm.DdmClient {
return ddm.NewDdmClient(ddm.DdmClientBuilder().WithCredential(
basic.NewCredentialsBuilder().WithAk(conf.AccessKey).WithSk(conf.SecretKey).WithProjectId(conf.ProjectID).Build()).
WithHttpConfig(config.DefaultHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithHttpConfig(GetHttpConfig().WithIgnoreSSLVerification(CloudConf.Global.IgnoreSSLVerify)).
WithEndpoint(getEndpoint("ddm", "v1")).Build())
}
Loading

0 comments on commit e5f2243

Please sign in to comment.