diff --git a/pkg/collector/handler_dcx.go b/pkg/collector/handler_dcx.go index c4dc783..a576089 100644 --- a/pkg/collector/handler_dcx.go +++ b/pkg/collector/handler_dcx.go @@ -3,6 +3,8 @@ package collector import ( "github.com/go-kit/kit/log" "github.com/tencentyun/tencentcloud-exporter/pkg/metric" + "github.com/tencentyun/tencentcloud-exporter/pkg/util" + "strings" ) const ( @@ -10,6 +12,10 @@ const ( DcxInstanceidKey = "directConnectConnId" ) +var ( + DcxInvalidMetricNames = []string{"rxbytes", "txbytes"} +) + func init() { registerHandler(DcxNamespace, defaultHandlerEnabled, NewDcxHandler) } @@ -19,6 +25,9 @@ type dcxHandler struct { } func (h *dcxHandler) CheckMetricMeta(meta *metric.TcmMeta) bool { + if util.IsStrInList(DcxInvalidMetricNames, strings.ToLower(meta.MetricName)) { + return false + } return true } diff --git a/pkg/collector/product.go b/pkg/collector/product.go index ecca64f..f38335c 100644 --- a/pkg/collector/product.go +++ b/pkg/collector/product.go @@ -124,7 +124,7 @@ func (c *TcProductCollector) loadMetricsByProductConf() (err error) { } // 指标元数据处理, false=跳过 if !c.handler.CheckMetricMeta(meta) { - level.Error(c.logger).Log("msg", " Metric meta check fail, skip", "Namespace", c.Namespace, "name", meta.MetricName) + level.Warn(c.logger).Log("msg", " Metric not support, skip", "Namespace", c.Namespace, "name", meta.MetricName) continue } @@ -143,7 +143,7 @@ func (c *TcProductCollector) loadMetricsByProductConf() (err error) { } // 指标过滤 if !c.handler.IsIncludeMetric(nm) { - level.Error(c.logger).Log("msg", " Metric not support, skip", "Namespace", c.Namespace, "name", nm.Meta.MetricName) + level.Warn(c.logger).Log("msg", " Metric not support, skip", "Namespace", c.Namespace, "name", nm.Meta.MetricName) continue } c.MetricMap[meta.MetricName] = nm diff --git a/pkg/metric/cache.go b/pkg/metric/cache.go index 553b409..cbba361 100644 --- a/pkg/metric/cache.go +++ b/pkg/metric/cache.go @@ -1,6 +1,7 @@ package metric import ( + "fmt" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "strings" @@ -20,7 +21,15 @@ func (c *TcmMetricCache) GetMeta(namespace string, name string) (*TcmMeta, error if err != nil { return nil, err } - return c.metaCache[namespace][strings.ToLower(name)], nil + np, exists := c.metaCache[namespace] + if !exists { + return nil, fmt.Errorf("namespace cache not exists") + } + m, exists := np[strings.ToLower(name)] + if !exists { + return nil, fmt.Errorf("metric cache not exists") + } + return m, nil } func (c *TcmMetricCache) ListMetaByNamespace(namespace string) ([]*TcmMeta, error) {