metric: Add region for duration、success collector
1. Add region for duration、success collector 2. Fix other metrics region which may be used in tracing.NewRegister Signed-off-by: Tonghao Zhang <tonghao@bamaicloud.com>
This commit is contained in:
parent
beb02323c6
commit
81265ad8a4
|
@ -83,6 +83,11 @@ func mainAction(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
blackListed := conf.Get().Tracing.BlackList
|
blackListed := conf.Get().Tracing.BlackList
|
||||||
|
prom, err := InitMetricsCollector(blackListed, conf.Region)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("InitMetricsCollector: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
mgr, err := tracing.NewMgrTracingEvent(blackListed)
|
mgr, err := tracing.NewMgrTracingEvent(blackListed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -92,13 +97,7 @@ func mainAction(ctx *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
prom, err := InitMetricsCollector(blackListed, conf.Region)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("InitMetricsCollector: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("Initialize the Metrics collector: %v", prom)
|
log.Infof("Initialize the Metrics collector: %v", prom)
|
||||||
|
|
||||||
services.Start(conf.Get().APIServer.TCPAddr, mgr, prom)
|
services.Start(conf.Get().APIServer.TCPAddr, mgr, prom)
|
||||||
|
|
||||||
// update cpu quota
|
// update cpu quota
|
||||||
|
|
|
@ -43,11 +43,17 @@ type CollectorWrapper struct {
|
||||||
type CollectorManager struct {
|
type CollectorManager struct {
|
||||||
collectors map[string]*CollectorWrapper
|
collectors map[string]*CollectorWrapper
|
||||||
hostname string
|
hostname string
|
||||||
|
region string
|
||||||
scrapeDurationDesc *prometheus.Desc
|
scrapeDurationDesc *prometheus.Desc
|
||||||
scrapeSuccessDesc *prometheus.Desc
|
scrapeSuccessDesc *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCollectorManager(blackListed []string, region string) (*CollectorManager, error) {
|
func NewCollectorManager(blackListed []string, region string) (*CollectorManager, error) {
|
||||||
|
// Init defaultRegion, defaultHostname firstly,
|
||||||
|
// NewGaugeData may be used for data caching in tracing.NewRegister.
|
||||||
|
hostname, _ := os.Hostname()
|
||||||
|
defaultRegion, defaultHostname = region, hostname
|
||||||
|
|
||||||
tracings, err := tracing.NewRegister(blackListed)
|
tracings, err := tracing.NewRegister(blackListed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -68,23 +74,20 @@ func NewCollectorManager(blackListed []string, region string) (*CollectorManager
|
||||||
scrapeDurationDesc := prometheus.NewDesc(
|
scrapeDurationDesc := prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(promNamespace, "scrape", "collector_duration_seconds"),
|
prometheus.BuildFQName(promNamespace, "scrape", "collector_duration_seconds"),
|
||||||
promNamespace+": Duration of a collector scrape.",
|
promNamespace+": Duration of a collector scrape.",
|
||||||
[]string{LabelHost, "collector"},
|
[]string{LabelHost, LabelRegion, "collector"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
scrapeSuccessDesc := prometheus.NewDesc(
|
scrapeSuccessDesc := prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(promNamespace, "scrape", "collector_success"),
|
prometheus.BuildFQName(promNamespace, "scrape", "collector_success"),
|
||||||
promNamespace+": Whether a collector succeeded.",
|
promNamespace+": Whether a collector succeeded.",
|
||||||
[]string{LabelHost, "collector"},
|
[]string{LabelHost, LabelRegion, "collector"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
hostname, _ := os.Hostname()
|
|
||||||
defaultRegion = region
|
|
||||||
defaultHostname = hostname
|
|
||||||
|
|
||||||
return &CollectorManager{
|
return &CollectorManager{
|
||||||
collectors: collectors,
|
collectors: collectors,
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
|
region: region,
|
||||||
scrapeDurationDesc: scrapeDurationDesc,
|
scrapeDurationDesc: scrapeDurationDesc,
|
||||||
scrapeSuccessDesc: scrapeSuccessDesc,
|
scrapeSuccessDesc: scrapeSuccessDesc,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -143,6 +146,6 @@ func (m *CollectorManager) doCollect(collectorName string, c *CollectorWrapper,
|
||||||
success = 1
|
success = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(m.scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), m.hostname, collectorName)
|
ch <- prometheus.MustNewConstMetric(m.scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), m.hostname, m.region, collectorName)
|
||||||
ch <- prometheus.MustNewConstMetric(m.scrapeSuccessDesc, prometheus.GaugeValue, success, m.hostname, collectorName)
|
ch <- prometheus.MustNewConstMetric(m.scrapeSuccessDesc, prometheus.GaugeValue, success, m.hostname, m.region, collectorName)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue