Skip to content

Commit

Permalink
发布2.0.9版本
Browse files Browse the repository at this point in the history
1.修改TTL时间可配置
2.修改gaussdb for mysql服务对应的rms参数
3.修改eps信息前缀统一与配置中的指标前缀相同
4.增加-v参数支持查看版本号
5.DLI服务适配资源池纬度指标
6.增加ep_ids配置,可配置只拉取指定企业项目下的资源指标
7.补充EVS服务grafana模板
  • Loading branch information
cxl123156 authored Jun 4, 2024
1 parent a69f6fc commit 5e2650b
Show file tree
Hide file tree
Showing 62 changed files with 2,025 additions and 107 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ global:
port: ":8087"
metric_path: "/metrics"
scrape_batch_size: 300
resource_sync_interval_minutes: 20 # Update frequency of resource information: resource information is updated every 180 minutes by default; If this parameter is set to a value less than 10 minutes, the information is updated every 10 minutes.
ep_ids: "xxx1,xxx2" # This is optional. Filter resources by enterpries project, cloudeye-exporter will get all resources when this is empty, if you need multiple enterprise project, use comma split them.
auth:
auth_url: "https://iam.{region_id}.myhuaweicloud.com/v3"
project_name: "{project_name}"
access_key: "{access_key}"
secret_key: "{secret_key}"
region: "{region}"
```
## Example of endpoint file(endpoints.yml)
Expand Down
2 changes: 2 additions & 0 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ tar -xzvf cloudeye-exporter.v2.0.5.tar.gz
global:
port: ":8087" # 监听端口 :8087代表在全部网络接口上开启监听8087端口,限定内部访问也可以指定IP例如:192.168.1.100:8087
scrape_batch_size: 300
resource_sync_interval_minutes: 20 # 资源信息更新频率:默认180分钟更新一次;该配置值小于10分钟,将以10分钟1次为资源信息更新频率
ep_ids: "xxx1,xxx2" # 可选配置,根据企业项目ID过滤资源,不配置默认查询所有资源的指标,多个ID使用英文逗号进行分割。
auth:
auth_url: "https://iam.{region_id}.myhuaweicloud.com/v3"
project_name: "cn-north-1" # 华为云项目名称,可以在“华为云->统一身份认证服务->项目”中查看
Expand Down
2 changes: 1 addition & 1 deletion clouds.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
global:
prefix: "huaweicloud"
scrape_batch_size: 300

resource_sync_interval_minutes: 180
auth:
auth_url: "https://iam.xxx.yyy.com/v3"
project_name: "{project_name}"
Expand Down
5 changes: 3 additions & 2 deletions collector/apic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"strings"
"time"

"github.com/huaweicloud/cloudeye-exporter/logs"
"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"

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

var apicInfo serversInfo
Expand Down Expand Up @@ -46,7 +47,7 @@ func (getter APICInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.Metri
}
apicInfo.LabelInfo = resourceInfos
apicInfo.FilterMetrics = filterMetrics
apicInfo.TTL = time.Now().Add(TTL).Unix()
apicInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return apicInfo.LabelInfo, apicInfo.FilterMetrics
}
Expand Down
2 changes: 1 addition & 1 deletion collector/apig.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (getter APIGInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricIn
}
apigInfo.LabelInfo = resourceInfos
apigInfo.FilterMetrics = filterMetrics
apigInfo.TTL = time.Now().Add(TTL).Unix()
apigInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return apigInfo.LabelInfo, apigInfo.FilterMetrics
}
Expand Down
2 changes: 1 addition & 1 deletion collector/as.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (getter ASInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.MetricI
}
asInfo.LabelInfo = resourceInfos
asInfo.FilterMetrics = filterMetrics
asInfo.TTL = time.Now().Add(TTL).Unix()
asInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return asInfo.LabelInfo, asInfo.FilterMetrics
}
Expand Down
5 changes: 3 additions & 2 deletions collector/bms.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package collector
import (
"time"

"github.com/huaweicloud/cloudeye-exporter/logs"
cesmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"

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

var bmsInfo serversInfo
Expand Down Expand Up @@ -40,7 +41,7 @@ func (getter BMSInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.Metric
}
bmsInfo.LabelInfo = resourceInfos
bmsInfo.FilterMetrics = filterMetrics
bmsInfo.TTL = time.Now().Add(TTL).Unix()
bmsInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return bmsInfo.LabelInfo, bmsInfo.FilterMetrics
}
Expand Down
5 changes: 3 additions & 2 deletions collector/cbr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package collector
import (
"time"

"github.com/huaweicloud/cloudeye-exporter/logs"
"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"

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

var cbrInfo serversInfo
Expand Down Expand Up @@ -51,7 +52,7 @@ func (getter CBRInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricInf

cbrInfo.LabelInfo = resourceInfos
cbrInfo.FilterMetrics = filterMetrics
cbrInfo.TTL = time.Now().Add(TTL).Unix()
cbrInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return cbrInfo.LabelInfo, cbrInfo.FilterMetrics
}
Expand Down
2 changes: 1 addition & 1 deletion collector/cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (getter CCInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.MetricI
return ccInfo.LabelInfo, ccInfo.FilterMetrics
}
ccInfo.LabelInfo, ccInfo.FilterMetrics = buildResourceInfoAndMetrics(metricNames, connections, packages, bandwidths)
ccInfo.TTL = time.Now().Add(TTL).Unix()
ccInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return ccInfo.LabelInfo, ccInfo.FilterMetrics
}
Expand Down
2 changes: 1 addition & 1 deletion collector/cdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (getter CDMInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.Metric
}
cdmInfo.LabelInfo = resourceInfos
cdmInfo.FilterMetrics = filterMetrics
cdmInfo.TTL = time.Now().Add(TTL).Unix()
cdmInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return cdmInfo.LabelInfo, cdmInfo.FilterMetrics
}
Expand Down
4 changes: 2 additions & 2 deletions collector/cfw.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (cfw CFWInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.MetricInf
metrics := buildSingleDimensionMetrics(metricNames, "SYS.CFW", "fw_instance_id", server.ID)
filterMetrics = append(filterMetrics, metrics...)
info := labelInfo{
Name: []string{"name", "ep_id"},
Name: []string{"name", "epId"},
Value: []string{server.Name, server.EpId},
}
keys, values := getTags(server.Tags)
Expand All @@ -56,7 +56,7 @@ func (cfw CFWInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.MetricInf

cfwServerInfo.LabelInfo = resourceInfos
cfwServerInfo.FilterMetrics = filterMetrics
cfwServerInfo.TTL = time.Now().Add(TTL).Unix()
cfwServerInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return cfwServerInfo.LabelInfo, cfwServerInfo.FilterMetrics
}
2 changes: 1 addition & 1 deletion collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (exporter *BaseHuaweiCloudExporter) listMetrics(namespace string) ([]model.
allResourcesInfo, metrics := exporter.listAllResources(namespace)
logs.Logger.Debugf("[%s] Resource number of %s: %d", exporter.txnKey, namespace, len(allResourcesInfo))

if len(metrics) > 0 {
if len(metrics) > 0 && CloudConf.Global.EpIds != "" {
return metrics, allResourcesInfo
}
logs.Logger.Debugf("[%s] Start to getAllMetric from CES", exporter.txnKey)
Expand Down
41 changes: 34 additions & 7 deletions collector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"errors"
"io/ioutil"
"net/http"
"path/filepath"
"regexp"
"strings"

"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
Expand All @@ -27,12 +30,14 @@ type CloudAuth struct {
}

type Global struct {
Port string `yaml:"port"`
Prefix string `yaml:"prefix"`
MetricPath string `yaml:"metric_path"`
EpsInfoPath string `yaml:"eps_path"`
MaxRoutines int `yaml:"max_routines"`
ScrapeBatchSize int `yaml:"scrape_batch_size"`
Port string `yaml:"port"`
Prefix string `yaml:"prefix"`
MetricPath string `yaml:"metric_path"`
EpsInfoPath string `yaml:"eps_path"`
MaxRoutines int `yaml:"max_routines"`
ScrapeBatchSize int `yaml:"scrape_batch_size"`
ResourceSyncIntervalMinutes int `yaml:"resource_sync_interval_minutes"`
EpIds string `yaml:"ep_ids"`
}

type CloudConfig struct {
Expand All @@ -46,7 +51,12 @@ var TmpAK string
var TmpSK string

func InitCloudConf(file string) error {
data, err := ioutil.ReadFile(file)
realPath, err := NormalizePath(file)
if err != nil {
return err
}

data, err := ioutil.ReadFile(realPath)
if err != nil {
return err
}
Expand All @@ -67,6 +77,19 @@ func InitCloudConf(file string) error {
return err
}

func NormalizePath(path string) (string, error) {
relPath, err := filepath.Abs(path) // 对文件路径进行标准化
if err != nil {
return "", err
}
relPath = strings.Replace(relPath, "\\", "/", -1)
match, err := regexp.MatchString("[!;<>&|$\n`\\\\]", relPath)
if match || err != nil {
return "", errors.New("match path error")
}
return relPath, nil
}

