github.com/grafana/synthetic-monitoring-agent@v0.64.2/internal/scraper/metrics.go (about)

     1  package scraper
     2  
     3  import "github.com/prometheus/client_golang/prometheus"
     4  
     5  func NewMetrics(scrapeCounter Incrementer, errorCounter IncrementerVec) Metrics {
     6  	return metrics{
     7  		scrapeCounter: scrapeCounter,
     8  		errorCounter:  errorCounter,
     9  	}
    10  }
    11  
    12  type metrics struct {
    13  	scrapeCounter Incrementer
    14  	errorCounter  IncrementerVec
    15  }
    16  
    17  func (m metrics) AddScrape() {
    18  	m.scrapeCounter.Inc()
    19  }
    20  
    21  func (m metrics) AddCheckError() {
    22  	m.errorCounter.WithLabelValues("check").Inc()
    23  }
    24  
    25  func (m metrics) AddCollectorError() {
    26  	m.errorCounter.WithLabelValues("collector").Inc()
    27  }
    28  
    29  type Incrementer interface {
    30  	Inc()
    31  }
    32  
    33  type IncrementerVec interface {
    34  	WithLabelValues(...string) Incrementer
    35  }
    36  
    37  type counterVecWrapper struct {
    38  	c *prometheus.CounterVec
    39  }
    40  
    41  func (c *counterVecWrapper) WithLabelValues(v ...string) Incrementer {
    42  	return c.c.WithLabelValues(v...)
    43  }
    44  
    45  func NewIncrementerFromCounterVec(c *prometheus.CounterVec) IncrementerVec {
    46  	return &counterVecWrapper{c: c}
    47  }