-
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 cbs product * docs: add region & product show Co-authored-by: juexiaolin(林觉霄) <[email protected]>
- Loading branch information
1 parent
2ee85f9
commit 4d52db5
Showing
6 changed files
with
184 additions
and
6 deletions.
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,43 @@ | ||
package collector | ||
|
||
import ( | ||
"github.com/go-kit/kit/log" | ||
"github.com/tencentyun/tencentcloud-exporter/pkg/metric" | ||
) | ||
|
||
const ( | ||
CbsNamespace = "QCE/BLOCK_STORAGE" | ||
CbsInstanceidKey = "diskId" | ||
) | ||
|
||
func init() { | ||
registerHandler(CbsNamespace, defaultHandlerEnabled, NewCbsHandler) | ||
} | ||
|
||
type cbsHandler struct { | ||
baseProductHandler | ||
} | ||
|
||
func (h *cbsHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool { | ||
return true | ||
} | ||
|
||
func (h *cbsHandler) GetNamespace() string { | ||
return CbsNamespace | ||
} | ||
|
||
func (h *cbsHandler) IsMetricVaild(m *metric.TcmMetric) bool { | ||
return true | ||
} | ||
|
||
func NewCbsHandler(c *TcProductCollector, logger log.Logger) (handler ProductHandler, err error) { | ||
handler = &cbsHandler{ | ||
baseProductHandler{ | ||
monitorQueryKey: CbsInstanceidKey, | ||
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/cbs/v20170312" | ||
) | ||
|
||
type CbsTcInstance struct { | ||
baseTcInstance | ||
meta *sdk.Disk | ||
} | ||
|
||
func (ins *CbsTcInstance) GetMeta() interface{} { | ||
return ins.meta | ||
} | ||
|
||
func NewCbsTcInstance(instanceId string, meta *sdk.Disk) (ins *CbsTcInstance, err error) { | ||
if instanceId == "" { | ||
return nil, fmt.Errorf("instanceId is empty ") | ||
} | ||
if meta == nil { | ||
return nil, fmt.Errorf("meta is empty ") | ||
} | ||
ins = &CbsTcInstance{ | ||
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,91 @@ | ||
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/cbs/v20170312" | ||
"github.com/tencentyun/tencentcloud-exporter/pkg/client" | ||
"github.com/tencentyun/tencentcloud-exporter/pkg/config" | ||
) | ||
|
||
func init() { | ||
registerRepository("QCE/BLOCK_STORAGE", NewCbsTcInstanceRepository) | ||
} | ||
|
||
type CbsTcInstanceRepository struct { | ||
client *sdk.Client | ||
logger log.Logger | ||
} | ||
|
||
func (repo *CbsTcInstanceRepository) GetInstanceKey() string { | ||
return "DiskId" | ||
} | ||
|
||
func (repo *CbsTcInstanceRepository) Get(id string) (instance TcInstance, err error) { | ||
req := sdk.NewDescribeDisksRequest() | ||
req.DiskIds = []*string{&id} | ||
resp, err := repo.client.DescribeDisks(req) | ||
if err != nil { | ||
return | ||
} | ||
if len(resp.Response.DiskSet) != 1 { | ||
return nil, fmt.Errorf("Response instanceDetails size != 1, id=%s ", id) | ||
} | ||
meta := resp.Response.DiskSet[0] | ||
instance, err = NewCbsTcInstance(id, meta) | ||
if err != nil { | ||
return | ||
} | ||
return | ||
} | ||
|
||
func (repo *CbsTcInstanceRepository) ListByIds(id []string) (instances []TcInstance, err error) { | ||
return | ||
} | ||
|
||
func (repo *CbsTcInstanceRepository) ListByFilters(filters map[string]string) (instances []TcInstance, err error) { | ||
req := sdk.NewDescribeDisksRequest() | ||
var offset uint64 = 0 | ||
var limit uint64 = 100 | ||
var total uint64 = 0 | ||
|
||
req.Offset = &offset | ||
req.Limit = &limit | ||
|
||
getMoreInstances: | ||
resp, err := repo.client.DescribeDisks(req) | ||
if err != nil { | ||
return | ||
} | ||
if total == 0 { | ||
total = *resp.Response.TotalCount | ||
} | ||
for _, meta := range resp.Response.DiskSet { | ||
ins, e := NewCbsTcInstance(*meta.DiskId, meta) | ||
if e != nil { | ||
level.Error(repo.logger).Log("msg", "Create cbs instance fail", "id", *meta.DiskId) | ||
continue | ||
} | ||
instances = append(instances, ins) | ||
} | ||
offset += limit | ||
if offset < total { | ||
req.Offset = &offset | ||
goto getMoreInstances | ||
} | ||
return | ||
} | ||
|
||
func NewCbsTcInstanceRepository(c *config.TencentConfig, logger log.Logger) (repo TcInstanceRepository, err error) { | ||
cli, err := client.NewCbsClient(c) | ||
if err != nil { | ||
return | ||
} | ||
repo = &CbsTcInstanceRepository{ | ||
client: cli, | ||
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