/
handler_cvm.go
65 lines (52 loc) · 1.45 KB
/
handler_cvm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package collector
import (
"strings"
"github.com/go-kit/log"
"github.com/tencentyun/tencentcloud-exporter/pkg/common"
"github.com/tencentyun/tencentcloud-exporter/pkg/metric"
"github.com/tencentyun/tencentcloud-exporter/pkg/util"
)
const (
CvmNamespace = "QCE/CVM"
CvmInstanceidKey = "InstanceId"
)
var (
CvmInvalidMetricNames = []string{"dccpuusage", "dcmemusage"}
)
func init() {
registerHandler(CvmNamespace, defaultHandlerEnabled, NewCvmHandler)
}
type cvmHandler struct {
baseProductHandler
}
func (h *cvmHandler) IsMetricMetaValid(meta *metric.TcmMeta) bool {
if !util.IsStrInList(meta.SupportDimensions, CvmInstanceidKey) {
meta.SupportDimensions = append(meta.SupportDimensions, CvmInstanceidKey)
}
return true
}
func (h *cvmHandler) GetNamespace() string {
return CvmNamespace
}
func (h *cvmHandler) IsMetricValid(m *metric.TcmMetric) bool {
if util.IsStrInList(CvmInvalidMetricNames, strings.ToLower(m.Meta.MetricName)) {
return false
}
return true
}
func (h *cvmHandler) GetSeries(m *metric.TcmMetric) (slist []*metric.TcmSeries, err error) {
if m.Conf.StatPeriodSeconds < 60 {
m.Conf.StatPeriodSeconds = 60
}
return h.baseProductHandler.GetSeries(m)
}
func NewCvmHandler(cred common.CredentialIface, c *TcProductCollector, logger log.Logger) (handler ProductHandler, err error) {
handler = &cvmHandler{
baseProductHandler{
monitorQueryKey: CvmInstanceidKey,
collector: c,
logger: logger,
},
}
return
}