Skip to content

Commit 81349e9

Browse files
authored
Merge pull request #102 from zianazhao/master
feat
2 parents 807623e + 6a1a417 commit 81349e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+763
-223
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ products:
115115
range_seconds: 300 // 可选, 选取时间范围, 开始时间=now-range_seconds, 结束时间=now
116116
delay_seconds: 60 // 可选, 时间偏移量, 结束时间=now-delay_seconds
117117
metric_name_type: 1 // 可选,导出指标的名字格式化类型, 1=大写转小写加下划线, 2=转小写; 默认2
118-
relod_interval_minutes: 60 // 可选, 在all_instances=true时, 周期reload实例列表, 建议频率不要太频繁
118+
reload_interval_minutes: 60 // 可选, 在all_instances=true时, 周期reload实例列表, 建议频率不要太频繁
119119

120120

121121
// 单个指标纬度配置, 每个指标一个item

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ require (
1212
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.334
1313
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.413
1414
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.437
15+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.634 // indirect
1516
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.334
1617
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.334
1718
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cmq v1.0.334
18-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.576
19+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.634
1920
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.334
2021
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.413
2122
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.334

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.413 h1:6cQPfHc
220220
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.413/go.mod h1:TEuicyMWitW1zPkLbknGYg+VBGNE5N7GckvCF+hurWo=
221221
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.437 h1:siozcBuF+BM1j2+nTAUMap7rUNJrBgFvxS8pM8TqY/M=
222222
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.437/go.mod h1:NSx2qKvoTWBKc1hBp5oUNwbbR3tzdBuTqfnAmb71KBo=
223+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.634 h1:r8qQAHGEQU16qBvAPD/Ws7iHCj74WiTsn3bCa2WbZUg=
224+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.634/go.mod h1:fkxeKfvsWh1A+wyS2zULxvGmVqltbqJwPHnS8aJcsjM=
223225
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.334 h1:LOXFeP3NHL/0PFFXA2GhYH/i7rDbcBwhcJJvqRdFO/w=
224226
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.334/go.mod h1:toYhD7pJDpz6XY3cf/zhUXtKDRt1CbLkgmOidQ2j8kA=
225227
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.334 h1:NeYNgw78v+qhxWbROjHaazaeEWigt6xTvg7CUS1dt6g=
@@ -241,6 +243,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.534 h1:ZsJC
241243
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.534/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
242244
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.576 h1:6L4MeAnCk1NkuKoSfJvNPxqOrXq/HG9FqV3jl6i5t+w=
243245
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.576/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
246+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.634 h1:xSW5zhVEl+Lp7gJ9Bah1XUAzpGdLB1JrcFmJ+r16RJw=
247+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.634/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
244248
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.334 h1:ulfSODMy8rpKa8MfnTIPbe5HyOArnlB4RJ1qmpj09to=
245249
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.334/go.mod h1:AqyM/ZZMD7q5mHBqNY9YImbSpEpoEe7E/vrTbUWX+po=
246250
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.413 h1:MomwSkFrSLB16s51Yu1h4JO+p3Pzc1yesIj+oNwAVM0=

pkg/client/client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
cbs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs/v20170312"
1212
cdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb/v20170320"
1313
cdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
14+
cfs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs/v20190719"
1415
kafka "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka/v20190819"
1516
clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
1617
cmq "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cmq/v20190304"
@@ -353,3 +354,13 @@ func NewWafClient(cred common.CredentialIface, conf *config.TencentConfig) (*waf
353354
}
354355
return waf.NewClient(cred, conf.Credential.Region, cpf)
355356
}
357+
358+
func NewCfsClient(cred common.CredentialIface, conf *config.TencentConfig) (*cfs.Client, error) {
359+
cpf := profile.NewClientProfile()
360+
if conf.Credential.IsInternal == true {
361+
cpf.HttpProfile.Endpoint = "cfs.internal.tencentcloudapi.com"
362+
} else {
363+
cpf.HttpProfile.Endpoint = "cfs.tencentcloudapi.com"
364+
}
365+
return cfs.NewClient(cred, conf.Credential.Region, cpf)
366+
}

