Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions collector/bonding_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package collector

import (
"flag"
"fmt"
"io/ioutil"
"os"
Expand All @@ -31,6 +32,7 @@ type bondingCollector struct {

func init() {
Factories["bonding"] = NewBondingCollector
CollectorsEnabledState["bonding"] = flag.Bool("collectors.bonding.enabled", false, "enables bonding-collector")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not saying it's wrong but why using a global map? I imagined just having a (global) flag per collector to enable it, which would toggle adding the collector instance via the Factories map.

Copy link
Contributor Author

@cherti cherti Dec 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that at first as well, but then we have the issue that those flags are not compiled in based on architecture, but always.
Because the map lives in the collector-package, not in the main package, we can just add the flags into the collector-files and have the nice property that collectors that are not compiled in (e.g. mdadm_linux.go on BSDs) don't show up in -help.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you define the flags in the arch files (or files with arch build tags) they should only get compiled there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but as far as I see, we don't have them yet for the main-package, therefore I'd tried to avoid introducing them and additionally, this would be additional bookkeeping, because we have to keep track of those flags in addition to the collectors, when adding or removing collectors.
This way, the collectors and their "state" is confined to their files, that's the intention behind that and with the map we can easily iterate over the available collectors.
That was the intention behind that.

}

// NewBondingCollector returns a newly allocated bondingCollector.
Expand Down
1 change: 1 addition & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
const Namespace = "node"

var Factories = make(map[string]func() (Collector, error))
var CollectorsEnabledState = make(map[string]*bool)

// Interface a collector has to implement.
type Collector interface {
Expand Down
3 changes: 3 additions & 0 deletions collector/conntrack_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package collector

import (
"flag"

"github.com/prometheus/client_golang/prometheus"
)

Expand All @@ -26,6 +28,7 @@ type conntrackCollector struct {

func init() {
Factories["conntrack"] = NewConntrackCollector
CollectorsEnabledState["conntrack"] = flag.Bool("collectors.conntrack.enabled", true, "enables conntrack-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/cpu_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package collector

import (
"errors"
"flag"
"fmt"
"unsafe"

Expand Down Expand Up @@ -89,6 +90,7 @@ type statCollector struct {

func init() {
Factories["cpu"] = NewStatCollector
enabledCollectors["cpu"] = flag.Bool("collectors.cpu.enabled", true, "enables cpu-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/cpu_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package collector

import (
"errors"
"flag"
"strconv"
"unsafe"

Expand Down Expand Up @@ -111,6 +112,7 @@ type statCollector struct {

func init() {
Factories["cpu"] = NewStatCollector
enabledCollectors["cpu"] = flag.Bool("collectors.cpu.enabled", true, "enables cpu-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/devstat_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package collector

import (
"errors"
"flag"
"fmt"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -100,6 +101,7 @@ type devstatCollector struct {

func init() {
Factories["devstat"] = NewDevstatCollector
enabledCollectors["devstat"] = flag.Bool("collectors.devstat.enabled", false, "enables devstat-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/devstat_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package collector

import (
"errors"
"flag"
"fmt"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -147,6 +148,7 @@ type devstatCollector struct {

func init() {
Factories["devstat"] = NewDevstatCollector
enabledCollectors["devstat"] = flag.Bool("collectors.devstat.enabled", false, "enables devstat-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
1 change: 1 addition & 0 deletions collector/diskstats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type diskstatsCollector struct {

func init() {
Factories["diskstats"] = NewDiskstatsCollector
CollectorsEnabledState["diskstats"] = flag.Bool("collectors.diskstats.enabled", true, "enables diskstats-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/drbd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package collector

import (
"bufio"
"flag"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -149,6 +150,7 @@ type drbdCollector struct{}

func init() {
Factories["drbd"] = newDRBDCollector
CollectorsEnabledState["drdb"] = flag.Bool("collectors.drdb.enabled", false, "enables drdb-collector")
}

func newDRBDCollector() (Collector, error) {
Expand Down
2 changes: 2 additions & 0 deletions collector/entropy_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package collector

import (
"flag"
"fmt"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -27,6 +28,7 @@ type entropyCollector struct {

func init() {
Factories["entropy"] = NewEntropyCollector
CollectorsEnabledState["entropy"] = flag.Bool("collectors.entropy.enabled", true, "enables entropy-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/filefd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package collector

import (
"bufio"
"flag"
"fmt"
"io"
"os"
Expand All @@ -34,6 +35,7 @@ type fileFDStatCollector struct{}

func init() {
Factories[fileFDStatSubsystem] = NewFileFDStatCollector
CollectorsEnabledState["filefd"] = flag.Bool("collectors.filefd.enabled", true, "enables filefd-collector")
}

// NewFileFDStatCollector returns a new Collector exposing file-nr stats.
Expand Down
1 change: 1 addition & 0 deletions collector/filesystem_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type filesystemStats struct {

func init() {
Factories["filesystem"] = NewFilesystemCollector
CollectorsEnabledState["filesystem"] = flag.Bool("collectors.filesystem.enabled", true, "enables filesystem-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/gmond.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package collector
import (
"bufio"
"encoding/xml"
"flag"
"fmt"
"io"
"net"
Expand All @@ -42,6 +43,7 @@ type gmondCollector struct {

func init() {
Factories["gmond"] = NewGmondCollector
CollectorsEnabledState["gmond"] = flag.Bool("collectors.gmond.enabled", false, "enables gmond-collector")
}

var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
Expand Down
2 changes: 2 additions & 0 deletions collector/hwmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package collector

import (
"errors"
"flag"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -45,6 +46,7 @@ var (

func init() {
Factories["hwmon"] = NewHwMonCollector
CollectorsEnabledState["hwmon"] = flag.Bool("collectors.hwmon.enabled", true, "enables hwmon-collector")
}

type hwMonCollector struct{}
Expand Down
7 changes: 6 additions & 1 deletion collector/interrupts_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@

package collector

import "github.com/prometheus/client_golang/prometheus"
import (
"flag"

"github.com/prometheus/client_golang/prometheus"
)

type interruptsCollector struct {
metric *prometheus.CounterVec
}

func init() {
Factories["interrupts"] = NewInterruptsCollector
CollectorsEnabledState["interrupts"] = flag.Bool("collectors.interrupts.enabled", false, "enables interrupts-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/ipvs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package collector

import (
"flag"
"fmt"
"strconv"

Expand All @@ -32,6 +33,7 @@ type ipvsCollector struct {

func init() {
Factories["ipvs"] = NewIPVSCollector
CollectorsEnabledState["ipvs"] = flag.Bool("collectors.ipvs.enabled", false, "enable interrupts-collector")
}

// NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the
Expand Down
2 changes: 2 additions & 0 deletions collector/ksmd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package collector

import (
"flag"
"fmt"
"path"

Expand All @@ -33,6 +34,7 @@ type ksmdCollector struct {

func init() {
Factories["ksmd"] = NewKsmdCollector
CollectorsEnabledState["ksmd"] = flag.Bool("collectors.ksmd.enabled", false, "enables ksmd-collector")
}

func getCanonicalMetricName(filename string) string {
Expand Down
2 changes: 2 additions & 0 deletions collector/loadavg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package collector

import (
"flag"
"fmt"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -29,6 +30,7 @@ type loadavgCollector struct {

func init() {
Factories["loadavg"] = NewLoadavgCollector
CollectorsEnabledState["loadavg"] = flag.Bool("collectors.loadavg.enabled", true, "enable loadavg-collector")
}

// Take a prometheus registry and return a new Collector exposing load average.
Expand Down
2 changes: 2 additions & 0 deletions collector/logind_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package collector

import (
"flag"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -79,6 +80,7 @@ type logindSeatEntry struct {

func init() {
Factories["logind"] = NewLogindCollector
CollectorsEnabledState["logind"] = flag.Bool("collectors.logind.enabled", false, "enables logind-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/mdadm_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package collector

import (
"flag"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -48,6 +49,7 @@ type mdadmCollector struct{}

func init() {
Factories["mdadm"] = NewMdadmCollector
CollectorsEnabledState["mdadm"] = flag.Bool("collectors.mdadm.enabled", true, "enable mdadm-collector")
}

func evalStatusline(statusline string) (active, total, size int64, err error) {
Expand Down
1 change: 1 addition & 0 deletions collector/megacli.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type megaCliCollector struct {

func init() {
Factories["megacli"] = NewMegaCliCollector
CollectorsEnabledState["megacli"] = flag.Bool("collectors.megacli.enabled", false, "enables megacli-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/meminfo_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package collector

import (
"errors"
"flag"

"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -49,6 +50,7 @@ type meminfoCollector struct{}

func init() {
Factories["meminfo"] = NewMeminfoCollector
CollectorsEnabledState["meminfo"] = flag.Bool("collectors.meminfo.enabled", true, "enables meminfo-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/meminfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package collector

import (
"bufio"
"flag"
"fmt"
"io"
"os"
Expand All @@ -36,6 +37,7 @@ type meminfoCollector struct{}

func init() {
Factories["meminfo"] = NewMeminfoCollector
CollectorsEnabledState["meminfo"] = flag.Bool("collectors.meminfo.enabled", true, "enables meminfo-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/meminfo_numa_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package collector

import (
"bufio"
"flag"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -48,6 +49,7 @@ type meminfoNumaCollector struct {

func init() {
Factories["meminfo_numa"] = NewMeminfoNumaCollector
CollectorsEnabledState["meminfo_numa"] = flag.Bool("collectors.meminfo_numa.enabled", false, "enable meminfo-numa-collector")
}

// Takes a prometheus registry and returns a new Collector exposing
Expand Down
2 changes: 2 additions & 0 deletions collector/mountstats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package collector

import (
"flag"
"fmt"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -61,6 +62,7 @@ type mountStatsCollector struct {

func init() {
Factories["mountstats"] = NewMountStatsCollector
CollectorsEnabledState["mountstats"] = flag.Bool("collectors.mountstats.enabled", false, "enable mountstats-collectors")
}

func NewMountStatsCollector() (Collector, error) {
Expand Down
1 change: 1 addition & 0 deletions collector/netdev_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type netDevCollector struct {

func init() {
Factories["netdev"] = NewNetDevCollector
CollectorsEnabledState["netdev"] = flag.Bool("collectors.netdev.enabled", true, "enables netdev-collector")
}

// NewNetDevCollector returns a new Collector exposing network device stats.
Expand Down
2 changes: 2 additions & 0 deletions collector/netstat_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package collector

import (
"bufio"
"flag"
"fmt"
"io"
"os"
Expand All @@ -34,6 +35,7 @@ type netStatCollector struct{}

func init() {
Factories["netstat"] = NewNetStatCollector
CollectorsEnabledState["netstat"] = flag.Bool("collectors.netstat.enabled", true, "enables netstat-collector")
}

// NewNetStatCollector takes and returns
Expand Down
Loading