From d5058caccc07f72542b2344702e30cc766bbc5cb Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 1 Mar 2021 12:05:45 +0200 Subject: [PATCH] lib/promscrape: add vm_promscrape_scrapework_cache_* metrics for tracking ScrapeWork cache effectiveness --- lib/promscrape/config.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 59d49b832..28e5959c6 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -566,6 +566,7 @@ func newScrapeWorkCache() *scrapeWorkCache { } func (swc *scrapeWorkCache) Get(key string) *ScrapeWork { + scrapeWorkCacheRequests.Inc() currentTime := fasttime.UnixTimestamp() swc.mu.Lock() swe := swc.m[key] @@ -576,9 +577,15 @@ func (swc *scrapeWorkCache) Get(key string) *ScrapeWork { if swe == nil { return nil } + scrapeWorkCacheHits.Inc() return swe.sw } +var ( + scrapeWorkCacheRequests = metrics.NewCounter(`vm_promscrape_scrapework_cache_requests_total`) + scrapeWorkCacheHits = metrics.NewCounter(`vm_promscrape_scrapework_cache_hits_total`) +) + func (swc *scrapeWorkCache) Set(key string, sw *ScrapeWork) { currentTime := fasttime.UnixTimestamp() swc.mu.Lock()