diff --git a/exporter.go b/exporter.go index eb4faad63071c25a1af7e953d48aec2e4cc369ac..5330109f91adfce4d798d7c31f7ae464d415faed 100644 --- a/exporter.go +++ b/exporter.go @@ -171,22 +171,35 @@ func (re *rsyslogExporter) Collect(ch chan<- prometheus.Metric) { continue } + labelValues := []string{} + if p.promLabelValue() != "" { + labelValues = []string{p.promLabelValue()} + } metric := prometheus.MustNewConstMetric( p.promDescription(), p.promType(), p.promValue(), - p.promLabelValue(), + labelValues..., ) ch <- metric } } -func (re *rsyslogExporter) run() { +func (re *rsyslogExporter) run(silent bool) { + errorPoint := &point{ + Name: "stats_line_errors", + Type: counter, + Description: "Counts errors during stats line handling", + } + re.set(errorPoint) for re.scanner.Scan() { err := re.handleStatLine(re.scanner.Bytes()) if err != nil { - log.Printf("error handling stats line: %v, line was: %s", err, re.scanner.Bytes()) + errorPoint.Value += 1 + if !silent { + log.Printf("error handling stats line: %v, line was: %s", err, re.scanner.Bytes()) + } } } if err := re.scanner.Err(); err != nil { diff --git a/fixtures/rsyslog-stats.log b/fixtures/rsyslog-stats.log index 0543f8191b844849c5db9c7fa27bb5264958a6cc..fa9082f517edfb88856eaa4ba74ae70d2b422a8b 100644 --- a/fixtures/rsyslog-stats.log +++ b/fixtures/rsyslog-stats.log @@ -1,4 +1,5 @@ 2017-08-30T08:09:54.776051+00:00 some-node.example.org rsyslogd-pstats: { "name": "global", "origin": "dynstats", "values": { } } +2017-08-30T08:09:54.776052+00:00 some-node.example.org rsyslogd-pstats: { "name": "global", "origin": "percentile", "values": { } } 2017-08-30T08:09:54.776072+00:00 some-node.example.org rsyslogd-pstats: { "name": "imuxsock", "origin": "imuxsock", "submitted": 9, "ratelimit.discarded": 0, "ratelimit.numratelimiters": 0 } 2017-08-30T08:09:54.776082+00:00 some-node.example.org rsyslogd-pstats: { "name": "action 0", "origin": "core.action", "processed": 0, "failed": 0, "suspended": 0, "suspended.duration": 0, "resumed": 0 } 2017-08-30T08:09:54.776088+00:00 some-node.example.org rsyslogd-pstats: { "name": "to_exporter_2", "origin": "core.action", "processed": 0, "failed": 0, "suspended": 0, "suspended.duration": 0, "resumed": 0 } diff --git a/main.go b/main.go index 90ef19f31fc95a93f21a1ba16fcd5ab4a03e9598..69b0adeb319090cca83339f2a45a17bd29dbfbc5 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ var ( metricPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") certPath = flag.String("tls.server-crt", "", "Path to PEM encoded file containing TLS server cert.") keyPath = flag.String("tls.server-key", "", "Path to PEM encoded file containing TLS server key (unencyrpted).") + silent = flag.Bool("silent", false, "Disable logging of errors in handling stats lines") ) func main() { @@ -37,7 +38,7 @@ func main() { }() go func() { - exporter.run() + exporter.run(*silent) }() prometheus.MustRegister(exporter) diff --git a/point.go b/point.go index 1f441182587186f24017591c90c506bc963fb67b..bb2f4d24e31caeeebf14e73637e4534626427657 100644 --- a/point.go +++ b/point.go @@ -23,10 +23,14 @@ type point struct { } func (p *point) promDescription() *prometheus.Desc { + variableLabels := []string{} + if p.promLabelName() != "" { + variableLabels = []string{p.promLabelName()} + } return prometheus.NewDesc( prometheus.BuildFQName("", "rsyslog", p.Name), p.Description, - []string{p.promLabelName()}, + variableLabels, nil, ) }