Add support for selecting collectors at buildtime

This works by using a global array with references to NewXCollector
functions. Each collector appends to that array in it's init() function.

Which file gets build depends on the build tags:

To build only the ganglia exporter, you can do:

    go build -tags nonative,ganglia

By default it will build only the native collector.
This commit is contained in:
Johannes 'fish' Ziemke 2014-02-07 17:09:39 +01:00
commit 04380ae60a
7 changed files with 76 additions and 41 deletions

View file

@ -1,3 +1,5 @@
// +build runit
package exporter
import (
@ -13,7 +15,11 @@ type runitCollector struct {
stateNormal prometheus.Gauge
}
func NewRunitCollector(config config, registry prometheus.Registry) (runitCollector, error) {
func init() {
collectors = append(collectors, NewRunitCollector)
}
func NewRunitCollector(config config, registry prometheus.Registry) (Collector, error) {
c := runitCollector{
name: "runit_collector",
config: config,
@ -43,7 +49,7 @@ func NewRunitCollector(config config, registry prometheus.Registry) (runitCollec
c.stateNormal,
)
return c, nil
return &c, nil
}
func (c *runitCollector) Name() string { return c.name }