mirror of https://github.com/grafana/loki
pass a prometheus registerer to promtail components (#3175)
Signed-off-by: Robert Fratto <robertfratto@gmail.com>pull/3180/head
parent
54d1d3bea7
commit
628c1fae95
@ -0,0 +1,79 @@ |
||||
package file |
||||
|
||||
import "github.com/prometheus/client_golang/prometheus" |
||||
|
||||
// Metrics hold the set of file-based metrics.
|
||||
type Metrics struct { |
||||
// Registerer used. May be nil.
|
||||
reg prometheus.Registerer |
||||
|
||||
// File-specific metrics
|
||||
readBytes *prometheus.GaugeVec |
||||
totalBytes *prometheus.GaugeVec |
||||
readLines *prometheus.CounterVec |
||||
filesActive prometheus.Gauge |
||||
logLengthHistogram *prometheus.HistogramVec |
||||
|
||||
// Manager metrics
|
||||
failedTargets *prometheus.CounterVec |
||||
targetsActive prometheus.Gauge |
||||
} |
||||
|
||||
// NewMetrics creates a new set of file metrics. If reg is non-nil, the metrics
|
||||
// will be registered.
|
||||
func NewMetrics(reg prometheus.Registerer) *Metrics { |
||||
var m Metrics |
||||
m.reg = reg |
||||
|
||||
m.readBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
||||
Namespace: "promtail", |
||||
Name: "read_bytes_total", |
||||
Help: "Number of bytes read.", |
||||
}, []string{"path"}) |
||||
m.totalBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
||||
Namespace: "promtail", |
||||
Name: "file_bytes_total", |
||||
Help: "Number of bytes total.", |
||||
}, []string{"path"}) |
||||
m.readLines = prometheus.NewCounterVec(prometheus.CounterOpts{ |
||||
Namespace: "promtail", |
||||
Name: "read_lines_total", |
||||
Help: "Number of lines read.", |
||||
}, []string{"path"}) |
||||
m.filesActive = prometheus.NewGauge(prometheus.GaugeOpts{ |
||||
Namespace: "promtail", |
||||
Name: "files_active_total", |
||||
Help: "Number of active files.", |
||||
}) |
||||
m.logLengthHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ |
||||
Namespace: "promtail", |
||||
Name: "log_entries_bytes", |
||||
Help: "the total count of bytes", |
||||
Buckets: prometheus.ExponentialBuckets(16, 2, 8), |
||||
}, []string{"path"}) |
||||
|
||||
m.failedTargets = prometheus.NewCounterVec(prometheus.CounterOpts{ |
||||
Namespace: "promtail", |
||||
Name: "targets_failed_total", |
||||
Help: "Number of failed targets.", |
||||
}, []string{"reason"}) |
||||
m.targetsActive = prometheus.NewGauge(prometheus.GaugeOpts{ |
||||
Namespace: "promtail", |
||||
Name: "targets_active_total", |
||||
Help: "Number of active total.", |
||||
}) |
||||
|
||||
if reg != nil { |
||||
reg.MustRegister( |
||||
m.readBytes, |
||||
m.totalBytes, |
||||
m.readLines, |
||||
m.filesActive, |
||||
m.logLengthHistogram, |
||||
m.failedTargets, |
||||
m.targetsActive, |
||||
) |
||||
} |
||||
|
||||
return &m |
||||
} |
@ -0,0 +1,45 @@ |
||||
package syslog |
||||
|
||||
import "github.com/prometheus/client_golang/prometheus" |
||||
|
||||
// Metrics holds a set of syslog metrics.
|
||||
type Metrics struct { |
||||
reg prometheus.Registerer |
||||
|
||||
syslogEntries prometheus.Counter |
||||
syslogParsingErrors prometheus.Counter |
||||
syslogEmptyMessages prometheus.Counter |
||||
} |
||||
|
||||
// NewMetrics creates a new set of syslog metrics. If reg is non-nil, the
|
||||
// metrics will be registered.
|
||||
func NewMetrics(reg prometheus.Registerer) *Metrics { |
||||
var m Metrics |
||||
m.reg = reg |
||||
|
||||
m.syslogEntries = prometheus.NewCounter(prometheus.CounterOpts{ |
||||
Namespace: "promtail", |
||||
Name: "syslog_target_entries_total", |
||||
Help: "Total number of successful entries sent to the syslog target", |
||||
}) |
||||
m.syslogParsingErrors = prometheus.NewCounter(prometheus.CounterOpts{ |
||||
Namespace: "promtail", |
||||
Name: "syslog_target_parsing_errors_total", |
||||
Help: "Total number of parsing errors while receiving syslog messages", |
||||
}) |
||||
m.syslogEmptyMessages = prometheus.NewCounter(prometheus.CounterOpts{ |
||||
Namespace: "promtail", |
||||
Name: "syslog_empty_messages_total", |
||||
Help: "Total number of empty messages receiving from syslog", |
||||
}) |
||||
|
||||
if reg != nil { |
||||
reg.MustRegister( |
||||
m.syslogEntries, |
||||
m.syslogParsingErrors, |
||||
m.syslogEmptyMessages, |
||||
) |
||||
} |
||||
|
||||
return &m |
||||
} |
Loading…
Reference in new issue