github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/clients/pkg/promtail/targets/journal/metrics.go (about)

     1  package journal
     2  
     3  import "github.com/prometheus/client_golang/prometheus"
     4  
     5  // Metrics holds a set of journal target metrics.
     6  type Metrics struct {
     7  	reg prometheus.Registerer
     8  
     9  	journalErrors *prometheus.CounterVec
    10  	journalLines  prometheus.Counter
    11  }
    12  
    13  const (
    14  	noMessageError   = "no_message"
    15  	emptyLabelsError = "empty_labels"
    16  )
    17  
    18  // NewMetrics creates a new set of journal target metrics. If reg is non-nil, the
    19  // metrics will be registered.
    20  func NewMetrics(reg prometheus.Registerer) *Metrics {
    21  	var m Metrics
    22  	m.reg = reg
    23  
    24  	m.journalErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
    25  		Namespace: "promtail",
    26  		Name:      "journal_target_parsing_errors_total",
    27  		Help:      "Total number of parsing errors while reading journal messages",
    28  	}, []string{"error"})
    29  	m.journalLines = prometheus.NewCounter(prometheus.CounterOpts{
    30  		Namespace: "promtail",
    31  		Name:      "journal_target_lines_total",
    32  		Help:      "Total number of successful journal lines read",
    33  	})
    34  
    35  	if reg != nil {
    36  		reg.MustRegister(
    37  			m.journalErrors,
    38  			m.journalLines,
    39  		)
    40  	}
    41  
    42  	return &m
    43  }