From 31605b5096c8687012e4344ccb5f86b42ff1129b Mon Sep 17 00:00:00 2001 From: Calle Pettersson Date: Tue, 7 Apr 2020 21:05:41 +0200 Subject: [PATCH] Update collector generator template --- tools/collector-generator/collector.template | 21 ++++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/tools/collector-generator/collector.template b/tools/collector-generator/collector.template index 41aec6ae..97a717ec 100644 --- a/tools/collector-generator/collector.template +++ b/tools/collector-generator/collector.template @@ -5,7 +5,7 @@ import ( "github.com/prometheus/common/log" ) func init() { - Factories["{{ .CollectorName | toLower }}"] = New{{ .CollectorName }}Collector + registerCollector("{{ .CollectorName | toLower }}", new{{ .CollectorName }}Collector) // TODO: Add any perflib dependencies here } // A {{ .CollectorName }}Collector is a Prometheus collector for WMI {{ .Class }} metrics type {{ .CollectorName }}Collector struct { @@ -13,8 +13,8 @@ type {{ .CollectorName }}Collector struct { {{ $m.Name }} *prometheus.Desc {{- end }} } -// New{{ .CollectorName }}Collector ... -func New{{ .CollectorName }}Collector() (Collector, error) { + +func new{{ .CollectorName }}Collector() (Collector, error) { const subsystem = "{{ .CollectorName | toLower }}" return &{{ .CollectorName }}Collector{ {{- range $m := .Members }} @@ -27,15 +27,7 @@ func New{{ .CollectorName }}Collector() (Collector, error) { {{- end }} }, nil } -// Collect sends the metric values for each metric -// to the provided prometheus Metric channel. -func (c *{{ .CollectorName }}Collector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error { - if desc, err := c.collect(ch); err != nil { - log.Error("failed collecting {{ .CollectorName | toLower }} metrics:", desc, err) - return err - } - return nil -} + // {{ .Class }} docs: // - type {{ .Class }} struct { @@ -44,7 +36,10 @@ type {{ .Class }} struct { {{ $m.Name }} {{ $m.Type }} {{- end }} } -func (c *{{ .CollectorName }}Collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + +// Collect sends the metric values for each metric +// to the provided prometheus Metric channel. +func (c *{{ .CollectorName }}Collector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error { var dst []{{ .Class }} q := queryAll(&dst) if err := wmi.Query(q, &dst); err != nil {