Skip to content
Merged

feat #102

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ products:
range_seconds: 300 // 可选, 选取时间范围, 开始时间=now-range_seconds, 结束时间=now
delay_seconds: 60 // 可选, 时间偏移量, 结束时间=now-delay_seconds
metric_name_type: 1 // 可选,导出指标的名字格式化类型, 1=大写转小写加下划线, 2=转小写; 默认2
relod_interval_minutes: 60 // 可选, 在all_instances=true时, 周期reload实例列表, 建议频率不要太频繁
reload_interval_minutes: 60 // 可选, 在all_instances=true时, 周期reload实例列表, 建议频率不要太频繁


// 单个指标纬度配置, 每个指标一个item
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.334
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.413
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.437
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.634 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.334
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.334
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cmq v1.0.334
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.576
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.634
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.334
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.413
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.334
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.413 h1:6cQPfHc
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.413/go.mod h1:TEuicyMWitW1zPkLbknGYg+VBGNE5N7GckvCF+hurWo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.437 h1:siozcBuF+BM1j2+nTAUMap7rUNJrBgFvxS8pM8TqY/M=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.437/go.mod h1:NSx2qKvoTWBKc1hBp5oUNwbbR3tzdBuTqfnAmb71KBo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.634 h1:r8qQAHGEQU16qBvAPD/Ws7iHCj74WiTsn3bCa2WbZUg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.634/go.mod h1:fkxeKfvsWh1A+wyS2zULxvGmVqltbqJwPHnS8aJcsjM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.334 h1:LOXFeP3NHL/0PFFXA2GhYH/i7rDbcBwhcJJvqRdFO/w=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.334/go.mod h1:toYhD7pJDpz6XY3cf/zhUXtKDRt1CbLkgmOidQ2j8kA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.334 h1:NeYNgw78v+qhxWbROjHaazaeEWigt6xTvg7CUS1dt6g=
Expand All @@ -241,6 +243,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.534 h1:ZsJC
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.534/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.576 h1:6L4MeAnCk1NkuKoSfJvNPxqOrXq/HG9FqV3jl6i5t+w=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.576/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.634 h1:xSW5zhVEl+Lp7gJ9Bah1XUAzpGdLB1JrcFmJ+r16RJw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.634/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.334 h1:ulfSODMy8rpKa8MfnTIPbe5HyOArnlB4RJ1qmpj09to=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.334/go.mod h1:AqyM/ZZMD7q5mHBqNY9YImbSpEpoEe7E/vrTbUWX+po=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.413 h1:MomwSkFrSLB16s51Yu1h4JO+p3Pzc1yesIj+oNwAVM0=
Expand Down
11 changes: 11 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
cbs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs/v20170312"
cdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb/v20170320"
cdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
cfs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs/v20190719"
kafka "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka/v20190819"
clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
cmq "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cmq/v20190304"
Expand Down Expand Up @@ -353,3 +354,13 @@ func NewWafClient(cred common.CredentialIface, conf *config.TencentConfig) (*waf
}
return waf.NewClient(cred, conf.Credential.Region, cpf)
}