pkg/collector/collector.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ func NewTcMonitorCollector(cred common.CredentialIface, conf *config.TencentConf
116116
level.Info(logger).Log("msg", "Create product collecter ok", "Namespace", namespace)
117117

118118
if pconf.IsReloadEnable() {
119-
relodInterval := time.Duration(pconf.RelodIntervalMinutes * int64(time.Minute))
120-
reloader := NewTcProductCollectorReloader(context.TODO(), collector, relodInterval, logger)
119+
reloadInterval := time.Duration(pconf.ReloadIntervalMinutes * int64(time.Minute))
120+
reloader := NewTcProductCollectorReloader(context.TODO(), collector, reloadInterval, logger)
121121
reloaders[namespace] = reloader
122122
go reloader.Run()
123123
level.Info(logger).Log(
124124
"msg", fmt.Sprintf("reload %s instances every %d minutes",
125-
namespace, pconf.RelodIntervalMinutes),
125+
namespace, pconf.ReloadIntervalMinutes),
126126
)
127127
}
128128
}

pkg/collector/handler.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ type ProductHandler interface {
2020
// 获取云监控指标namespace
2121
GetNamespace() string
2222
// 对指标元数据做检验, true=可用, false=跳过
23-
IsMetricMetaVaild(meta *metric.TcmMeta) bool
23+
IsMetricMetaValid(meta *metric.TcmMeta) bool
2424
// 修改指标元数据
2525
ModifyMetricMeta(meta *metric.TcmMeta) error
2626
// 对指标做校验, true=可用, false=跳过
27-
IsMetricVaild(m *metric.TcmMetric) bool
27+
IsMetricValid(m *metric.TcmMetric) bool
2828
// 修改指标
2929
ModifyMetric(m *metric.TcmMetric) error
3030
// 获取该指标下符合条件的所有实例, 并生成所有的series
@@ -42,15 +42,15 @@ type baseProductHandler struct {
4242
logger log.Logger
4343
}
4444

45-
func (h *baseProductHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool {
45+
func (h *baseProductHandler) IsMetricMetaValid(meta *metric.TcmMeta) bool {
4646
return true
4747
}
4848

4949
func (h *baseProductHandler) ModifyMetricMeta(meta *metric.TcmMeta) error {
5050
return nil
5151
}
5252

53-
func (h *baseProductHandler) IsMetricVaild(m *metric.TcmMetric) bool {
53+
func (h *baseProductHandler) IsMetricValid(m *metric.TcmMetric) bool {
5454
p, err := m.Meta.GetPeriod(m.Conf.StatPeriodSeconds)
5555
if err != nil {
5656
return false
@@ -95,7 +95,7 @@ func (h *baseProductHandler) GetSeriesByOnly(m *metric.TcmMetric) ([]*metric.Tcm
9595
s, err := metric.NewTcmSeries(m, ql, ins)
9696
if err != nil {
9797
level.Error(h.logger).Log("msg", "Create metric series fail",
98-
"metric", m.Meta.MetricName, "instacne", insId)
98+
"metric", m.Meta.MetricName, "instance", insId)
9999
continue
100100
}
101101
slist = append(slist, s)
@@ -119,7 +119,7 @@ func (h *baseProductHandler) GetSeriesByAll(m *metric.TcmMetric) ([]*metric.TcmS
119119
s, err := metric.NewTcmSeries(m, ql, ins)
120120
if err != nil {
121121
level.Error(h.logger).Log("msg", "Create metric series fail",
122-
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
122+
"metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
123123
continue
124124
}
125125
slist = append(slist, s)
@@ -146,7 +146,7 @@ func (h *baseProductHandler) GetSeriesByCustom(m *metric.TcmMetric) ([]*metric.T
146146
s, err := metric.NewTcmSeries(m, ql, ins)
147147
if err != nil {
148148
level.Error(h.logger).Log("msg", "Create metric series fail",
149-
"err", err, "metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
149+
"err", err, "metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
150150
continue
151151
}
152152
slist = append(slist, s)

pkg/collector/handler_cbs.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ type cbsHandler struct {
2424
instanceInfosRepo instance.CbsTcInstanceInfosRepository
2525
}
2626

27-
func (h *cbsHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool {
27+
func (h *cbsHandler) IsMetricMetaValid(meta *metric.TcmMeta) bool {
2828
return true
2929
}
3030

3131
func (h *cbsHandler) GetNamespace() string {
3232
return CbsNamespace
3333
}
3434

35-
func (h *cbsHandler) IsMetricVaild(m *metric.TcmMetric) bool {
35+
func (h *cbsHandler) IsMetricValid(m *metric.TcmMetric) bool {
3636
// 暂时过滤nvme盘类指标
3737
var dimensions []string
3838
for _, v := range m.Meta.SupportDimensions {
@@ -76,7 +76,7 @@ func (h *cbsHandler) GetSeriesByOnly(m *metric.TcmMetric) ([]*metric.TcmSeries,
7676
sl, err := h.getSeriesByMetricType(m, nil, cvmIds)
7777
if err != nil {
7878
level.Error(h.logger).Log("msg", "Create metric series fail",
79-
"metric", m.Meta.MetricName, "instacne", cvmIds)
79+
"metric", m.Meta.MetricName, "instance", cvmIds)
8080
continue
8181
}
8282
slist = append(slist, sl...)
@@ -92,7 +92,7 @@ func (h *cbsHandler) GetSeriesByOnly(m *metric.TcmMetric) ([]*metric.TcmSeries,
9292
sl, err := h.getSeriesByMetricType(m, ins, nil)
9393
if err != nil {
9494
level.Error(h.logger).Log("msg", "Create metric series fail",
95-
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
95+
"metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
9696
continue
9797
}
9898
slist = append(slist, sl...)
@@ -112,7 +112,7 @@ func (h *cbsHandler) GetSeriesByAll(m *metric.TcmMetric) ([]*metric.TcmSeries, e
112112
sl, err := h.getSeriesByMetricType(m, nil, nil)
113113
if err != nil {
114114
level.Error(h.logger).Log("msg", "Create metric series fail",
115-
"metric", m.Meta.MetricName, "instacne")
115+
"metric", m.Meta.MetricName, "instance")
116116
}
117117
slist = append(slist, sl...)
118118
} else {
@@ -128,7 +128,7 @@ func (h *cbsHandler) GetSeriesByAll(m *metric.TcmMetric) ([]*metric.TcmSeries, e
128128
sl, err := h.getSeriesByMetricType(m, ins, nil)
129129
if err != nil {
130130
level.Error(h.logger).Log("msg", "Create metric series fail",
131-
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
131+
"metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
132132
continue
133133
}
134134
slist = append(slist, sl...)
@@ -157,7 +157,7 @@ func (h *cbsHandler) GetSeriesByCustom(m *metric.TcmMetric) ([]*metric.TcmSeries
157157
sl, err := h.getSeriesByMetricType(m, ins, nil)
158158
if err != nil {
159159
level.Error(h.logger).Log("msg", "Create metric series fail",
160-
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
160+
"metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
161161
continue
162162
}
163163
slist = append(slist, sl...)

pkg/collector/handler_cdb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ type cdbHandler struct {
2828
baseProductHandler
2929
}
3030

31-
func (h *cdbHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool {
31+
func (h *cdbHandler) IsMetricMetaValid(meta *metric.TcmMeta) bool {
3232
return true
3333
}
3434

3535
func (h *cdbHandler) GetNamespace() string {
3636
return CdbNamespace
3737
}
3838

39-
func (h *cdbHandler) IsMetricVaild(m *metric.TcmMetric) bool {
39+
func (h *cdbHandler) IsMetricValid(m *metric.TcmMetric) bool {
4040
_, ok := excludeMetricName[m.Meta.MetricName]
4141
if ok {
4242
return false

pkg/collector/handler_cdn.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ type cdnHandler struct {
2323
baseProductHandler
2424
}
2525

26-
func (h *cdnHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool {
26+
func (h *cdnHandler) IsMetricMetaValid(meta *metric.TcmMeta) bool {
2727
return true
2828
}
2929

3030
func (h *cdnHandler) GetNamespace() string {
3131
return CdnNamespace
3232
}
3333

34-
func (h *cdnHandler) IsMetricVaild(m *metric.TcmMetric) bool {
34+
func (h *cdnHandler) IsMetricValid(m *metric.TcmMetric) bool {
3535
_, ok := excludeMetricName[m.Meta.MetricName]
3636
if ok {
3737
return false
@@ -82,7 +82,7 @@ func (h *cdnHandler) GetSeriesByOnly(m *metric.TcmMetric) ([]*metric.TcmSeries,
8282
s, err := metric.NewTcmSeries(m, ql, ins)
8383
if err != nil {
8484
level.Error(h.logger).Log("msg", "Create metric series fail",
85-
"metric", m.Meta.MetricName, "instacne", insId)
85+
"metric", m.Meta.MetricName, "instance", insId)
8686
continue
8787
}
8888
slist = append(slist, s)
@@ -113,7 +113,7 @@ func (h *cdnHandler) GetSeriesByAll(m *metric.TcmMetric) ([]*metric.TcmSeries, e
113113
s, err := metric.NewTcmSeries(m, ql, ins)
114114
if err != nil {
115115
level.Error(h.logger).Log("msg", "Create metric series fail",
116-
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
116+
"metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
117117
continue
118118
}
119119
slist = append(slist, s)

0 commit comments

Comments
 (0)