-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new product SqlServer metrics export
- Loading branch information
1 parent
b409a10
commit fc7153f
Showing
7 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
credential: | ||
access_key: "access_key" | ||
secret_key: "secret_key" | ||
region: "region" | ||
|
||
rate_limit: 15 #云监控拉数据接口最大限制, 20/秒, 1200/分钟, https://cloud.tencent.com/document/product/248/31014 | ||
|
||
products: | ||
- namespace: QCE/SQLSERVER #指标详情: https://cloud.tencent.com/document/product/248/45146 | ||
all_metrics: true | ||
all_instances: true | ||
#only_include_metrics: [] | ||
#only_include_instances: [mssql-xxxxxxxx] | ||
#extra_labels: [InstanceId,Name,Region,Vip] | ||
#statistics_types: [last] | ||
period_seconds: 300 | ||
#metric_name_type: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package collector | ||
|
||
import ( | ||
"github.com/go-kit/kit/log" | ||
|
||
"github.com/tencentyun/tencentcloud-exporter/pkg/metric" | ||
) | ||
|
||
const ( | ||
SqlServerNamespace = "QCE/SQLSERVER" | ||
SqlServerInstanceidKey = "resourceId" | ||
) | ||
|
||
func init() { | ||
registerHandler(SqlServerNamespace, defaultHandlerEnabled, NewSqlServerHandler) | ||
} | ||
|
||
type sqlServerHandler struct { | ||
baseProductHandler | ||
} | ||
|
||
func (h *sqlServerHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool { | ||
return true | ||
} | ||
|
||
func (h *sqlServerHandler) GetNamespace() string { | ||
return SqlServerNamespace | ||
} | ||
|
||
func (h *sqlServerHandler) IsMetricVaild(m *metric.TcmMetric) bool { | ||
return true | ||
} | ||
|
||
func NewSqlServerHandler(c *TcProductCollector, logger log.Logger) (handler ProductHandler, err error) { | ||
handler = &sqlServerHandler{ | ||
baseProductHandler{ | ||
monitorQueryKey: SqlServerInstanceidKey, | ||
collector: c, | ||
logger: logger, | ||
}, | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package instance | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
sdk "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver/v20180328" | ||
) | ||
|
||
type SqlServerTcInstance struct { | ||
baseTcInstance | ||
meta *sdk.DBInstance | ||
} | ||
|
||
func (ins *SqlServerTcInstance) GetMeta() interface{} { | ||
return ins.meta | ||
} | ||
|
||
func NewSqlServerTcInstance(instanceId string, meta *sdk.DBInstance) (ins *SqlServerTcInstance, err error) { | ||
if instanceId == "" { | ||
return nil, fmt.Errorf("instanceId is empty ") | ||
} | ||
if meta == nil { | ||
return nil, fmt.Errorf("meta is empty ") | ||
} | ||
ins = &SqlServerTcInstance{ | ||
baseTcInstance: baseTcInstance{ | ||
instanceId: instanceId, | ||
value: reflect.ValueOf(*meta), | ||
}, | ||
meta: meta, | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package instance | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/go-kit/kit/log/level" | ||
sdk "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver/v20180328" | ||
|
||
"github.com/tencentyun/tencentcloud-exporter/pkg/client" | ||
"github.com/tencentyun/tencentcloud-exporter/pkg/config" | ||
) | ||
|
||
func init() { | ||
registerRepository("QCE/SQLSERVER", NewSqlServerTcInstanceRepository) | ||
} | ||
|
||
type SqlServerTcInstanceRepository struct { | ||
client *sdk.Client | ||
logger log.Logger | ||
} | ||
|
||
func (repo *SqlServerTcInstanceRepository) GetInstanceKey() string { | ||
return "InstanceId" | ||
} | ||
|
||
func (repo *SqlServerTcInstanceRepository) Get(id string) (instance TcInstance, err error) { | ||
req := sdk.NewDescribeDBInstancesRequest() | ||
req.InstanceIdSet = []*string{&id} | ||
resp, err := repo.client.DescribeDBInstances(req) | ||
if err != nil { | ||
return | ||
} | ||
if len(resp.Response.DBInstances) != 1 { | ||
return nil, fmt.Errorf("Response instanceDetails size != 1, id=%s ", id) | ||
} | ||
meta := resp.Response.DBInstances[0] | ||
instance, err = NewSqlServerTcInstance(id, meta) | ||
if err != nil { | ||
return | ||
} | ||
return | ||
} | ||
|
||
func (repo *SqlServerTcInstanceRepository) ListByIds(id []string) (instances []TcInstance, err error) { | ||
return | ||
} | ||
|
||
func (repo *SqlServerTcInstanceRepository) ListByFilters(filters map[string]string) (instances []TcInstance, err error) { | ||
req := sdk.NewDescribeDBInstancesRequest() | ||
var offset int64 = 0 | ||
var limit int64 = 100 | ||
var total int64 = -1 | ||
|
||
req.Offset = &offset | ||
req.Limit = &limit | ||
|
||
getMoreInstances: | ||
resp, err := repo.client.DescribeDBInstances(req) | ||
if err != nil { | ||
return | ||
} | ||
if total == -1 { | ||
total = *resp.Response.TotalCount | ||
} | ||
for _, meta := range resp.Response.DBInstances { | ||
ins, e := NewSqlServerTcInstance(*meta.InstanceId, meta) | ||
if e != nil { | ||
level.Error(repo.logger).Log("msg", "Create cdb instance fail", "id", *meta.InstanceId) | ||
continue | ||
} | ||
instances = append(instances, ins) | ||
} | ||
offset += limit | ||
if offset < total { | ||
req.Offset = &offset | ||
goto getMoreInstances | ||
} | ||
|
||
return | ||
} | ||
|
||
func NewSqlServerTcInstanceRepository(c *config.TencentConfig, logger log.Logger) (repo TcInstanceRepository, err error) { | ||
cli, err := client.NewSqlServerClient(c) | ||
if err != nil { | ||
return | ||
} | ||
repo = &SqlServerTcInstanceRepository{ | ||
client: cli, | ||
logger: logger, | ||
} | ||
return | ||
} |