func NewCfsClient(cred common.CredentialIface, conf *config.TencentConfig) (*cfs.Client, error) {
cpf := profile.NewClientProfile()
if conf.Credential.IsInternal == true {
cpf.HttpProfile.Endpoint = "cfs.internal.tencentcloudapi.com"
} else {
cpf.HttpProfile.Endpoint = "cfs.tencentcloudapi.com"
}
return cfs.NewClient(cred, conf.Credential.Region, cpf)
}
6 changes: 3 additions & 3 deletions pkg/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ func NewTcMonitorCollector(cred common.CredentialIface, conf *config.TencentConf
level.Info(logger).Log("msg", "Create product collecter ok", "Namespace", namespace)

if pconf.IsReloadEnable() {
relodInterval := time.Duration(pconf.RelodIntervalMinutes * int64(time.Minute))
reloader := NewTcProductCollectorReloader(context.TODO(), collector, relodInterval, logger)
reloadInterval := time.Duration(pconf.ReloadIntervalMinutes * int64(time.Minute))
reloader := NewTcProductCollectorReloader(context.TODO(), collector, reloadInterval, logger)
reloaders[namespace] = reloader
go reloader.Run()
level.Info(logger).Log(
"msg", fmt.Sprintf("reload %s instances every %d minutes",
namespace, pconf.RelodIntervalMinutes),
namespace, pconf.ReloadIntervalMinutes),
)
}
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/collector/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type ProductHandler interface {
// 获取云监控指标namespace
GetNamespace() string
// 对指标元数据做检验, true=可用, false=跳过
IsMetricMetaVaild(meta *metric.TcmMeta) bool
IsMetricMetaValid(meta *metric.TcmMeta) bool
// 修改指标元数据
ModifyMetricMeta(meta *metric.TcmMeta) error
// 对指标做校验, true=可用, false=跳过
IsMetricVaild(m *metric.TcmMetric) bool
IsMetricValid(m *metric.TcmMetric) bool
// 修改指标
ModifyMetric(m *metric.TcmMetric) error
// 获取该指标下符合条件的所有实例, 并生成所有的series
Expand All @@ -42,15 +42,15 @@ type baseProductHandler struct {
logger log.Logger
}

func (h *baseProductHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool {
func (h *baseProductHandler) IsMetricMetaValid(meta *metric.TcmMeta) bool {
return true
}

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

func (h *baseProductHandler) IsMetricVaild(m *metric.TcmMetric) bool {
func (h *baseProductHandler) IsMetricValid(m *metric.TcmMetric) bool {
p, err := m.Meta.GetPeriod(m.Conf.StatPeriodSeconds)
if err != nil {
return false
Expand Down Expand Up @@ -95,7 +95,7 @@ func (h *baseProductHandler) GetSeriesByOnly(m *metric.TcmMetric) ([]*metric.Tcm
s, err := metric.NewTcmSeries(m, ql, ins)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"metric", m.Meta.MetricName, "instacne", insId)
"metric", m.Meta.MetricName, "instance", insId)
continue
}
slist = append(slist, s)
Expand All @@ -119,7 +119,7 @@ func (h *baseProductHandler) GetSeriesByAll(m *metric.TcmMetric) ([]*metric.TcmS
s, err := metric.NewTcmSeries(m, ql, ins)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
"metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
continue
}
slist = append(slist, s)
Expand All @@ -146,7 +146,7 @@ func (h *baseProductHandler) GetSeriesByCustom(m *metric.TcmMetric) ([]*metric.T
s, err := metric.NewTcmSeries(m, ql, ins)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"err", err, "metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
"err", err, "metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
continue
}
slist = append(slist, s)
Expand Down
14 changes: 7 additions & 7 deletions pkg/collector/handler_cbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ type cbsHandler struct {
instanceInfosRepo instance.CbsTcInstanceInfosRepository
}

func (h *cbsHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool {
func (h *cbsHandler) IsMetricMetaValid(meta *metric.TcmMeta) bool {
return true
}

func (h *cbsHandler) GetNamespace() string {
return CbsNamespace
}

func (h *cbsHandler) IsMetricVaild(m *metric.TcmMetric) bool {
func (h *cbsHandler) IsMetricValid(m *metric.TcmMetric) bool {
// 暂时过滤nvme盘类指标
var dimensions []string
for _, v := range m.Meta.SupportDimensions {
Expand Down Expand Up @@ -76,7 +76,7 @@ func (h *cbsHandler) GetSeriesByOnly(m *metric.TcmMetric) ([]*metric.TcmSeries,
sl, err := h.getSeriesByMetricType(m, nil, cvmIds)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"metric", m.Meta.MetricName, "instacne", cvmIds)
"metric", m.Meta.MetricName, "instance", cvmIds)
continue
}
slist = append(slist, sl...)
Expand All @@ -92,7 +92,7 @@ func (h *cbsHandler) GetSeriesByOnly(m *metric.TcmMetric) ([]*metric.TcmSeries,
sl, err := h.getSeriesByMetricType(m, ins, nil)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
"metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
continue
}
slist = append(slist, sl...)
Expand All @@ -112,7 +112,7 @@ func (h *cbsHandler) GetSeriesByAll(m *metric.TcmMetric) ([]*metric.TcmSeries, e
sl, err := h.getSeriesByMetricType(m, nil, nil)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"metric", m.Meta.MetricName, "instacne")
"metric", m.Meta.MetricName, "instance")
}
slist = append(slist, sl...)
} else {
Expand All @@ -128,7 +128,7 @@ func (h *cbsHandler) GetSeriesByAll(m *metric.TcmMetric) ([]*metric.TcmSeries, e
sl, err := h.getSeriesByMetricType(m, ins, nil)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
"metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
continue
}
slist = append(slist, sl...)
Expand Down Expand Up @@ -157,7 +157,7 @@ func (h *cbsHandler) GetSeriesByCustom(m *metric.TcmMetric) ([]*metric.TcmSeries
sl, err := h.getSeriesByMetricType(m, ins, nil)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
"metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
continue
}
slist = append(slist, sl...)
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/handler_cdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ type cdbHandler struct {
baseProductHandler
}

func (h *cdbHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool {
func (h *cdbHandler) IsMetricMetaValid(meta *metric.TcmMeta) bool {
return true
}

func (h *cdbHandler) GetNamespace() string {
return CdbNamespace
}

func (h *cdbHandler) IsMetricVaild(m *metric.TcmMetric) bool {
func (h *cdbHandler) IsMetricValid(m *metric.TcmMetric) bool {
_, ok := excludeMetricName[m.Meta.MetricName]
if ok {
return false
Expand Down
8 changes: 4 additions & 4 deletions pkg/collector/handler_cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ type cdnHandler struct {
baseProductHandler
}

func (h *cdnHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool {
func (h *cdnHandler) IsMetricMetaValid(meta *metric.TcmMeta) bool {
return true
}

func (h *cdnHandler) GetNamespace() string {
return CdnNamespace
}

func (h *cdnHandler) IsMetricVaild(m *metric.TcmMetric) bool {
func (h *cdnHandler) IsMetricValid(m *metric.TcmMetric) bool {
_, ok := excludeMetricName[m.Meta.MetricName]
if ok {
return false
Expand Down Expand Up @@ -82,7 +82,7 @@ func (h *cdnHandler) GetSeriesByOnly(m *metric.TcmMetric) ([]*metric.TcmSeries,
s, err := metric.NewTcmSeries(m, ql, ins)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"metric", m.Meta.MetricName, "instacne", insId)
"metric", m.Meta.MetricName, "instance", insId)
continue
}
slist = append(slist, s)
Expand Down Expand Up @@ -113,7 +113,7 @@ func (h *cdnHandler) GetSeriesByAll(m *metric.TcmMetric) ([]*metric.TcmSeries, e
s, err := metric.NewTcmSeries(m, ql, ins)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
"metric", m.Meta.MetricName, "instance", ins.GetInstanceId())
continue
}
slist = append(slist, s)
Expand Down
Loading