From 56a0b058c1ae9a6a045cb145990702df8bc8cce0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 8 Dec 2020 01:54:13 +0200 Subject: [PATCH] lib/promscrape: export `vm_promscrape_active_scrapers{type=""}` metric for tracking the number of active scrapers per each service discovery type --- docs/CHANGELOG.md | 1 + lib/promscrape/scraper.go | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3734f9d668..539d0150cf 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,7 @@ * FEATURE: allow multiple whitespace chars between measurements, fields and timestamp when parsing InfluxDB line protocol. Though [InfluxDB line protocol](https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/) denies multiple whitespace chars between these entities, some apps improperly put multiple whitespace chars. This workaround allows accepting data from such apps. +* FEATURE: export `vm_promscrape_active_scrapers{type=""}` metric for tracking the number of active scrapers per each service discovery type. * BUGFIX: prevent from duplicate `name` tag returned from `/tags/autoComplete/tags` handler. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/942 * BUGFIX: do not enable strict parsing for `-promscrape.config` if `-promscrape.config.dryRun` comand-line flag is set. Strict parsing can be enabled with `-promscrape.config.strictParse` command-line flag. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/944 diff --git a/lib/promscrape/scraper.go b/lib/promscrape/scraper.go index ccb0d4aaff..db5f3dde3a 100644 --- a/lib/promscrape/scraper.go +++ b/lib/promscrape/scraper.go @@ -244,20 +244,24 @@ func (scfg *scrapeConfig) run() { } type scraperGroup struct { - name string - wg sync.WaitGroup - mLock sync.Mutex - m map[string]*scraper - pushData func(wr *prompbmarshal.WriteRequest) - changesCount *metrics.Counter + name string + wg sync.WaitGroup + mLock sync.Mutex + m map[string]*scraper + pushData func(wr *prompbmarshal.WriteRequest) + + changesCount *metrics.Counter + activeScrapers *metrics.Counter } func newScraperGroup(name string, pushData func(wr *prompbmarshal.WriteRequest)) *scraperGroup { sg := &scraperGroup{ - name: name, - m: make(map[string]*scraper), - pushData: pushData, - changesCount: metrics.NewCounter(fmt.Sprintf(`vm_promscrape_config_changes_total{type=%q}`, name)), + name: name, + m: make(map[string]*scraper), + pushData: pushData, + + changesCount: metrics.NewCounter(fmt.Sprintf(`vm_promscrape_config_changes_total{type=%q}`, name)), + activeScrapers: metrics.NewCounter(fmt.Sprintf(`vm_promscrape_active_scrapers{type=%q}`, name)), } metrics.NewGauge(fmt.Sprintf(`vm_promscrape_targets{type=%q, status="up"}`, name), func() float64 { return float64(tsmGlobal.StatusByGroup(sg.name, true)) @@ -308,11 +312,13 @@ func (sg *scraperGroup) update(sws []ScrapeWork) { // Start a scraper for the missing key. sc := newScraper(sw, sg.name, sg.pushData) + sg.activeScrapers.Inc() sg.wg.Add(1) go func() { defer sg.wg.Done() sc.sw.run(sc.stopCh) tsmGlobal.Unregister(sw) + sg.activeScrapers.Dec() }() tsmGlobal.Register(sw) sg.m[key] = sc