Skip to content

Commit ebe4788

Browse files
committed
support tdmysql/eip
1 parent c98d51a commit ebe4788

File tree

13 files changed

+392
-3
lines changed

13 files changed

+392
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ PostgreSQL|QCE/POSTGRES|[指标详情](https://cloud.tencent.com/document/produc
3030
CKafka 实例|QCE/CKAFKA|[指标详情](https://cloud.tencent.com/document/product/248/45121)
3131
Memcached |QCE/MEMCACHED|指标详情说明文档(待上线)
3232
Lighthouse |QCE/LIGHTHOUSE|指标详情说明文档(待上线)
33+
分布式数据库 TDSQL MySQL 实例|QCE/TDMYSQL|[指标详情](https://cloud.tencent.com/document/product/248/54401)
34+
弹性公网 IP|QCE/LB|[指标详情](https://cloud.tencent.com/document/product/248/45099)
3335

3436
`后续会有更多的产品支持`
3537

configs/qcloud-eip-product.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
credential:
2+
access_key: "access_key"
3+
secret_key: "secret_key"
4+
region: "region"
5+
6+
rate_limit: 15 #云监控拉数据接口最大限制, 20/秒, 1200/分钟, https://cloud.tencent.com/document/product/248/31014
7+
8+
products:
9+
- namespace: QCE/LB #指标详情: https://cloud.tencent.com/document/product/248/45099
10+
all_metrics: true
11+
only_include_instances: ['eip-xxxx']
12+
extra_labels: [AddressName]
13+
#all_instances: true
14+
#only_include_metrics: []
15+
#statistics_types: [last]
16+
#period_seconds: 60
17+
#metric_name_type: 2

configs/qcloud-es-product.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ credential:
66
rate_limit: 10 #云监控拉数据接口最大限制, 20/秒, 1200/分钟, https://cloud.tencent.com/document/product/248/31014
77

88
products:
9-
- namespace: QCE/ES #指标详情: https://cloud.tencent.com/document/product/248/45129
9+
- namespace: QCE/CES #指标详情: https://cloud.tencent.com/document/product/248/45129
1010
all_metrics: true
1111
all_instances: true
1212
extra_labels: [InstanceName]

configs/qcloud-tdmysql-product.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
credential:
2+
access_key: "access_key"
3+
secret_key: "secret_key"
4+
region: "region"
5+
6+
rate_limit: 15 #云监控拉数据接口最大限制, 20/秒, 1200/分钟, https://cloud.tencent.com/document/product/248/31014
7+
8+
products:
9+
- namespace: QCE/TDMYSQL #指标详情: https://cloud.tencent.com/document/product/248/54401
10+
all_metrics: true
11+
only_include_instances: [ 'tdsqlshard-xxxx' ]
12+
extra_labels: [ InstanceName ]
13+
#all_instances: true
14+
#only_include_metrics: []
15+
#statistics_types: [last]
16+
#period_seconds: 60
17+
#metric_name_type: 2

pkg/client/client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
1111
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
1212
dc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc/v20180410"
13+
dcdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb/v20180411"
1314
es "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es/v20180416"
1415
lh "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse/v20200324"
1516
mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312"
@@ -186,3 +187,12 @@ func NewKafkaClient(conf *config.TencentConfig) (*kafka.Client, error) {
186187
cpf := profile.NewClientProfile()
187188
return kafka.NewClient(credential, conf.Credential.Region, cpf)
188189
}
190+
191+
func NewDCDBClient(conf *config.TencentConfig) (*dcdb.Client, error) {
192+
credential := common.NewCredential(
193+
conf.Credential.AccessKey,
194+
conf.Credential.SecretKey,
195+
)
196+
cpf := profile.NewClientProfile()
197+
return dcdb.NewClient(credential, conf.Credential.Region, cpf)
198+
}

pkg/collector/handler_dcdb.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package collector
2+
3+
import (
4+
"github.com/go-kit/kit/log"
5+
"github.com/tencentyun/tencentcloud-exporter/pkg/metric"
6+
)
7+
8+
const (
9+
DcdbNamespace = "QCE/TDMYSQL"
10+
DcdbInstanceidKey = "InstanceId"
11+
)
12+
13+
func init() {
14+
registerHandler(DcdbNamespace, defaultHandlerEnabled, NewDcdbHandler)
15+
}
16+
17+
type dcdbHandler struct {
18+
baseProductHandler
19+
}
20+
21+
func (h *dcdbHandler) GetNamespace() string {
22+
return DcdbNamespace
23+
}
24+
25+
func (h *dcdbHandler) IsMetricVaild(m *metric.TcmMetric) bool {
26+
// ignore node/shard metric, bug for cloud monitor if filter dim
27+
if len(m.Meta.SupportDimensions) != 1 {
28+
return false
29+
}
30+
return true
31+
}
32+
33+
func NewDcdbHandler(c *TcProductCollector, logger log.Logger) (handler ProductHandler, err error) {
34+
handler = &dcdbHandler{
35+
baseProductHandler{
36+
monitorQueryKey: DcdbInstanceidKey,
37+
collector: c,
38+
logger: logger,
39+
},
40+
}
41+
return
42+
43+
}

pkg/collector/handler_eip.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package collector
2+
3+
import (
4+
"github.com/go-kit/kit/log"
5+
"github.com/tencentyun/tencentcloud-exporter/pkg/metric"
6+
)
7+
8+
const (
9+
EIPNamespace = "QCE/LB"
10+
EIPInstanceidKey = "eip"
11+
)
12+
13+
func init() {
14+
registerHandler(EIPNamespace, defaultHandlerEnabled, NewEIPHandler)
15+
}
16+
17+
type eipHandler struct {
18+
baseProductHandler
19+
}
20+
21+
func (h *eipHandler) GetNamespace() string {
22+
return EIPNamespace
23+
}
24+
func (h *eipHandler) IsMetricVaild(m *metric.TcmMetric) bool {
25+
// ignore node/shard metric, bug for cloud monitor if filter dim
26+
if len(m.Meta.SupportDimensions) != 1 {
27+
return false
28+
}
29+
return true
30+
}
31+
func NewEIPHandler(c *TcProductCollector, logger log.Logger) (handler ProductHandler, err error) {
32+
handler = &eipHandler{
33+
baseProductHandler{
34+
monitorQueryKey: EIPInstanceidKey,
35+
collector: c,
36+
logger: logger,
37+
},
38+
}
39+
return
40+
41+
}

pkg/collector/product.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ func (c *TcProductCollector) LoadMetricsByProductConf() error {
8484
level.Warn(c.logger).Log("msg", "Create metric fail", "err", err, "Namespace", c.Namespace, "name", mname)
8585
continue
8686
}
87+
if nm == nil {
88+
// maybe some metric not support
89+
continue
90+
}
8791
c.MetricMap[nm.Meta.MetricName] = nm
8892

8993
// 获取该指标下的所有实例纬度查询或自定义纬度查询
@@ -164,7 +168,8 @@ func (c *TcProductCollector) createMetricWithProductConf(mname string, pconf con
164168
}
165169
// 指标过滤
166170
if !c.handler.IsMetricVaild(nm) {
167-
return nil, fmt.Errorf("metric not support")
171+
// ignore invalid metric
172+
return nil, nil
168173
}
169174
err = c.handler.ModifyMetric(nm)
170175
if err != nil {

pkg/config/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ var (
5353
"postgres": "QCE/POSTGRES",
5454
"memcached": "QCE/MEMCACHED",
5555
"lighthouse": "QCE/LIGHTHOUSE",
56-
"ckafka": "QCE/CKAFKA",
56+
"ckafka": "QCE/CKAFKA",
57+
"tdmysql": "QCE/TDMYSQL",
58+
"lb": "QCE/LB", // for eip
5759
}
5860

5961
SupportStatisticsTypes = map[string]bool{

pkg/instance/instance_dcdb.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package instance
2+
3+
import (
4+
"fmt"
5+
"reflect"
6+
7+
sdk "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb/v20180411"
8+
)
9+
10+
type DcdbTcInstance struct {
11+
baseTcInstance
12+
meta *sdk.DCDBInstanceInfo
13+
}
14+
15+
func (ins *DcdbTcInstance) GetMeta() interface{} {
16+
return ins.meta
17+
}
18+
19+
func NewDcdbTcInstance(instanceId string, meta *sdk.DCDBInstanceInfo) (ins *DcdbTcInstance, err error) {
20+
if instanceId == "" {
21+
return nil, fmt.Errorf("instanceId is empty ")
22+
}
23+
if meta == nil {
24+
return nil, fmt.Errorf("meta is empty ")
25+
}
26+
ins = &DcdbTcInstance{
27+
baseTcInstance: baseTcInstance{
28+
instanceId: instanceId,
29+
value: reflect.ValueOf(*meta),
30+
},
31+
meta: meta,
32+
}
33+
return
34+
}

0 commit comments

Comments
 (0)