func SetDefaultConfigValues(config *CloudConfig) {
if config.Global.Port == "" {
config.Global.Port = ":8087"
Expand All @@ -91,6 +114,10 @@ func SetDefaultConfigValues(config *CloudConfig) {
if config.Global.ScrapeBatchSize == 0 {
config.Global.ScrapeBatchSize = 300
}

if config.Global.ResourceSyncIntervalMinutes <= 0 {
config.Global.ResourceSyncIntervalMinutes = 180
}
}

type MetricConf struct {
Expand Down
60 changes: 60 additions & 0 deletions collector/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package collector

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/agiledragon/gomonkey/v2"
Expand Down Expand Up @@ -112,3 +114,61 @@ func TestInitEndpointConfig(t *testing.T) {
})
}
}

func TestSetDefaultConfigValues(t *testing.T) {
config := &CloudConfig{}
SetDefaultConfigValues(config)
assert.NotEqual(t, 0, config.Global.ResourceSyncIntervalMinutes)
}

func TestInitCloudConf(t *testing.T) {
testCases := []struct {
name string
patches func() *gomonkey.Patches
expect func(t *testing.T, err error)
}{
{
"NormalizeGetAbsolutePathError",
func() *gomonkey.Patches {
patches := gomonkey.NewPatches()
patches.ApplyFuncReturn(filepath.Abs, "", errors.New("get absolute path error"))
return patches
},
func(t *testing.T, err error) {
assert.NotNil(t, err)
},
},
{
"PathPatternError",
func() *gomonkey.Patches {
patches := gomonkey.NewPatches()
patches.ApplyFuncReturn(filepath.Abs, "/usr/local/\n/cloudeye-exporter/clouds.conf", nil)
return patches
},
func(t *testing.T, err error) {
assert.NotNil(t, err)
},
},
{
"NormalizeSuccessReadError",
func() *gomonkey.Patches {
patches := gomonkey.NewPatches()
patches.ApplyFuncReturn(filepath.Abs, "/usr/local/cloudeye-exporter/clouds.conf", nil)
patches.ApplyFuncReturn(ioutil.ReadFile, nil, errors.New("read file content error"))
return patches
},
func(t *testing.T, err error) {
assert.NotNil(t, err)
},
},
}

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
patches := testCase.patches()
defer patches.Reset()
err := InitCloudConf("/usr/local/cloudeye-exporter/clouds.conf")
testCase.expect(t, err)
})
}
}
2 changes: 1 addition & 1 deletion collector/dayu.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (getter DayuInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricIn

dayuInfo.LabelInfo = resourceInfos
dayuInfo.FilterMetrics = filterMetrics
dayuInfo.TTL = time.Now().Add(TTL).Unix()
dayuInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return dayuInfo.LabelInfo, dayuInfo.FilterMetrics
}
Expand Down
2 changes: 1 addition & 1 deletion collector/dbss.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (getter DBSSInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricIn

dbssInfo.LabelInfo = resourceInfos
dbssInfo.FilterMetrics = filterMetrics
dbssInfo.TTL = time.Now().Add(TTL).Unix()
dbssInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return dbssInfo.LabelInfo, dbssInfo.FilterMetrics
}
Expand Down
2 changes: 1 addition & 1 deletion collector/dcaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (getter DCAASInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricI

dcaasInfo.LabelInfo = resourceInfos
dcaasInfo.FilterMetrics = filterMetrics
dcaasInfo.TTL = time.Now().Add(TTL).Unix()
dcaasInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return dcaasInfo.LabelInfo, dcaasInfo.FilterMetrics
}
Expand Down
2 changes: 1 addition & 1 deletion collector/dcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (getter DCSInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricInf

dcsInfo.LabelInfo = resourceInfos
dcsInfo.FilterMetrics = filterMetrics
dcsInfo.TTL = time.Now().Add(TTL).Unix()
dcsInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return dcsInfo.LabelInfo, dcsInfo.FilterMetrics
}
Expand Down
2 changes: 1 addition & 1 deletion collector/ddms.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (getter DDMSInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricIn
}
ddmsInfo.LabelInfo = resourceInfos
ddmsInfo.FilterMetrics = filterMetrics
ddmsInfo.TTL = time.Now().Add(TTL).Unix()
ddmsInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return ddmsInfo.LabelInfo, ddmsInfo.FilterMetrics
}
Expand Down
2 changes: 1 addition & 1 deletion collector/ddos.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (getter DDOSInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricIn
}
ddosInfo.LabelInfo = resourceInfos
ddosInfo.FilterMetrics = filterMetrics
ddosInfo.TTL = time.Now().Add(TTL).Unix()
ddosInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return ddosInfo.LabelInfo, ddosInfo.FilterMetrics
}
Expand Down
5 changes: 3 additions & 2 deletions collector/dds.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package collector
import (
"time"

"github.com/huaweicloud/cloudeye-exporter/logs"
"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"
dds "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dds/v3"
ddsmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dds/v3/model"

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

type DdsInstanceInfo struct {
Expand Down Expand Up @@ -71,7 +72,7 @@ func (getter DDSInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricInf
}
ddsInfo.LabelInfo = resourceInfos
ddsInfo.FilterMetrics = filterMetrics
ddsInfo.TTL = time.Now().Add(TTL).Unix()
ddsInfo.TTL = time.Now().Add(GetResourceInfoExpirationTime()).Unix()
}
return ddsInfo.LabelInfo, ddsInfo.FilterMetrics
}
Expand Down
Loading

0 comments on commit 5e2650b

Please sign in to comment.