lib/promscrape: add vm_promscrape_scrapework_cache_* metrics for tracking ScrapeWork cache effectiveness

This commit is contained in:
Aliaksandr Valialkin 2021-03-01 12:05:45 +02:00
parent 4e3cfe8461
commit e84153d5ca

View file

@ -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()