Replace --collectors.enabled with per-collector flags (#640)

* Move NodeCollector into package collector

* Refactor collector enabling

* Update README with new collector enabled flags

* Fix out-of-date inline flag reference syntax

* Use new flags in end-to-end tests

* Add flag to disable all default collectors

* Track if a flag has been set explicitly

* Add --collectors.disable-defaults to README

* Revert disable-defaults flag

* Shorten flags

* Fixup timex collector registration

* Fix end-to-end tests

* Change procfs and sysfs path flags

* Fix review comments
This commit is contained in:
Calle Pettersson 2017-09-28 15:06:26 +02:00 committed by Johannes 'fish' Ziemke
parent 3762191e66
commit 859a825bb8
58 changed files with 410 additions and 406 deletions

View file

@ -16,7 +16,8 @@ The [WMI exporter](https://github.com/martinlindhe/wmi_exporter) is recommended
There is varying support for collectors on each operating system. The tables There is varying support for collectors on each operating system. The tables
below list all existing collectors and the supported systems. below list all existing collectors and the supported systems.
Which collectors are used is controlled by the `--collectors.enabled` flag. Collectors are enabled by providing a `--collector.<name>` flag.
Collectors that are enabled by default can be disabled by providing a `--no-collector.<name>` flag.
### Enabled by default ### Enabled by default
@ -137,8 +138,8 @@ docker run -d -p 9100:9100 \
-v "/:/rootfs:ro" \ -v "/:/rootfs:ro" \
--net="host" \ --net="host" \
quay.io/prometheus/node-exporter \ quay.io/prometheus/node-exporter \
--collector.procfs /host/proc \ --path.procfs /host/proc \
--collector.sysfs /host/sys \ --path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)" --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
``` ```

View file

@ -30,14 +30,14 @@ type arpCollector struct {
} }
func init() { func init() {
Factories["arp"] = NewARPCollector registerCollector("arp", defaultEnabled, NewARPCollector)
} }
// NewARPCollector returns a new Collector exposing ARP stats. // NewARPCollector returns a new Collector exposing ARP stats.
func NewARPCollector() (Collector, error) { func NewARPCollector() (Collector, error) {
return &arpCollector{ return &arpCollector{
entries: prometheus.NewDesc( entries: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "arp", "entries"), prometheus.BuildFQName(namespace, "arp", "entries"),
"ARP entries by device", "ARP entries by device",
[]string{"device"}, nil, []string{"device"}, nil,
), ),

View file

@ -25,7 +25,7 @@ import (
) )
func init() { func init() {
Factories["bcache"] = NewBcacheCollector registerCollector("bcache", defaultEnabled, NewBcacheCollector)
} }
// A bcacheCollector is a Collector which gathers metrics from Linux bcache. // A bcacheCollector is a Collector which gathers metrics from Linux bcache.
@ -283,7 +283,7 @@ func (c *bcacheCollector) updateBcacheStats(ch chan<- prometheus.Metric, s *bcac
labels := append(devLabel, m.extraLabel...) labels := append(devLabel, m.extraLabel...)
desc := prometheus.NewDesc( desc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, m.name), prometheus.BuildFQName(namespace, subsystem, m.name),
m.desc, m.desc,
labels, labels,
nil, nil,

View file

@ -31,7 +31,7 @@ type bondingCollector struct {
} }
func init() { func init() {
Factories["bonding"] = NewBondingCollector registerCollector("bonding", defaultDisabled, NewBondingCollector)
} }
// NewBondingCollector returns a newly allocated bondingCollector. // NewBondingCollector returns a newly allocated bondingCollector.
@ -39,12 +39,12 @@ func init() {
func NewBondingCollector() (Collector, error) { func NewBondingCollector() (Collector, error) {
return &bondingCollector{ return &bondingCollector{
slaves: typedDesc{prometheus.NewDesc( slaves: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "bonding", "slaves"), prometheus.BuildFQName(namespace, "bonding", "slaves"),
"Number of configured slaves per bonding interface.", "Number of configured slaves per bonding interface.",
[]string{"master"}, nil, []string{"master"}, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
active: typedDesc{prometheus.NewDesc( active: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "bonding", "active"), prometheus.BuildFQName(namespace, "bonding", "active"),
"Number of active slaves per bonding interface.", "Number of active slaves per bonding interface.",
[]string{"master"}, nil, []string{"master"}, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},

View file

@ -34,13 +34,13 @@ type buddyinfoCollector struct {
} }
func init() { func init() {
Factories["buddyinfo"] = NewBuddyinfoCollector registerCollector("buddyinfo", defaultDisabled, NewBuddyinfoCollector)
} }
// NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats. // NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats.
func NewBuddyinfoCollector() (Collector, error) { func NewBuddyinfoCollector() (Collector, error) {
desc := prometheus.NewDesc( desc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, buddyInfoSubsystem, "count"), prometheus.BuildFQName(namespace, buddyInfoSubsystem, "count"),
"Count of free blocks according to size.", "Count of free blocks according to size.",
[]string{"node", "zone", "size"}, nil, []string{"node", "zone", "size"}, nil,
) )

View file

@ -15,20 +15,121 @@
package collector package collector
import ( import (
"fmt"
"sync"
"time"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log" "github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
) )
// Namespace defines the common namespace to be used by all metrics. // Namespace defines the common namespace to be used by all metrics.
const Namespace = "node" const namespace = "node"
// Factories contains the list of all available collectors. var (
var Factories = make(map[string]func() (Collector, error)) scrapeDurationDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "scrape", "collector_duration_seconds"),
"node_exporter: Duration of a collector scrape.",
[]string{"collector"},
nil,
)
scrapeSuccessDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "scrape", "collector_success"),
"node_exporter: Whether a collector succeeded.",
[]string{"collector"},
nil,
)
)
func warnDeprecated(collector string) { func warnDeprecated(collector string) {
log.Warnf("The %s collector is deprecated and will be removed in the future!", collector) log.Warnf("The %s collector is deprecated and will be removed in the future!", collector)
} }
const (
defaultEnabled = true
defaultDisabled = false
)
var (
factories = make(map[string]func() (Collector, error))
collectorState = make(map[string]*bool)
)
func registerCollector(collector string, isDefaultEnabled bool, factory func() (Collector, error)) {
var helpDefaultState string
if isDefaultEnabled {
helpDefaultState = "enabled"
} else {
helpDefaultState = "disabled"
}
flagName := fmt.Sprintf("collector.%s", collector)
flagHelp := fmt.Sprintf("Enable the %s collector (default: %s).", collector, helpDefaultState)
defaultValue := fmt.Sprintf("%v", isDefaultEnabled)
flag := kingpin.Flag(flagName, flagHelp).Default(defaultValue).Bool()
collectorState[collector] = flag
factories[collector] = factory
}
// NodeCollector implements the prometheus.Collector interface.
type nodeCollector struct {
Collectors map[string]Collector
}
// NewNodeCollector creates a new NodeCollector
func NewNodeCollector() (*nodeCollector, error) {
collectors := make(map[string]Collector)
for key, enabled := range collectorState {
if *enabled {
collector, err := factories[key]()
if err != nil {
return nil, err
}
collectors[key] = collector
}
}
return &nodeCollector{Collectors: collectors}, nil
}
// Describe implements the prometheus.Collector interface.
func (n nodeCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- scrapeDurationDesc
ch <- scrapeSuccessDesc
}
// Collect implements the prometheus.Collector interface.
func (n nodeCollector) Collect(ch chan<- prometheus.Metric) {
wg := sync.WaitGroup{}
wg.Add(len(n.Collectors))
for name, c := range n.Collectors {
go func(name string, c Collector) {
execute(name, c, ch)
wg.Done()
}(name, c)
}
wg.Wait()
}
func execute(name string, c Collector, ch chan<- prometheus.Metric) {
begin := time.Now()
err := c.Update(ch)
duration := time.Since(begin)
var success float64
if err != nil {
log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err)
success = 0
} else {
log.Debugf("OK: %s collector succeeded after %fs.", name, duration.Seconds())
success = 1
}
ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name)
ch <- prometheus.MustNewConstMetric(scrapeSuccessDesc, prometheus.GaugeValue, success, name)
}
// Collector is the interface a collector has to implement. // Collector is the interface a collector has to implement.
type Collector interface { type Collector interface {
// Get new metrics and expose them via prometheus registry. // Get new metrics and expose them via prometheus registry.

View file

@ -25,19 +25,19 @@ type conntrackCollector struct {
} }
func init() { func init() {
Factories["conntrack"] = NewConntrackCollector registerCollector("conntrack", defaultEnabled, NewConntrackCollector)
} }
// NewConntrackCollector returns a new Collector exposing conntrack stats. // NewConntrackCollector returns a new Collector exposing conntrack stats.
func NewConntrackCollector() (Collector, error) { func NewConntrackCollector() (Collector, error) {
return &conntrackCollector{ return &conntrackCollector{
current: prometheus.NewDesc( current: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "nf_conntrack_entries"), prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"),
"Number of currently allocated flow entries for connection tracking.", "Number of currently allocated flow entries for connection tracking.",
nil, nil, nil, nil,
), ),
limit: prometheus.NewDesc( limit: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "nf_conntrack_entries_limit"), prometheus.BuildFQName(namespace, "", "nf_conntrack_entries_limit"),
"Maximum size of connection tracking table.", "Maximum size of connection tracking table.",
nil, nil, nil, nil,
), ),

View file

@ -52,14 +52,14 @@ type statCollector struct {
} }
func init() { func init() {
Factories["cpu"] = NewCPUCollector registerCollector("cpu", defaultEnabled, NewCPUCollector)
} }
// NewCPUCollector returns a new Collector exposing CPU stats. // NewCPUCollector returns a new Collector exposing CPU stats.
func NewCPUCollector() (Collector, error) { func NewCPUCollector() (Collector, error) {
return &statCollector{ return &statCollector{
cpu: prometheus.NewDesc( cpu: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "cpu"), prometheus.BuildFQName(namespace, "", "cpu"),
"Seconds the cpus spent in each mode.", "Seconds the cpus spent in each mode.",
[]string{"cpu", "mode"}, nil, []string{"cpu", "mode"}, nil,
), ),

View file

@ -88,14 +88,14 @@ type statCollector struct {
} }
func init() { func init() {
Factories["cpu"] = NewStatCollector registerCollector("cpu", defaultEnabled, NewStatCollector)
} }
// NewStatCollector returns a new Collector exposing CPU stats. // NewStatCollector returns a new Collector exposing CPU stats.
func NewStatCollector() (Collector, error) { func NewStatCollector() (Collector, error) {
return &statCollector{ return &statCollector{
cpu: prometheus.NewDesc( cpu: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "cpu"), prometheus.BuildFQName(namespace, "", "cpu"),
"Seconds the cpus spent in each mode.", "Seconds the cpus spent in each mode.",
[]string{"cpu", "mode"}, nil, []string{"cpu", "mode"}, nil,
), ),

View file

@ -86,19 +86,19 @@ type statCollector struct {
} }
func init() { func init() {
Factories["cpu"] = NewStatCollector registerCollector("cpu", defaultEnabled, NewStatCollector)
} }
// NewStatCollector returns a new Collector exposing CPU stats. // NewStatCollector returns a new Collector exposing CPU stats.
func NewStatCollector() (Collector, error) { func NewStatCollector() (Collector, error) {
return &statCollector{ return &statCollector{
cpu: typedDesc{prometheus.NewDesc( cpu: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "cpu", "seconds_total"), prometheus.BuildFQName(namespace, "cpu", "seconds_total"),
"Seconds the CPU spent in each mode.", "Seconds the CPU spent in each mode.",
[]string{"cpu", "mode"}, nil, []string{"cpu", "mode"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
temp: typedDesc{prometheus.NewDesc( temp: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "cpu", "temperature_celsius"), prometheus.BuildFQName(namespace, "cpu", "temperature_celsius"),
"CPU temperature", "CPU temperature",
[]string{"cpu"}, nil, []string{"cpu"}, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},

View file

@ -29,7 +29,7 @@ import (
) )
const ( const (
cpuCollectorNamespace = "cpu" cpuCollectorSubsystem = "cpu"
) )
var ( var (
@ -46,40 +46,40 @@ type cpuCollector struct {
} }
func init() { func init() {
Factories["cpu"] = NewCPUCollector registerCollector("cpu", defaultEnabled, NewCPUCollector)
} }
// NewCPUCollector returns a new Collector exposing kernel/system statistics. // NewCPUCollector returns a new Collector exposing kernel/system statistics.
func NewCPUCollector() (Collector, error) { func NewCPUCollector() (Collector, error) {
return &cpuCollector{ return &cpuCollector{
cpu: prometheus.NewDesc( cpu: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", cpuCollectorNamespace), prometheus.BuildFQName(namespace, "", cpuCollectorSubsystem),
"Seconds the cpus spent in each mode.", "Seconds the cpus spent in each mode.",
[]string{"cpu", "mode"}, nil, []string{"cpu", "mode"}, nil,
), ),
cpuFreq: prometheus.NewDesc( cpuFreq: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, cpuCollectorNamespace, "frequency_hertz"), prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_hertz"),
"Current cpu thread frequency in hertz.", "Current cpu thread frequency in hertz.",
[]string{"cpu"}, nil, []string{"cpu"}, nil,
), ),
cpuFreqMin: prometheus.NewDesc( cpuFreqMin: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, cpuCollectorNamespace, "frequency_min_hertz"), prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_min_hertz"),
"Minimum cpu thread frequency in hertz.", "Minimum cpu thread frequency in hertz.",
[]string{"cpu"}, nil, []string{"cpu"}, nil,
), ),
cpuFreqMax: prometheus.NewDesc( cpuFreqMax: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, cpuCollectorNamespace, "frequency_max_hertz"), prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_max_hertz"),
"Maximum cpu thread frequency in hertz.", "Maximum cpu thread frequency in hertz.",
[]string{"cpu"}, nil, []string{"cpu"}, nil,
), ),
// FIXME: This should be a per core metric, not per cpu! // FIXME: This should be a per core metric, not per cpu!
cpuCoreThrottle: prometheus.NewDesc( cpuCoreThrottle: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, cpuCollectorNamespace, "core_throttles_total"), prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "core_throttles_total"),
"Number of times this cpu core has been throttled.", "Number of times this cpu core has been throttled.",
[]string{"cpu"}, nil, []string{"cpu"}, nil,
), ),
cpuPackageThrottle: prometheus.NewDesc( cpuPackageThrottle: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, cpuCollectorNamespace, "package_throttles_total"), prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "package_throttles_total"),
"Number of times this cpu package has been throttled.", "Number of times this cpu package has been throttled.",
[]string{"node"}, nil, []string{"node"}, nil,
), ),

View file

@ -99,24 +99,24 @@ type devstatCollector struct {
} }
func init() { func init() {
Factories["devstat"] = NewDevstatCollector registerCollector("devstat", defaultDisabled, NewDevstatCollector)
} }
// NewDevstatCollector returns a new Collector exposing Device stats. // NewDevstatCollector returns a new Collector exposing Device stats.
func NewDevstatCollector() (Collector, error) { func NewDevstatCollector() (Collector, error) {
return &devstatCollector{ return &devstatCollector{
bytesDesc: prometheus.NewDesc( bytesDesc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, devstatSubsystem, "bytes_total"), prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"),
"The total number of bytes transferred for reads and writes on the device.", "The total number of bytes transferred for reads and writes on the device.",
[]string{"device"}, nil, []string{"device"}, nil,
), ),
transfersDesc: prometheus.NewDesc( transfersDesc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, devstatSubsystem, "transfers_total"), prometheus.BuildFQName(namespace, devstatSubsystem, "transfers_total"),
"The total number of transactions completed.", "The total number of transactions completed.",
[]string{"device"}, nil, []string{"device"}, nil,
), ),
blocksDesc: prometheus.NewDesc( blocksDesc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, devstatSubsystem, "blocks_total"), prometheus.BuildFQName(namespace, devstatSubsystem, "blocks_total"),
"The total number of bytes given in terms of the devices blocksize.", "The total number of bytes given in terms of the devices blocksize.",
[]string{"device"}, nil, []string{"device"}, nil,
), ),

View file

@ -44,7 +44,7 @@ type devstatCollector struct {
} }
func init() { func init() {
Factories["devstat"] = NewDevstatCollector registerCollector("devstat", defaultDisabled, NewDevstatCollector)
} }
// NewDevstatCollector returns a new Collector exposing Device stats. // NewDevstatCollector returns a new Collector exposing Device stats.
@ -52,27 +52,27 @@ func NewDevstatCollector() (Collector, error) {
return &devstatCollector{ return &devstatCollector{
devinfo: &C.struct_devinfo{}, devinfo: &C.struct_devinfo{},
bytes: typedDesc{prometheus.NewDesc( bytes: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, devstatSubsystem, "bytes_total"), prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"),
"The total number of bytes in transactions.", "The total number of bytes in transactions.",
[]string{"device", "type"}, nil, []string{"device", "type"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
transfers: typedDesc{prometheus.NewDesc( transfers: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, devstatSubsystem, "transfers_total"), prometheus.BuildFQName(namespace, devstatSubsystem, "transfers_total"),
"The total number of transactions.", "The total number of transactions.",
[]string{"device", "type"}, nil, []string{"device", "type"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
duration: typedDesc{prometheus.NewDesc( duration: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, devstatSubsystem, "duration_seconds_total"), prometheus.BuildFQName(namespace, devstatSubsystem, "duration_seconds_total"),
"The total duration of transactions in seconds.", "The total duration of transactions in seconds.",
[]string{"device", "type"}, nil, []string{"device", "type"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
busyTime: typedDesc{prometheus.NewDesc( busyTime: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, devstatSubsystem, "busy_time_seconds_total"), prometheus.BuildFQName(namespace, devstatSubsystem, "busy_time_seconds_total"),
"Total time the device had one or more transactions outstanding in seconds.", "Total time the device had one or more transactions outstanding in seconds.",
[]string{"device"}, nil, []string{"device"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
blocks: typedDesc{prometheus.NewDesc( blocks: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, devstatSubsystem, "blocks_transferred_total"), prometheus.BuildFQName(namespace, devstatSubsystem, "blocks_transferred_total"),
"The total number of blocks transferred.", "The total number of blocks transferred.",
[]string{"device"}, nil, []string{"device"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},

View file

@ -36,7 +36,7 @@ type diskstatsCollector struct {
} }
func init() { func init() {
Factories["diskstats"] = NewDiskstatsCollector registerCollector("diskstats", defaultEnabled, NewDiskstatsCollector)
} }
// NewDiskstatsCollector returns a new Collector exposing disk device stats. // NewDiskstatsCollector returns a new Collector exposing disk device stats.
@ -48,7 +48,7 @@ func NewDiskstatsCollector() (Collector, error) {
{ {
typedDesc: typedDesc{ typedDesc: typedDesc{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "reads_completed_total"), prometheus.BuildFQName(namespace, diskSubsystem, "reads_completed_total"),
"The total number of reads completed successfully.", "The total number of reads completed successfully.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -62,7 +62,7 @@ func NewDiskstatsCollector() (Collector, error) {
{ {
typedDesc: typedDesc{ typedDesc: typedDesc{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "read_sectors_total"), prometheus.BuildFQName(namespace, diskSubsystem, "read_sectors_total"),
"The total number of sectors read successfully.", "The total number of sectors read successfully.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -76,7 +76,7 @@ func NewDiskstatsCollector() (Collector, error) {
{ {
typedDesc: typedDesc{ typedDesc: typedDesc{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "read_seconds_total"), prometheus.BuildFQName(namespace, diskSubsystem, "read_seconds_total"),
"The total number of seconds spent by all reads.", "The total number of seconds spent by all reads.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -90,7 +90,7 @@ func NewDiskstatsCollector() (Collector, error) {
{ {
typedDesc: typedDesc{ typedDesc: typedDesc{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "writes_completed_total"), prometheus.BuildFQName(namespace, diskSubsystem, "writes_completed_total"),
"The total number of writes completed successfully.", "The total number of writes completed successfully.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -104,7 +104,7 @@ func NewDiskstatsCollector() (Collector, error) {
{ {
typedDesc: typedDesc{ typedDesc: typedDesc{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "written_sectors_total"), prometheus.BuildFQName(namespace, diskSubsystem, "written_sectors_total"),
"The total number of sectors written successfully.", "The total number of sectors written successfully.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -118,7 +118,7 @@ func NewDiskstatsCollector() (Collector, error) {
{ {
typedDesc: typedDesc{ typedDesc: typedDesc{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "write_seconds_total"), prometheus.BuildFQName(namespace, diskSubsystem, "write_seconds_total"),
"This is the total number of seconds spent by all writes.", "This is the total number of seconds spent by all writes.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -132,7 +132,7 @@ func NewDiskstatsCollector() (Collector, error) {
{ {
typedDesc: typedDesc{ typedDesc: typedDesc{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "read_bytes_total"), prometheus.BuildFQName(namespace, diskSubsystem, "read_bytes_total"),
"The total number of bytes read successfully.", "The total number of bytes read successfully.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -146,7 +146,7 @@ func NewDiskstatsCollector() (Collector, error) {
{ {
typedDesc: typedDesc{ typedDesc: typedDesc{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "written_bytes_total"), prometheus.BuildFQName(namespace, diskSubsystem, "written_bytes_total"),
"The total number of bytes written successfully.", "The total number of bytes written successfully.",
diskLabelNames, diskLabelNames,
nil, nil,

View file

@ -44,7 +44,7 @@ type diskstatsCollector struct {
} }
func init() { func init() {
Factories["diskstats"] = NewDiskstatsCollector registerCollector("diskstats", defaultEnabled, NewDiskstatsCollector)
} }
// NewDiskstatsCollector returns a new Collector exposing disk device stats. // NewDiskstatsCollector returns a new Collector exposing disk device stats.
@ -57,7 +57,7 @@ func NewDiskstatsCollector() (Collector, error) {
descs: []typedDesc{ descs: []typedDesc{
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "reads_completed"), prometheus.BuildFQName(namespace, diskSubsystem, "reads_completed"),
"The total number of reads completed successfully.", "The total number of reads completed successfully.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -65,7 +65,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "reads_merged"), prometheus.BuildFQName(namespace, diskSubsystem, "reads_merged"),
"The total number of reads merged. See https://www.kernel.org/doc/Documentation/iostats.txt.", "The total number of reads merged. See https://www.kernel.org/doc/Documentation/iostats.txt.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -73,7 +73,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "sectors_read"), prometheus.BuildFQName(namespace, diskSubsystem, "sectors_read"),
"The total number of sectors read successfully.", "The total number of sectors read successfully.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -81,7 +81,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "read_time_ms"), prometheus.BuildFQName(namespace, diskSubsystem, "read_time_ms"),
"The total number of milliseconds spent by all reads.", "The total number of milliseconds spent by all reads.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -89,7 +89,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "writes_completed"), prometheus.BuildFQName(namespace, diskSubsystem, "writes_completed"),
"The total number of writes completed successfully.", "The total number of writes completed successfully.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -97,7 +97,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "writes_merged"), prometheus.BuildFQName(namespace, diskSubsystem, "writes_merged"),
"The number of writes merged. See https://www.kernel.org/doc/Documentation/iostats.txt.", "The number of writes merged. See https://www.kernel.org/doc/Documentation/iostats.txt.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -105,7 +105,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "sectors_written"), prometheus.BuildFQName(namespace, diskSubsystem, "sectors_written"),
"The total number of sectors written successfully.", "The total number of sectors written successfully.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -113,7 +113,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "write_time_ms"), prometheus.BuildFQName(namespace, diskSubsystem, "write_time_ms"),
"This is the total number of milliseconds spent by all writes.", "This is the total number of milliseconds spent by all writes.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -121,7 +121,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "io_now"), prometheus.BuildFQName(namespace, diskSubsystem, "io_now"),
"The number of I/Os currently in progress.", "The number of I/Os currently in progress.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -129,7 +129,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "io_time_ms"), prometheus.BuildFQName(namespace, diskSubsystem, "io_time_ms"),
"Total Milliseconds spent doing I/Os.", "Total Milliseconds spent doing I/Os.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -137,7 +137,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "io_time_weighted"), prometheus.BuildFQName(namespace, diskSubsystem, "io_time_weighted"),
"The weighted # of milliseconds spent doing I/Os. See https://www.kernel.org/doc/Documentation/iostats.txt.", "The weighted # of milliseconds spent doing I/Os. See https://www.kernel.org/doc/Documentation/iostats.txt.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -145,7 +145,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "bytes_read"), prometheus.BuildFQName(namespace, diskSubsystem, "bytes_read"),
"The total number of bytes read successfully.", "The total number of bytes read successfully.",
diskLabelNames, diskLabelNames,
nil, nil,
@ -153,7 +153,7 @@ func NewDiskstatsCollector() (Collector, error) {
}, },
{ {
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "bytes_written"), prometheus.BuildFQName(namespace, diskSubsystem, "bytes_written"),
"The total number of bytes written successfully.", "The total number of bytes written successfully.",
diskLabelNames, diskLabelNames,
nil, nil,

View file

@ -34,7 +34,7 @@ type drbdNumericalMetric struct {
func newDRBDNumericalMetric(name string, desc string, valueType prometheus.ValueType, multiplier float64) drbdNumericalMetric { func newDRBDNumericalMetric(name string, desc string, valueType prometheus.ValueType, multiplier float64) drbdNumericalMetric {
return drbdNumericalMetric{ return drbdNumericalMetric{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "drbd", name), prometheus.BuildFQName(namespace, "drbd", name),
desc, desc,
[]string{"device"}, nil), []string{"device"}, nil),
valueType: valueType, valueType: valueType,
@ -58,7 +58,7 @@ func (metric *drbdStringPairMetric) isOkay(value string) float64 {
func newDRBDStringPairMetric(name string, desc string, valueOkay string) drbdStringPairMetric { func newDRBDStringPairMetric(name string, desc string, valueOkay string) drbdStringPairMetric {
return drbdStringPairMetric{ return drbdStringPairMetric{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "drbd", name), prometheus.BuildFQName(namespace, "drbd", name),
desc, desc,
[]string{"device", "node"}, nil), []string{"device", "node"}, nil),
valueOkay: valueOkay, valueOkay: valueOkay,
@ -140,7 +140,7 @@ var (
} }
drbdConnected = prometheus.NewDesc( drbdConnected = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "drbd", "connected"), prometheus.BuildFQName(namespace, "drbd", "connected"),
"Whether DRBD is connected to the peer.", "Whether DRBD is connected to the peer.",
[]string{"device"}, nil) []string{"device"}, nil)
) )
@ -148,7 +148,7 @@ var (
type drbdCollector struct{} type drbdCollector struct{}
func init() { func init() {
Factories["drbd"] = newDRBDCollector registerCollector("drbd", defaultDisabled, newDRBDCollector)
} }
func newDRBDCollector() (Collector, error) { func newDRBDCollector() (Collector, error) {

View file

@ -41,29 +41,29 @@ type edacCollector struct {
} }
func init() { func init() {
Factories["edac"] = NewEdacCollector registerCollector("edac", defaultEnabled, NewEdacCollector)
} }
// NewEdacCollector returns a new Collector exposing edac stats. // NewEdacCollector returns a new Collector exposing edac stats.
func NewEdacCollector() (Collector, error) { func NewEdacCollector() (Collector, error) {
return &edacCollector{ return &edacCollector{
ceCount: prometheus.NewDesc( ceCount: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, edacSubsystem, "correctable_errors_total"), prometheus.BuildFQName(namespace, edacSubsystem, "correctable_errors_total"),
"Total correctable memory errors.", "Total correctable memory errors.",
[]string{"controller"}, nil, []string{"controller"}, nil,
), ),
ueCount: prometheus.NewDesc( ueCount: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, edacSubsystem, "uncorrectable_errors_total"), prometheus.BuildFQName(namespace, edacSubsystem, "uncorrectable_errors_total"),
"Total uncorrectable memory errors.", "Total uncorrectable memory errors.",
[]string{"controller"}, nil, []string{"controller"}, nil,
), ),
csRowCECount: prometheus.NewDesc( csRowCECount: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, edacSubsystem, "csrow_correctable_errors_total"), prometheus.BuildFQName(namespace, edacSubsystem, "csrow_correctable_errors_total"),
"Total correctable memory errors for this csrow.", "Total correctable memory errors for this csrow.",
[]string{"controller", "csrow"}, nil, []string{"controller", "csrow"}, nil,
), ),
csRowUECount: prometheus.NewDesc( csRowUECount: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, edacSubsystem, "csrow_uncorrectable_errors_total"), prometheus.BuildFQName(namespace, edacSubsystem, "csrow_uncorrectable_errors_total"),
"Total uncorrectable memory errors for this csrow.", "Total uncorrectable memory errors for this csrow.",
[]string{"controller", "csrow"}, nil, []string{"controller", "csrow"}, nil,
), ),

View file

@ -26,14 +26,14 @@ type entropyCollector struct {
} }
func init() { func init() {
Factories["entropy"] = NewEntropyCollector registerCollector("entropy", defaultEnabled, NewEntropyCollector)
} }
// NewEntropyCollector returns a new Collector exposing entropy stats. // NewEntropyCollector returns a new Collector exposing entropy stats.
func NewEntropyCollector() (Collector, error) { func NewEntropyCollector() (Collector, error) {
return &entropyCollector{ return &entropyCollector{
entropyAvail: prometheus.NewDesc( entropyAvail: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "entropy_available_bits"), prometheus.BuildFQName(namespace, "", "entropy_available_bits"),
"Bits of available entropy.", "Bits of available entropy.",
nil, nil, nil, nil,
), ),

View file

@ -25,7 +25,7 @@ type execCollector struct {
} }
func init() { func init() {
Factories["exec"] = NewExecCollector registerCollector("exec", defaultEnabled, NewExecCollector)
} }
// NewExecCollector returns a new Collector exposing system execution statistics. // NewExecCollector returns a new Collector exposing system execution statistics.
@ -95,7 +95,7 @@ func (c *execCollector) Update(ch chan<- prometheus.Metric) error {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc( prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "exec", m.name), prometheus.BuildFQName(namespace, "exec", m.name),
m.description, m.description,
nil, nil, nil, nil,
), prometheus.CounterValue, v) ), prometheus.CounterValue, v)

View file

@ -32,7 +32,7 @@ const (
type fileFDStatCollector struct{} type fileFDStatCollector struct{}
func init() { func init() {
Factories[fileFDStatSubsystem] = NewFileFDStatCollector registerCollector(fileFDStatSubsystem, defaultEnabled, NewFileFDStatCollector)
} }
// NewFileFDStatCollector returns a new Collector exposing file-nr stats. // NewFileFDStatCollector returns a new Collector exposing file-nr stats.
@ -52,7 +52,7 @@ func (c *fileFDStatCollector) Update(ch chan<- prometheus.Metric) error {
} }
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc( prometheus.NewDesc(
prometheus.BuildFQName(Namespace, fileFDStatSubsystem, name), prometheus.BuildFQName(namespace, fileFDStatSubsystem, name),
fmt.Sprintf("File descriptor statistics: %s.", name), fmt.Sprintf("File descriptor statistics: %s.", name),
nil, nil, nil, nil,
), ),

View file

@ -62,7 +62,7 @@ type filesystemStats struct {
} }
func init() { func init() {
Factories["filesystem"] = NewFilesystemCollector registerCollector("filesystem", defaultEnabled, NewFilesystemCollector)
} }
// NewFilesystemCollector returns a new Collector exposing filesystems stats. // NewFilesystemCollector returns a new Collector exposing filesystems stats.
@ -72,43 +72,43 @@ func NewFilesystemCollector() (Collector, error) {
filesystemsTypesPattern := regexp.MustCompile(*ignoredFSTypes) filesystemsTypesPattern := regexp.MustCompile(*ignoredFSTypes)
sizeDesc := prometheus.NewDesc( sizeDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "size"), prometheus.BuildFQName(namespace, subsystem, "size"),
"Filesystem size in bytes.", "Filesystem size in bytes.",
filesystemLabelNames, nil, filesystemLabelNames, nil,
) )
freeDesc := prometheus.NewDesc( freeDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "free"), prometheus.BuildFQName(namespace, subsystem, "free"),
"Filesystem free space in bytes.", "Filesystem free space in bytes.",
filesystemLabelNames, nil, filesystemLabelNames, nil,
) )
availDesc := prometheus.NewDesc( availDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "avail"), prometheus.BuildFQName(namespace, subsystem, "avail"),
"Filesystem space available to non-root users in bytes.", "Filesystem space available to non-root users in bytes.",
filesystemLabelNames, nil, filesystemLabelNames, nil,
) )
filesDesc := prometheus.NewDesc( filesDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "files"), prometheus.BuildFQName(namespace, subsystem, "files"),
"Filesystem total file nodes.", "Filesystem total file nodes.",
filesystemLabelNames, nil, filesystemLabelNames, nil,
) )
filesFreeDesc := prometheus.NewDesc( filesFreeDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "files_free"), prometheus.BuildFQName(namespace, subsystem, "files_free"),
"Filesystem total free file nodes.", "Filesystem total free file nodes.",
filesystemLabelNames, nil, filesystemLabelNames, nil,
) )
roDesc := prometheus.NewDesc( roDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "readonly"), prometheus.BuildFQName(namespace, subsystem, "readonly"),
"Filesystem read-only status.", "Filesystem read-only status.",
filesystemLabelNames, nil, filesystemLabelNames, nil,
) )
deviceErrorDesc := prometheus.NewDesc( deviceErrorDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "device_error"), prometheus.BuildFQName(namespace, subsystem, "device_error"),
"Whether an error occurred while getting statistics for the given device.", "Whether an error occurred while getting statistics for the given device.",
filesystemLabelNames, nil, filesystemLabelNames, nil,
) )

View file

@ -41,7 +41,7 @@ type gmondCollector struct {
} }
func init() { func init() {
Factories["gmond"] = NewGmondCollector registerCollector("gmond", defaultDisabled, NewGmondCollector)
} }
var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`) var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)

View file

@ -42,7 +42,7 @@ var (
) )
func init() { func init() {
Factories["hwmon"] = NewHwMonCollector registerCollector("hwmon", defaultEnabled, NewHwMonCollector)
} }
type hwMonCollector struct{} type hwMonCollector struct{}

View file

@ -44,7 +44,7 @@ type infinibandMetric struct {
} }
func init() { func init() {
Factories["infiniband"] = NewInfiniBandCollector registerCollector("infiniband", defaultEnabled, NewInfiniBandCollector)
} }
// NewInfiniBandCollector returns a new Collector exposing InfiniBand stats. // NewInfiniBandCollector returns a new Collector exposing InfiniBand stats.
@ -80,7 +80,7 @@ func NewInfiniBandCollector() (Collector, error) {
for metricName, infinibandMetric := range i.counters { for metricName, infinibandMetric := range i.counters {
i.metricDescs[metricName] = prometheus.NewDesc( i.metricDescs[metricName] = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, metricName), prometheus.BuildFQName(namespace, subsystem, metricName),
infinibandMetric.Help, infinibandMetric.Help,
[]string{"device", "port"}, []string{"device", "port"},
nil, nil,
@ -89,7 +89,7 @@ func NewInfiniBandCollector() (Collector, error) {
for metricName, infinibandMetric := range i.legacyCounters { for metricName, infinibandMetric := range i.legacyCounters {
i.metricDescs[metricName] = prometheus.NewDesc( i.metricDescs[metricName] = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, metricName), prometheus.BuildFQName(namespace, subsystem, metricName),
infinibandMetric.Help, infinibandMetric.Help,
[]string{"device", "port"}, []string{"device", "port"},
nil, nil,

View file

@ -23,14 +23,14 @@ type interruptsCollector struct {
} }
func init() { func init() {
Factories["interrupts"] = NewInterruptsCollector registerCollector("interrupts", defaultDisabled, NewInterruptsCollector)
} }
// NewInterruptsCollector returns a new Collector exposing interrupts stats. // NewInterruptsCollector returns a new Collector exposing interrupts stats.
func NewInterruptsCollector() (Collector, error) { func NewInterruptsCollector() (Collector, error) {
return &interruptsCollector{ return &interruptsCollector{
desc: typedDesc{prometheus.NewDesc( desc: typedDesc{prometheus.NewDesc(
Namespace+"_interrupts", namespace+"_interrupts",
"Interrupt details.", "Interrupt details.",
interruptLabelNames, nil, interruptLabelNames, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},

View file

@ -33,7 +33,7 @@ type ipvsCollector struct {
} }
func init() { func init() {
Factories["ipvs"] = NewIPVSCollector registerCollector("ipvs", defaultEnabled, NewIPVSCollector)
} }
// NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the // NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the
@ -62,42 +62,42 @@ func newIPVSCollector() (*ipvsCollector, error) {
} }
c.connections = typedDesc{prometheus.NewDesc( c.connections = typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "connections_total"), prometheus.BuildFQName(namespace, subsystem, "connections_total"),
"The total number of connections made.", "The total number of connections made.",
nil, nil, nil, nil,
), prometheus.CounterValue} ), prometheus.CounterValue}
c.incomingPackets = typedDesc{prometheus.NewDesc( c.incomingPackets = typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "incoming_packets_total"), prometheus.BuildFQName(namespace, subsystem, "incoming_packets_total"),
"The total number of incoming packets.", "The total number of incoming packets.",
nil, nil, nil, nil,
), prometheus.CounterValue} ), prometheus.CounterValue}
c.outgoingPackets = typedDesc{prometheus.NewDesc( c.outgoingPackets = typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "outgoing_packets_total"), prometheus.BuildFQName(namespace, subsystem, "outgoing_packets_total"),
"The total number of outgoing packets.", "The total number of outgoing packets.",
nil, nil, nil, nil,
), prometheus.CounterValue} ), prometheus.CounterValue}
c.incomingBytes = typedDesc{prometheus.NewDesc( c.incomingBytes = typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "incoming_bytes_total"), prometheus.BuildFQName(namespace, subsystem, "incoming_bytes_total"),
"The total amount of incoming data.", "The total amount of incoming data.",
nil, nil, nil, nil,
), prometheus.CounterValue} ), prometheus.CounterValue}
c.outgoingBytes = typedDesc{prometheus.NewDesc( c.outgoingBytes = typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "outgoing_bytes_total"), prometheus.BuildFQName(namespace, subsystem, "outgoing_bytes_total"),
"The total amount of outgoing data.", "The total amount of outgoing data.",
nil, nil, nil, nil,
), prometheus.CounterValue} ), prometheus.CounterValue}
c.backendConnectionsActive = typedDesc{prometheus.NewDesc( c.backendConnectionsActive = typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "backend_connections_active"), prometheus.BuildFQName(namespace, subsystem, "backend_connections_active"),
"The current active connections by local and remote address.", "The current active connections by local and remote address.",
ipvsBackendLabelNames, nil, ipvsBackendLabelNames, nil,
), prometheus.GaugeValue} ), prometheus.GaugeValue}
c.backendConnectionsInact = typedDesc{prometheus.NewDesc( c.backendConnectionsInact = typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "backend_connections_inactive"), prometheus.BuildFQName(namespace, subsystem, "backend_connections_inactive"),
"The current inactive connections by local and remote address.", "The current inactive connections by local and remote address.",
ipvsBackendLabelNames, nil, ipvsBackendLabelNames, nil,
), prometheus.GaugeValue} ), prometheus.GaugeValue}
c.backendWeight = typedDesc{prometheus.NewDesc( c.backendWeight = typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "backend_weight"), prometheus.BuildFQName(namespace, subsystem, "backend_weight"),
"The current backend weight by local and remote address.", "The current backend weight by local and remote address.",
ipvsBackendLabelNames, nil, ipvsBackendLabelNames, nil,
), prometheus.GaugeValue} ), prometheus.GaugeValue}

View file

@ -27,7 +27,7 @@ import (
) )
func TestIPVSCollector(t *testing.T) { func TestIPVSCollector(t *testing.T) {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", "fixtures/proc"}); err != nil { if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "fixtures/proc"}); err != nil {
t.Fatal(err) t.Fatal(err)
} }
collector, err := newIPVSCollector() collector, err := newIPVSCollector()
@ -76,7 +76,7 @@ func (c miniCollector) Describe(ch chan<- *prometheus.Desc) {
} }
func TestIPVSCollectorResponse(t *testing.T) { func TestIPVSCollectorResponse(t *testing.T) {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", "fixtures/proc"}); err != nil { if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "fixtures/proc"}); err != nil {
t.Fatal(err) t.Fatal(err)
} }
collector, err := NewIPVSCollector() collector, err := NewIPVSCollector()

View file

@ -32,7 +32,7 @@ type ksmdCollector struct {
} }
func init() { func init() {
Factories["ksmd"] = NewKsmdCollector registerCollector("ksmd", defaultDisabled, NewKsmdCollector)
} }
func getCanonicalMetricName(filename string) string { func getCanonicalMetricName(filename string) string {
@ -53,7 +53,7 @@ func NewKsmdCollector() (Collector, error) {
for _, n := range ksmdFiles { for _, n := range ksmdFiles {
descs[n] = prometheus.NewDesc( descs[n] = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, getCanonicalMetricName(n)), prometheus.BuildFQName(namespace, subsystem, getCanonicalMetricName(n)),
fmt.Sprintf("ksmd '%s' file.", n), nil, nil) fmt.Sprintf("ksmd '%s' file.", n), nil, nil)
} }
return &ksmdCollector{descs}, nil return &ksmdCollector{descs}, nil

View file

@ -28,16 +28,16 @@ type loadavgCollector struct {
} }
func init() { func init() {
Factories["loadavg"] = NewLoadavgCollector registerCollector("loadavg", defaultEnabled, NewLoadavgCollector)
} }
// NewLoadavgCollector returns a new Collector exposing load average stats. // NewLoadavgCollector returns a new Collector exposing load average stats.
func NewLoadavgCollector() (Collector, error) { func NewLoadavgCollector() (Collector, error) {
return &loadavgCollector{ return &loadavgCollector{
metric: []typedDesc{ metric: []typedDesc{
{prometheus.NewDesc(Namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue}, {prometheus.NewDesc(namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue},
{prometheus.NewDesc(Namespace+"_load5", "5m load average.", nil, nil), prometheus.GaugeValue}, {prometheus.NewDesc(namespace+"_load5", "5m load average.", nil, nil), prometheus.GaugeValue},
{prometheus.NewDesc(Namespace+"_load15", "15m load average.", nil, nil), prometheus.GaugeValue}, {prometheus.NewDesc(namespace+"_load15", "15m load average.", nil, nil), prometheus.GaugeValue},
}, },
}, nil }, nil
} }

View file

@ -38,7 +38,7 @@ var (
attrClassValues = []string{"other", "user", "greeter", "lock-screen", "background"} attrClassValues = []string{"other", "user", "greeter", "lock-screen", "background"}
sessionsDesc = prometheus.NewDesc( sessionsDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, logindSubsystem, "sessions"), prometheus.BuildFQName(namespace, logindSubsystem, "sessions"),
"Number of sessions registered in logind.", []string{"seat", "remote", "type", "class"}, nil, "Number of sessions registered in logind.", []string{"seat", "remote", "type", "class"}, nil,
) )
) )
@ -78,7 +78,7 @@ type logindSeatEntry struct {
} }
func init() { func init() {
Factories["logind"] = NewLogindCollector registerCollector("logind", defaultDisabled, NewLogindCollector)
} }
// NewLogindCollector returns a new Collector exposing logind statistics. // NewLogindCollector returns a new Collector exposing logind statistics.

View file

@ -47,7 +47,7 @@ type mdStatus struct {
type mdadmCollector struct{} type mdadmCollector struct{}
func init() { func init() {
Factories["mdadm"] = NewMdadmCollector registerCollector("mdadm", defaultEnabled, NewMdadmCollector)
} }
func evalStatusline(statusline string) (active, total, size int64, err error) { func evalStatusline(statusline string) (active, total, size int64, err error) {
@ -220,35 +220,35 @@ func NewMdadmCollector() (Collector, error) {
var ( var (
isActiveDesc = prometheus.NewDesc( isActiveDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "md", "is_active"), prometheus.BuildFQName(namespace, "md", "is_active"),
"Indicator whether the md-device is active or not.", "Indicator whether the md-device is active or not.",
[]string{"device"}, []string{"device"},
nil, nil,
) )
disksActiveDesc = prometheus.NewDesc( disksActiveDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "md", "disks_active"), prometheus.BuildFQName(namespace, "md", "disks_active"),
"Number of active disks of device.", "Number of active disks of device.",
[]string{"device"}, []string{"device"},
nil, nil,
) )
disksTotalDesc = prometheus.NewDesc( disksTotalDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "md", "disks"), prometheus.BuildFQName(namespace, "md", "disks"),
"Total number of disks of device.", "Total number of disks of device.",
[]string{"device"}, []string{"device"},
nil, nil,
) )
blocksTotalDesc = prometheus.NewDesc( blocksTotalDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "md", "blocks"), prometheus.BuildFQName(namespace, "md", "blocks"),
"Total number of blocks on device.", "Total number of blocks on device.",
[]string{"device"}, []string{"device"},
nil, nil,
) )
blocksSyncedDesc = prometheus.NewDesc( blocksSyncedDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "md", "blocks_synced"), prometheus.BuildFQName(namespace, "md", "blocks_synced"),
"Number of blocks synced on device.", "Number of blocks synced on device.",
[]string{"device"}, []string{"device"},
nil, nil,

View file

@ -44,7 +44,7 @@ type megaCliCollector struct {
} }
func init() { func init() {
Factories["megacli"] = NewMegaCliCollector registerCollector("megacli", defaultDisabled, NewMegaCliCollector)
} }
// NewMegaCliCollector returns a new Collector exposing RAID status through // NewMegaCliCollector returns a new Collector exposing RAID status through
@ -54,17 +54,17 @@ func NewMegaCliCollector() (Collector, error) {
return &megaCliCollector{ return &megaCliCollector{
cli: *megacliCommand, cli: *megacliCommand,
driveTemperature: prometheus.NewGaugeVec(prometheus.GaugeOpts{ driveTemperature: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace, Namespace: namespace,
Name: "megacli_drive_temperature_celsius", Name: "megacli_drive_temperature_celsius",
Help: "megacli: drive temperature", Help: "megacli: drive temperature",
}, []string{"enclosure", "slot"}), }, []string{"enclosure", "slot"}),
driveCounters: prometheus.NewGaugeVec(prometheus.GaugeOpts{ driveCounters: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace, Namespace: namespace,
Name: "megacli_drive_count", Name: "megacli_drive_count",
Help: "megacli: drive error and event counters", Help: "megacli: drive error and event counters",
}, []string{"enclosure", "slot", "type"}), }, []string{"enclosure", "slot", "type"}),
drivePresence: prometheus.NewGaugeVec(prometheus.GaugeOpts{ drivePresence: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace, Namespace: namespace,
Name: "megacli_adapter_disk_presence", Name: "megacli_adapter_disk_presence",
Help: "megacli: disk presence per adapter", Help: "megacli: disk presence per adapter",
}, []string{"type"}), }, []string{"type"}),

View file

@ -30,7 +30,7 @@ const (
type meminfoCollector struct{} type meminfoCollector struct{}
func init() { func init() {
Factories["meminfo"] = NewMeminfoCollector registerCollector("meminfo", defaultEnabled, NewMeminfoCollector)
} }
// NewMeminfoCollector returns a new Collector exposing memory stats. // NewMeminfoCollector returns a new Collector exposing memory stats.
@ -49,7 +49,7 @@ func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error {
for k, v := range memInfo { for k, v := range memInfo {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc( prometheus.NewDesc(
prometheus.BuildFQName(Namespace, memInfoSubsystem, k), prometheus.BuildFQName(namespace, memInfoSubsystem, k),
fmt.Sprintf("Memory information field %s.", k), fmt.Sprintf("Memory information field %s.", k),
nil, nil, nil, nil,
), ),

View file

@ -47,7 +47,7 @@ type meminfoNumaCollector struct {
} }
func init() { func init() {
Factories["meminfo_numa"] = NewMeminfoNumaCollector registerCollector("meminfo_numa", defaultDisabled, NewMeminfoNumaCollector)
} }
// NewMeminfoNumaCollector returns a new Collector exposing memory stats. // NewMeminfoNumaCollector returns a new Collector exposing memory stats.
@ -66,7 +66,7 @@ func (c *meminfoNumaCollector) Update(ch chan<- prometheus.Metric) error {
desc, ok := c.metricDescs[v.metricName] desc, ok := c.metricDescs[v.metricName]
if !ok { if !ok {
desc = prometheus.NewDesc( desc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, memInfoNumaSubsystem, v.metricName), prometheus.BuildFQName(namespace, memInfoNumaSubsystem, v.metricName),
fmt.Sprintf("Memory information field %s.", v.metricName), fmt.Sprintf("Memory information field %s.", v.metricName),
[]string{"node"}, nil) []string{"node"}, nil)
c.metricDescs[v.metricName] = desc c.metricDescs[v.metricName] = desc

View file

@ -90,7 +90,7 @@ type mountStatsCollector struct {
} }
func init() { func init() {
Factories["mountstats"] = NewMountStatsCollector registerCollector("mountstats", defaultDisabled, NewMountStatsCollector)
} }
// NewMountStatsCollector returns a new Collector exposing NFS statistics. // NewMountStatsCollector returns a new Collector exposing NFS statistics.
@ -117,371 +117,371 @@ func NewMountStatsCollector() (Collector, error) {
return &mountStatsCollector{ return &mountStatsCollector{
NFSAgeSecondsTotal: prometheus.NewDesc( NFSAgeSecondsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "age_seconds_total"), prometheus.BuildFQName(namespace, subsystem, "age_seconds_total"),
"The age of the NFS mount in seconds.", "The age of the NFS mount in seconds.",
labels, labels,
nil, nil,
), ),
NFSReadBytesTotal: prometheus.NewDesc( NFSReadBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "read_bytes_total"), prometheus.BuildFQName(namespace, subsystem, "read_bytes_total"),
"Number of bytes read using the read() syscall.", "Number of bytes read using the read() syscall.",
labels, labels,
nil, nil,
), ),
NFSWriteBytesTotal: prometheus.NewDesc( NFSWriteBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "write_bytes_total"), prometheus.BuildFQName(namespace, subsystem, "write_bytes_total"),
"Number of bytes written using the write() syscall.", "Number of bytes written using the write() syscall.",
labels, labels,
nil, nil,
), ),
NFSDirectReadBytesTotal: prometheus.NewDesc( NFSDirectReadBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "direct_read_bytes_total"), prometheus.BuildFQName(namespace, subsystem, "direct_read_bytes_total"),
"Number of bytes read using the read() syscall in O_DIRECT mode.", "Number of bytes read using the read() syscall in O_DIRECT mode.",
labels, labels,
nil, nil,
), ),
NFSDirectWriteBytesTotal: prometheus.NewDesc( NFSDirectWriteBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "direct_write_bytes_total"), prometheus.BuildFQName(namespace, subsystem, "direct_write_bytes_total"),
"Number of bytes written using the write() syscall in O_DIRECT mode.", "Number of bytes written using the write() syscall in O_DIRECT mode.",
labels, labels,
nil, nil,
), ),
NFSTotalReadBytesTotal: prometheus.NewDesc( NFSTotalReadBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "total_read_bytes_total"), prometheus.BuildFQName(namespace, subsystem, "total_read_bytes_total"),
"Number of bytes read from the NFS server, in total.", "Number of bytes read from the NFS server, in total.",
labels, labels,
nil, nil,
), ),
NFSTotalWriteBytesTotal: prometheus.NewDesc( NFSTotalWriteBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "total_write_bytes_total"), prometheus.BuildFQName(namespace, subsystem, "total_write_bytes_total"),
"Number of bytes written to the NFS server, in total.", "Number of bytes written to the NFS server, in total.",
labels, labels,
nil, nil,
), ),
NFSReadPagesTotal: prometheus.NewDesc( NFSReadPagesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "read_pages_total"), prometheus.BuildFQName(namespace, subsystem, "read_pages_total"),
"Number of pages read directly via mmap()'d files.", "Number of pages read directly via mmap()'d files.",
labels, labels,
nil, nil,
), ),
NFSWritePagesTotal: prometheus.NewDesc( NFSWritePagesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "write_pages_total"), prometheus.BuildFQName(namespace, subsystem, "write_pages_total"),
"Number of pages written directly via mmap()'d files.", "Number of pages written directly via mmap()'d files.",
labels, labels,
nil, nil,
), ),
NFSTransportBindTotal: prometheus.NewDesc( NFSTransportBindTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transport_bind_total"), prometheus.BuildFQName(namespace, subsystem, "transport_bind_total"),
"Number of times the client has had to establish a connection from scratch to the NFS server.", "Number of times the client has had to establish a connection from scratch to the NFS server.",
labels, labels,
nil, nil,
), ),
NFSTransportConnectTotal: prometheus.NewDesc( NFSTransportConnectTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transport_connect_total"), prometheus.BuildFQName(namespace, subsystem, "transport_connect_total"),
"Number of times the client has made a TCP connection to the NFS server.", "Number of times the client has made a TCP connection to the NFS server.",
labels, labels,
nil, nil,
), ),
NFSTransportIdleTimeSeconds: prometheus.NewDesc( NFSTransportIdleTimeSeconds: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transport_idle_time_seconds"), prometheus.BuildFQName(namespace, subsystem, "transport_idle_time_seconds"),
"Duration since the NFS mount last saw any RPC traffic, in seconds.", "Duration since the NFS mount last saw any RPC traffic, in seconds.",
labels, labels,
nil, nil,
), ),
NFSTransportSendsTotal: prometheus.NewDesc( NFSTransportSendsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transport_sends_total"), prometheus.BuildFQName(namespace, subsystem, "transport_sends_total"),
"Number of RPC requests for this mount sent to the NFS server.", "Number of RPC requests for this mount sent to the NFS server.",
labels, labels,
nil, nil,
), ),
NFSTransportReceivesTotal: prometheus.NewDesc( NFSTransportReceivesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transport_receives_total"), prometheus.BuildFQName(namespace, subsystem, "transport_receives_total"),
"Number of RPC responses for this mount received from the NFS server.", "Number of RPC responses for this mount received from the NFS server.",
labels, labels,
nil, nil,
), ),
NFSTransportBadTransactionIDsTotal: prometheus.NewDesc( NFSTransportBadTransactionIDsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transport_bad_transaction_ids_total"), prometheus.BuildFQName(namespace, subsystem, "transport_bad_transaction_ids_total"),
"Number of times the NFS server sent a response with a transaction ID unknown to this client.", "Number of times the NFS server sent a response with a transaction ID unknown to this client.",
labels, labels,
nil, nil,
), ),
NFSTransportBacklogQueueTotal: prometheus.NewDesc( NFSTransportBacklogQueueTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transport_backlog_queue_total"), prometheus.BuildFQName(namespace, subsystem, "transport_backlog_queue_total"),
"Total number of items added to the RPC backlog queue.", "Total number of items added to the RPC backlog queue.",
labels, labels,
nil, nil,
), ),
NFSTransportMaximumRPCSlots: prometheus.NewDesc( NFSTransportMaximumRPCSlots: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transport_maximum_rpc_slots"), prometheus.BuildFQName(namespace, subsystem, "transport_maximum_rpc_slots"),
"Maximum number of simultaneously active RPC requests ever used.", "Maximum number of simultaneously active RPC requests ever used.",
labels, labels,
nil, nil,
), ),
NFSTransportSendingQueueTotal: prometheus.NewDesc( NFSTransportSendingQueueTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transport_sending_queue_total"), prometheus.BuildFQName(namespace, subsystem, "transport_sending_queue_total"),
"Total number of items added to the RPC transmission sending queue.", "Total number of items added to the RPC transmission sending queue.",
labels, labels,
nil, nil,
), ),
NFSTransportPendingQueueTotal: prometheus.NewDesc( NFSTransportPendingQueueTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transport_pending_queue_total"), prometheus.BuildFQName(namespace, subsystem, "transport_pending_queue_total"),
"Total number of items added to the RPC transmission pending queue.", "Total number of items added to the RPC transmission pending queue.",
labels, labels,
nil, nil,
), ),
NFSOperationsRequestsTotal: prometheus.NewDesc( NFSOperationsRequestsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "operations_requests_total"), prometheus.BuildFQName(namespace, subsystem, "operations_requests_total"),
"Number of requests performed for a given operation.", "Number of requests performed for a given operation.",
opLabels, opLabels,
nil, nil,
), ),
NFSOperationsTransmissionsTotal: prometheus.NewDesc( NFSOperationsTransmissionsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "operations_transmissions_total"), prometheus.BuildFQName(namespace, subsystem, "operations_transmissions_total"),
"Number of times an actual RPC request has been transmitted for a given operation.", "Number of times an actual RPC request has been transmitted for a given operation.",
opLabels, opLabels,
nil, nil,
), ),
NFSOperationsMajorTimeoutsTotal: prometheus.NewDesc( NFSOperationsMajorTimeoutsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "operations_major_timeouts_total"), prometheus.BuildFQName(namespace, subsystem, "operations_major_timeouts_total"),
"Number of times a request has had a major timeout for a given operation.", "Number of times a request has had a major timeout for a given operation.",
opLabels, opLabels,
nil, nil,
), ),
NFSOperationsSentBytesTotal: prometheus.NewDesc( NFSOperationsSentBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "operations_sent_bytes_total"), prometheus.BuildFQName(namespace, subsystem, "operations_sent_bytes_total"),
"Number of bytes sent for a given operation, including RPC headers and payload.", "Number of bytes sent for a given operation, including RPC headers and payload.",
opLabels, opLabels,
nil, nil,
), ),
NFSOperationsReceivedBytesTotal: prometheus.NewDesc( NFSOperationsReceivedBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "operations_received_bytes_total"), prometheus.BuildFQName(namespace, subsystem, "operations_received_bytes_total"),
"Number of bytes received for a given operation, including RPC headers and payload.", "Number of bytes received for a given operation, including RPC headers and payload.",
opLabels, opLabels,
nil, nil,
), ),
NFSOperationsQueueTimeSecondsTotal: prometheus.NewDesc( NFSOperationsQueueTimeSecondsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "operations_queue_time_seconds_total"), prometheus.BuildFQName(namespace, subsystem, "operations_queue_time_seconds_total"),
"Duration all requests spent queued for transmission for a given operation before they were sent, in seconds.", "Duration all requests spent queued for transmission for a given operation before they were sent, in seconds.",
opLabels, opLabels,
nil, nil,
), ),
NFSOperationsResponseTimeSecondsTotal: prometheus.NewDesc( NFSOperationsResponseTimeSecondsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "operations_response_time_seconds_total"), prometheus.BuildFQName(namespace, subsystem, "operations_response_time_seconds_total"),
"Duration all requests took to get a reply back after a request for a given operation was transmitted, in seconds.", "Duration all requests took to get a reply back after a request for a given operation was transmitted, in seconds.",
opLabels, opLabels,
nil, nil,
), ),
NFSOperationsRequestTimeSecondsTotal: prometheus.NewDesc( NFSOperationsRequestTimeSecondsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "operations_request_time_seconds_total"), prometheus.BuildFQName(namespace, subsystem, "operations_request_time_seconds_total"),
"Duration all requests took from when a request was enqueued to when it was completely handled for a given operation, in seconds.", "Duration all requests took from when a request was enqueued to when it was completely handled for a given operation, in seconds.",
opLabels, opLabels,
nil, nil,
), ),
NFSEventInodeRevalidateTotal: prometheus.NewDesc( NFSEventInodeRevalidateTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_inode_revalidate_total"), prometheus.BuildFQName(namespace, subsystem, "event_inode_revalidate_total"),
"Number of times cached inode attributes are re-validated from the server.", "Number of times cached inode attributes are re-validated from the server.",
labels, labels,
nil, nil,
), ),
NFSEventDnodeRevalidateTotal: prometheus.NewDesc( NFSEventDnodeRevalidateTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_dnode_revalidate_total"), prometheus.BuildFQName(namespace, subsystem, "event_dnode_revalidate_total"),
"Number of times cached dentry nodes are re-validated from the server.", "Number of times cached dentry nodes are re-validated from the server.",
labels, labels,
nil, nil,
), ),
NFSEventDataInvalidateTotal: prometheus.NewDesc( NFSEventDataInvalidateTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_data_invalidate_total"), prometheus.BuildFQName(namespace, subsystem, "event_data_invalidate_total"),
"Number of times an inode cache is cleared.", "Number of times an inode cache is cleared.",
labels, labels,
nil, nil,
), ),
NFSEventAttributeInvalidateTotal: prometheus.NewDesc( NFSEventAttributeInvalidateTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_attribute_invalidate_total"), prometheus.BuildFQName(namespace, subsystem, "event_attribute_invalidate_total"),
"Number of times cached inode attributes are invalidated.", "Number of times cached inode attributes are invalidated.",
labels, labels,
nil, nil,
), ),
NFSEventVFSOpenTotal: prometheus.NewDesc( NFSEventVFSOpenTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_open_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_open_total"),
"Number of times cached inode attributes are invalidated.", "Number of times cached inode attributes are invalidated.",
labels, labels,
nil, nil,
), ),
NFSEventVFSLookupTotal: prometheus.NewDesc( NFSEventVFSLookupTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_lookup_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_lookup_total"),
"Number of times a directory lookup has occurred.", "Number of times a directory lookup has occurred.",
labels, labels,
nil, nil,
), ),
NFSEventVFSAccessTotal: prometheus.NewDesc( NFSEventVFSAccessTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_access_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_access_total"),
"Number of times permissions have been checked.", "Number of times permissions have been checked.",
labels, labels,
nil, nil,
), ),
NFSEventVFSUpdatePageTotal: prometheus.NewDesc( NFSEventVFSUpdatePageTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_update_page_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_update_page_total"),
"Number of updates (and potential writes) to pages.", "Number of updates (and potential writes) to pages.",
labels, labels,
nil, nil,
), ),
NFSEventVFSReadPageTotal: prometheus.NewDesc( NFSEventVFSReadPageTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_read_page_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_read_page_total"),
"Number of pages read directly via mmap()'d files.", "Number of pages read directly via mmap()'d files.",
labels, labels,
nil, nil,
), ),
NFSEventVFSReadPagesTotal: prometheus.NewDesc( NFSEventVFSReadPagesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_read_pages_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_read_pages_total"),
"Number of times a group of pages have been read.", "Number of times a group of pages have been read.",
labels, labels,
nil, nil,
), ),
NFSEventVFSWritePageTotal: prometheus.NewDesc( NFSEventVFSWritePageTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_write_page_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_write_page_total"),
"Number of pages written directly via mmap()'d files.", "Number of pages written directly via mmap()'d files.",
labels, labels,
nil, nil,
), ),
NFSEventVFSWritePagesTotal: prometheus.NewDesc( NFSEventVFSWritePagesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_write_pages_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_write_pages_total"),
"Number of times a group of pages have been written.", "Number of times a group of pages have been written.",
labels, labels,
nil, nil,
), ),
NFSEventVFSGetdentsTotal: prometheus.NewDesc( NFSEventVFSGetdentsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_getdents_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_getdents_total"),
"Number of times directory entries have been read with getdents().", "Number of times directory entries have been read with getdents().",
labels, labels,
nil, nil,
), ),
NFSEventVFSSetattrTotal: prometheus.NewDesc( NFSEventVFSSetattrTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_setattr_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_setattr_total"),
"Number of times directory entries have been read with getdents().", "Number of times directory entries have been read with getdents().",
labels, labels,
nil, nil,
), ),
NFSEventVFSFlushTotal: prometheus.NewDesc( NFSEventVFSFlushTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_flush_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_flush_total"),
"Number of pending writes that have been forcefully flushed to the server.", "Number of pending writes that have been forcefully flushed to the server.",
labels, labels,
nil, nil,
), ),
NFSEventVFSFsyncTotal: prometheus.NewDesc( NFSEventVFSFsyncTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_fsync_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_fsync_total"),
"Number of times fsync() has been called on directories and files.", "Number of times fsync() has been called on directories and files.",
labels, labels,
nil, nil,
), ),
NFSEventVFSLockTotal: prometheus.NewDesc( NFSEventVFSLockTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_lock_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_lock_total"),
"Number of times locking has been attempted on a file.", "Number of times locking has been attempted on a file.",
labels, labels,
nil, nil,
), ),
NFSEventVFSFileReleaseTotal: prometheus.NewDesc( NFSEventVFSFileReleaseTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_vfs_file_release_total"), prometheus.BuildFQName(namespace, subsystem, "event_vfs_file_release_total"),
"Number of times files have been closed and released.", "Number of times files have been closed and released.",
labels, labels,
nil, nil,
), ),
NFSEventTruncationTotal: prometheus.NewDesc( NFSEventTruncationTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_truncation_total"), prometheus.BuildFQName(namespace, subsystem, "event_truncation_total"),
"Number of times files have been truncated.", "Number of times files have been truncated.",
labels, labels,
nil, nil,
), ),
NFSEventWriteExtensionTotal: prometheus.NewDesc( NFSEventWriteExtensionTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_write_extension_total"), prometheus.BuildFQName(namespace, subsystem, "event_write_extension_total"),
"Number of times a file has been grown due to writes beyond its existing end.", "Number of times a file has been grown due to writes beyond its existing end.",
labels, labels,
nil, nil,
), ),
NFSEventSillyRenameTotal: prometheus.NewDesc( NFSEventSillyRenameTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_silly_rename_total"), prometheus.BuildFQName(namespace, subsystem, "event_silly_rename_total"),
"Number of times a file was removed while still open by another process.", "Number of times a file was removed while still open by another process.",
labels, labels,
nil, nil,
), ),
NFSEventShortReadTotal: prometheus.NewDesc( NFSEventShortReadTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_short_read_total"), prometheus.BuildFQName(namespace, subsystem, "event_short_read_total"),
"Number of times the NFS server gave less data than expected while reading.", "Number of times the NFS server gave less data than expected while reading.",
labels, labels,
nil, nil,
), ),
NFSEventShortWriteTotal: prometheus.NewDesc( NFSEventShortWriteTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_short_write_total"), prometheus.BuildFQName(namespace, subsystem, "event_short_write_total"),
"Number of times the NFS server wrote less data than expected while writing.", "Number of times the NFS server wrote less data than expected while writing.",
labels, labels,
nil, nil,
), ),
NFSEventJukeboxDelayTotal: prometheus.NewDesc( NFSEventJukeboxDelayTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_jukebox_delay_total"), prometheus.BuildFQName(namespace, subsystem, "event_jukebox_delay_total"),
"Number of times the NFS server indicated EJUKEBOX; retrieving data from offline storage.", "Number of times the NFS server indicated EJUKEBOX; retrieving data from offline storage.",
labels, labels,
nil, nil,
), ),
NFSEventPNFSReadTotal: prometheus.NewDesc( NFSEventPNFSReadTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_pnfs_read_total"), prometheus.BuildFQName(namespace, subsystem, "event_pnfs_read_total"),
"Number of NFS v4.1+ pNFS reads.", "Number of NFS v4.1+ pNFS reads.",
labels, labels,
nil, nil,
), ),
NFSEventPNFSWriteTotal: prometheus.NewDesc( NFSEventPNFSWriteTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "event_pnfs_write_total"), prometheus.BuildFQName(namespace, subsystem, "event_pnfs_write_total"),
"Number of NFS v4.1+ pNFS writes.", "Number of NFS v4.1+ pNFS writes.",
labels, labels,
nil, nil,

View file

@ -36,7 +36,7 @@ type netDevCollector struct {
} }
func init() { func init() {
Factories["netdev"] = NewNetDevCollector registerCollector("netdev", defaultEnabled, NewNetDevCollector)
} }
// NewNetDevCollector returns a new Collector exposing network device stats. // NewNetDevCollector returns a new Collector exposing network device stats.
@ -59,7 +59,7 @@ func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error {
desc, ok := c.metricDescs[key] desc, ok := c.metricDescs[key]
if !ok { if !ok {
desc = prometheus.NewDesc( desc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, c.subsystem, key), prometheus.BuildFQName(namespace, c.subsystem, key),
fmt.Sprintf("Network device statistic %s.", key), fmt.Sprintf("Network device statistic %s.", key),
[]string{"device"}, []string{"device"},
nil, nil,

View file

@ -33,7 +33,7 @@ const (
type netStatCollector struct{} type netStatCollector struct{}
func init() { func init() {
Factories["netstat"] = NewNetStatCollector registerCollector("netstat", defaultEnabled, NewNetStatCollector)
} }
// NewNetStatCollector takes and returns // NewNetStatCollector takes and returns
@ -72,7 +72,7 @@ func (c *netStatCollector) Update(ch chan<- prometheus.Metric) error {
} }
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc( prometheus.NewDesc(
prometheus.BuildFQName(Namespace, netStatsSubsystem, key), prometheus.BuildFQName(namespace, netStatsSubsystem, key),
fmt.Sprintf("Statistic %s.", protocol+name), fmt.Sprintf("Statistic %s.", protocol+name),
nil, nil, nil, nil,
), ),

View file

@ -66,39 +66,39 @@ var (
} }
nfsNetReadsDesc = prometheus.NewDesc( nfsNetReadsDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "nfs", "net_reads"), prometheus.BuildFQName(namespace, "nfs", "net_reads"),
"Number of reads at the network layer.", "Number of reads at the network layer.",
[]string{"protocol"}, []string{"protocol"},
nil, nil,
) )
nfsNetConnectionsDesc = prometheus.NewDesc( nfsNetConnectionsDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "nfs", "net_connections"), prometheus.BuildFQName(namespace, "nfs", "net_connections"),
"Number of connections at the network layer.", "Number of connections at the network layer.",
[]string{"protocol"}, []string{"protocol"},
nil, nil,
) )
nfsRPCOperationsDesc = prometheus.NewDesc( nfsRPCOperationsDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "nfs", "rpc_operations"), prometheus.BuildFQName(namespace, "nfs", "rpc_operations"),
"Number of RPCs performed.", "Number of RPCs performed.",
nil, nil,
nil, nil,
) )
nfsRPCRetransmissionsDesc = prometheus.NewDesc( nfsRPCRetransmissionsDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "nfs", "rpc_retransmissions"), prometheus.BuildFQName(namespace, "nfs", "rpc_retransmissions"),
"Number of RPC transmissions performed.", "Number of RPC transmissions performed.",
nil, nil,
nil, nil,
) )
nfsRPCAuthenticationRefreshesDesc = prometheus.NewDesc( nfsRPCAuthenticationRefreshesDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "nfs", "rpc_authentication_refreshes"), prometheus.BuildFQName(namespace, "nfs", "rpc_authentication_refreshes"),
"Number of RPC authentication refreshes performed.", "Number of RPC authentication refreshes performed.",
nil, nil,
nil, nil,
) )
nfsProceduresDesc = prometheus.NewDesc( nfsProceduresDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "nfs", "procedures"), prometheus.BuildFQName(namespace, "nfs", "procedures"),
"Number of NFS procedures invoked.", "Number of NFS procedures invoked.",
[]string{"version", "procedure"}, []string{"version", "procedure"},
nil, nil,
@ -108,7 +108,7 @@ var (
type nfsCollector struct{} type nfsCollector struct{}
func init() { func init() {
Factories["nfs"] = NewNfsCollector registerCollector("nfs", defaultDisabled, NewNfsCollector)
} }
// NewNfsCollector returns a new Collector exposing NFS statistics. // NewNfsCollector returns a new Collector exposing NFS statistics.

View file

@ -26,7 +26,7 @@ import (
) )
const ( const (
hour24 = 24 * time.Hour // `time` does not export `Day` as Day != 24h because of DST hour24 = 24 * time.Hour // `time` does not export `Day` as Day != 24h because of DST
ntpSubsystem = "ntp" ntpSubsystem = "ntp"
) )
@ -48,7 +48,7 @@ type ntpCollector struct {
} }
func init() { func init() {
Factories["ntp"] = NewNtpCollector registerCollector("ntp", defaultDisabled, NewNtpCollector)
} }
// NewNtpCollector returns a new Collector exposing sanity of local NTP server. // NewNtpCollector returns a new Collector exposing sanity of local NTP server.
@ -58,7 +58,7 @@ func init() {
func NewNtpCollector() (Collector, error) { func NewNtpCollector() (Collector, error) {
ipaddr := net.ParseIP(*ntpServer) ipaddr := net.ParseIP(*ntpServer)
if !*ntpServerIsLocal && (ipaddr == nil || !ipaddr.IsLoopback()) { if !*ntpServerIsLocal && (ipaddr == nil || !ipaddr.IsLoopback()) {
return nil, fmt.Errorf("only IP address of local NTP server is valid for -collector.ntp.server") return nil, fmt.Errorf("only IP address of local NTP server is valid for --collector.ntp.server")
} }
if *ntpProtocolVersion < 2 || *ntpProtocolVersion > 4 { if *ntpProtocolVersion < 2 || *ntpProtocolVersion > 4 {
@ -71,42 +71,42 @@ func NewNtpCollector() (Collector, error) {
return &ntpCollector{ return &ntpCollector{
stratum: typedDesc{prometheus.NewDesc( stratum: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "stratum"), prometheus.BuildFQName(namespace, ntpSubsystem, "stratum"),
"NTPD stratum.", "NTPD stratum.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
leap: typedDesc{prometheus.NewDesc( leap: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "leap"), prometheus.BuildFQName(namespace, ntpSubsystem, "leap"),
"NTPD leap second indicator, 2 bits.", "NTPD leap second indicator, 2 bits.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
rtt: typedDesc{prometheus.NewDesc( rtt: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "rtt_seconds"), prometheus.BuildFQName(namespace, ntpSubsystem, "rtt_seconds"),
"RTT to NTPD.", "RTT to NTPD.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
offset: typedDesc{prometheus.NewDesc( offset: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "offset_seconds"), prometheus.BuildFQName(namespace, ntpSubsystem, "offset_seconds"),
"ClockOffset between NTP and local clock.", "ClockOffset between NTP and local clock.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
reftime: typedDesc{prometheus.NewDesc( reftime: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "reference_timestamp_seconds"), prometheus.BuildFQName(namespace, ntpSubsystem, "reference_timestamp_seconds"),
"NTPD ReferenceTime, UNIX timestamp.", "NTPD ReferenceTime, UNIX timestamp.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
rootDelay: typedDesc{prometheus.NewDesc( rootDelay: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "root_delay_seconds"), prometheus.BuildFQName(namespace, ntpSubsystem, "root_delay_seconds"),
"NTPD RootDelay.", "NTPD RootDelay.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
rootDispersion: typedDesc{prometheus.NewDesc( rootDispersion: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "root_dispersion_seconds"), prometheus.BuildFQName(namespace, ntpSubsystem, "root_dispersion_seconds"),
"NTPD RootDispersion.", "NTPD RootDispersion.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
sanity: typedDesc{prometheus.NewDesc( sanity: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "sanity"), prometheus.BuildFQName(namespace, ntpSubsystem, "sanity"),
"NTPD sanity according to RFC5905 heuristics and configured limits.", "NTPD sanity according to RFC5905 heuristics and configured limits.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},

View file

@ -22,8 +22,8 @@ import (
var ( var (
// The path of the proc filesystem. // The path of the proc filesystem.
procPath = kingpin.Flag("collector.procfs", "procfs mountpoint.").Default(procfs.DefaultMountPoint).String() procPath = kingpin.Flag("path.procfs", "procfs mountpoint.").Default(procfs.DefaultMountPoint).String()
sysPath = kingpin.Flag("collector.sysfs", "sysfs mountpoint.").Default("/sys").String() sysPath = kingpin.Flag("path.sysfs", "sysfs mountpoint.").Default("/sys").String()
) )
func procFilePath(name string) string { func procFilePath(name string) string {

View file

@ -21,7 +21,7 @@ import (
) )
func TestDefaultProcPath(t *testing.T) { func TestDefaultProcPath(t *testing.T) {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", procfs.DefaultMountPoint}); err != nil { if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", procfs.DefaultMountPoint}); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -35,7 +35,7 @@ func TestDefaultProcPath(t *testing.T) {
} }
func TestCustomProcPath(t *testing.T) { func TestCustomProcPath(t *testing.T) {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", "./../some/./place/"}); err != nil { if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "./../some/./place/"}); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -49,7 +49,7 @@ func TestCustomProcPath(t *testing.T) {
} }
func TestDefaultSysPath(t *testing.T) { func TestDefaultSysPath(t *testing.T) {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.sysfs", "/sys"}); err != nil { if _, err := kingpin.CommandLine.Parse([]string{"--path.sysfs", "/sys"}); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -63,7 +63,7 @@ func TestDefaultSysPath(t *testing.T) {
} }
func TestCustomSysPath(t *testing.T) { func TestCustomSysPath(t *testing.T) {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.sysfs", "./../some/./place/"}); err != nil { if _, err := kingpin.CommandLine.Parse([]string{"--path.sysfs", "./../some/./place/"}); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -34,37 +34,37 @@ type qdiscStatCollector struct {
} }
var ( var (
collectorQdisc = kingpin.Flag("collector.qdisc", "test fixtures to use for qdisc collector end-to-end testing").Default("").String() collectorQdisc = kingpin.Flag("collector.qdisc.fixtures", "test fixtures to use for qdisc collector end-to-end testing").Default("").String()
) )
func init() { func init() {
Factories["qdisc"] = NewQdiscStatCollector registerCollector("qdisc", defaultDisabled, NewQdiscStatCollector)
} }
func NewQdiscStatCollector() (Collector, error) { func NewQdiscStatCollector() (Collector, error) {
return &qdiscStatCollector{ return &qdiscStatCollector{
bytes: typedDesc{prometheus.NewDesc( bytes: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "qdisc", "bytes_total"), prometheus.BuildFQName(namespace, "qdisc", "bytes_total"),
"Number of bytes sent.", "Number of bytes sent.",
[]string{"device", "kind"}, nil, []string{"device", "kind"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
packets: typedDesc{prometheus.NewDesc( packets: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "qdisc", "packets_total"), prometheus.BuildFQName(namespace, "qdisc", "packets_total"),
"Number of packets sent.", "Number of packets sent.",
[]string{"device", "kind"}, nil, []string{"device", "kind"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
drops: typedDesc{prometheus.NewDesc( drops: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "qdisc", "drops_total"), prometheus.BuildFQName(namespace, "qdisc", "drops_total"),
"Number of packets dropped.", "Number of packets dropped.",
[]string{"device", "kind"}, nil, []string{"device", "kind"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
requeues: typedDesc{prometheus.NewDesc( requeues: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "qdisc", "requeues_total"), prometheus.BuildFQName(namespace, "qdisc", "requeues_total"),
"Number of packets dequeued, not transmitted, and requeued.", "Number of packets dequeued, not transmitted, and requeued.",
[]string{"device", "kind"}, nil, []string{"device", "kind"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
overlimits: typedDesc{prometheus.NewDesc( overlimits: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "qdisc", "overlimits_total"), prometheus.BuildFQName(namespace, "qdisc", "overlimits_total"),
"Number of overlimit packets.", "Number of overlimit packets.",
[]string{"device", "kind"}, nil, []string{"device", "kind"}, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},

View file

@ -29,7 +29,7 @@ type runitCollector struct {
} }
func init() { func init() {
Factories["runit"] = NewRunitCollector registerCollector("runit", defaultDisabled, NewRunitCollector)
} }
// NewRunitCollector returns a new Collector exposing runit statistics. // NewRunitCollector returns a new Collector exposing runit statistics.
@ -42,22 +42,22 @@ func NewRunitCollector() (Collector, error) {
return &runitCollector{ return &runitCollector{
state: typedDesc{prometheus.NewDesc( state: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "state"), prometheus.BuildFQName(namespace, subsystem, "state"),
"State of runit service.", "State of runit service.",
labelNames, constLabels, labelNames, constLabels,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
stateDesired: typedDesc{prometheus.NewDesc( stateDesired: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "desired_state"), prometheus.BuildFQName(namespace, subsystem, "desired_state"),
"Desired state of runit service.", "Desired state of runit service.",
labelNames, constLabels, labelNames, constLabels,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
stateNormal: typedDesc{prometheus.NewDesc( stateNormal: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "normal_state"), prometheus.BuildFQName(namespace, subsystem, "normal_state"),
"Normal state of runit service.", "Normal state of runit service.",
labelNames, constLabels, labelNames, constLabels,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
stateTimestamp: typedDesc{prometheus.NewDesc( stateTimestamp: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "state_last_change_timestamp_seconds"), prometheus.BuildFQName(namespace, subsystem, "state_last_change_timestamp_seconds"),
"Unix timestamp of the last runit service state change.", "Unix timestamp of the last runit service state change.",
labelNames, constLabels, labelNames, constLabels,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},

View file

@ -36,7 +36,7 @@ var pageSize = os.Getpagesize()
type sockStatCollector struct{} type sockStatCollector struct{}
func init() { func init() {
Factories[sockStatSubsystem] = NewSockStatCollector registerCollector(sockStatSubsystem, defaultEnabled, NewSockStatCollector)
} }
// NewSockStatCollector returns a new Collector exposing socket stats. // NewSockStatCollector returns a new Collector exposing socket stats.
@ -57,7 +57,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error {
} }
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc( prometheus.NewDesc(
prometheus.BuildFQName(Namespace, sockStatSubsystem, protocol+"_"+name), prometheus.BuildFQName(namespace, sockStatSubsystem, protocol+"_"+name),
fmt.Sprintf("Number of %s sockets in state %s.", protocol, name), fmt.Sprintf("Number of %s sockets in state %s.", protocol, name),
nil, nil, nil, nil,
), ),

View file

@ -34,44 +34,44 @@ type statCollector struct {
} }
func init() { func init() {
Factories["stat"] = NewStatCollector registerCollector("stat", defaultEnabled, NewStatCollector)
} }
// NewStatCollector returns a new Collector exposing kernel/system statistics. // NewStatCollector returns a new Collector exposing kernel/system statistics.
func NewStatCollector() (Collector, error) { func NewStatCollector() (Collector, error) {
return &statCollector{ return &statCollector{
cpu: prometheus.NewDesc( cpu: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "cpu"), prometheus.BuildFQName(namespace, "", "cpu"),
"Seconds the cpus spent in each mode.", "Seconds the cpus spent in each mode.",
[]string{"cpu", "mode"}, nil, []string{"cpu", "mode"}, nil,
), ),
intr: prometheus.NewDesc( intr: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "intr"), prometheus.BuildFQName(namespace, "", "intr"),
"Total number of interrupts serviced.", "Total number of interrupts serviced.",
nil, nil, nil, nil,
), ),
ctxt: prometheus.NewDesc( ctxt: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "context_switches"), prometheus.BuildFQName(namespace, "", "context_switches"),
"Total number of context switches.", "Total number of context switches.",
nil, nil, nil, nil,
), ),
forks: prometheus.NewDesc( forks: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "forks"), prometheus.BuildFQName(namespace, "", "forks"),
"Total number of forks.", "Total number of forks.",
nil, nil, nil, nil,
), ),
btime: prometheus.NewDesc( btime: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "boot_time"), prometheus.BuildFQName(namespace, "", "boot_time"),
"Node boot time, in unixtime.", "Node boot time, in unixtime.",
nil, nil, nil, nil,
), ),
procsRunning: prometheus.NewDesc( procsRunning: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "procs_running"), prometheus.BuildFQName(namespace, "", "procs_running"),
"Number of processes in runnable state.", "Number of processes in runnable state.",
nil, nil, nil, nil,
), ),
procsBlocked: prometheus.NewDesc( procsBlocked: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "procs_blocked"), prometheus.BuildFQName(namespace, "", "procs_blocked"),
"Number of processes blocked waiting for I/O to complete.", "Number of processes blocked waiting for I/O to complete.",
nil, nil, nil, nil,
), ),

View file

@ -35,7 +35,7 @@ type supervisordCollector struct {
} }
func init() { func init() {
Factories["supervisord"] = NewSupervisordCollector registerCollector("supervisord", defaultDisabled, NewSupervisordCollector)
} }
// NewSupervisordCollector returns a new Collector exposing supervisord statistics. // NewSupervisordCollector returns a new Collector exposing supervisord statistics.
@ -52,25 +52,25 @@ func NewSupervisordCollector() (Collector, error) {
return &supervisordCollector{ return &supervisordCollector{
client: client, client: client,
upDesc: prometheus.NewDesc( upDesc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "up"), prometheus.BuildFQName(namespace, subsystem, "up"),
"Process Up", "Process Up",
labelNames, labelNames,
nil, nil,
), ),
stateDesc: prometheus.NewDesc( stateDesc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "state"), prometheus.BuildFQName(namespace, subsystem, "state"),
"Process State", "Process State",
labelNames, labelNames,
nil, nil,
), ),
exitStatusDesc: prometheus.NewDesc( exitStatusDesc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "exit_status"), prometheus.BuildFQName(namespace, subsystem, "exit_status"),
"Process Exit Status", "Process Exit Status",
labelNames, labelNames,
nil, nil,
), ),
uptimeDesc: prometheus.NewDesc( uptimeDesc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "uptime"), prometheus.BuildFQName(namespace, subsystem, "uptime"),
"Process Uptime", "Process Uptime",
labelNames, labelNames,
nil, nil,

View file

@ -41,7 +41,7 @@ type systemdCollector struct {
var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"} var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"}
func init() { func init() {
Factories["systemd"] = NewSystemdCollector registerCollector("systemd", defaultDisabled, NewSystemdCollector)
} }
// NewSystemdCollector returns a new Collector exposing systemd statistics. // NewSystemdCollector returns a new Collector exposing systemd statistics.
@ -49,11 +49,11 @@ func NewSystemdCollector() (Collector, error) {
const subsystem = "systemd" const subsystem = "systemd"
unitDesc := prometheus.NewDesc( unitDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "unit_state"), prometheus.BuildFQName(namespace, subsystem, "unit_state"),
"Systemd unit", []string{"name", "state"}, nil, "Systemd unit", []string{"name", "state"}, nil,
) )
systemRunningDesc := prometheus.NewDesc( systemRunningDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "system_running"), prometheus.BuildFQName(namespace, subsystem, "system_running"),
"Whether the system is operational (see 'systemctl is-system-running')", "Whether the system is operational (see 'systemctl is-system-running')",
nil, nil, nil, nil,
) )

View file

@ -58,14 +58,14 @@ type tcpStatCollector struct {
} }
func init() { func init() {
Factories["tcpstat"] = NewTCPStatCollector registerCollector("tcpstat", defaultDisabled, NewTCPStatCollector)
} }
// NewTCPStatCollector returns a new Collector exposing network stats. // NewTCPStatCollector returns a new Collector exposing network stats.
func NewTCPStatCollector() (Collector, error) { func NewTCPStatCollector() (Collector, error) {
return &tcpStatCollector{ return &tcpStatCollector{
desc: typedDesc{prometheus.NewDesc( desc: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "tcp", "connection_states"), prometheus.BuildFQName(namespace, "tcp", "connection_states"),
"Number of connection states.", "Number of connection states.",
[]string{"state"}, nil, []string{"state"}, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},

View file

@ -41,7 +41,7 @@ type textFileCollector struct {
} }
func init() { func init() {
Factories["textfile"] = NewTextFileCollector registerCollector("textfile", defaultEnabled, NewTextFileCollector)
} }
// NewTextFileCollector returns a new Collector exposing metrics read from files // NewTextFileCollector returns a new Collector exposing metrics read from files

View file

@ -27,7 +27,7 @@ type timeCollector struct {
} }
func init() { func init() {
Factories["time"] = NewTimeCollector registerCollector("time", defaultEnabled, NewTimeCollector)
} }
// NewTimeCollector returns a new Collector exposing the current system time in // NewTimeCollector returns a new Collector exposing the current system time in
@ -35,7 +35,7 @@ func init() {
func NewTimeCollector() (Collector, error) { func NewTimeCollector() (Collector, error) {
return &timeCollector{ return &timeCollector{
desc: prometheus.NewDesc( desc: prometheus.NewDesc(
Namespace+"_time", namespace+"_time",
"System time in seconds since epoch (1970).", "System time in seconds since epoch (1970).",
nil, nil, nil, nil,
), ),

View file

@ -28,9 +28,9 @@ import (
const ( const (
// The system clock is not synchronized to a reliable server. // The system clock is not synchronized to a reliable server.
timeError = C.TIME_ERROR timeError = C.TIME_ERROR
// The timex.Status time resolution bit, 0 = microsecond, 1 = nanoseconds. // The timex.Status time resolution bit, 0 = microsecond, 1 = nanoseconds.
staNano = C.STA_NANO staNano = C.STA_NANO
// 1 second in // 1 second in
nanoSeconds = 1000000000 nanoSeconds = 1000000000
microSeconds = 1000000 microSeconds = 1000000
@ -57,7 +57,7 @@ type timexCollector struct {
} }
func init() { func init() {
Factories["timex"] = NewTimexCollector registerCollector("timex", defaultEnabled, NewTimexCollector)
} }
// NewTimexCollector returns a new Collector exposing adjtime(3) stats. // NewTimexCollector returns a new Collector exposing adjtime(3) stats.
@ -66,87 +66,87 @@ func NewTimexCollector() (Collector, error) {
return &timexCollector{ return &timexCollector{
offset: typedDesc{prometheus.NewDesc( offset: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "offset_seconds"), prometheus.BuildFQName(namespace, subsystem, "offset_seconds"),
"Time offset in between local system and reference clock.", "Time offset in between local system and reference clock.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
freq: typedDesc{prometheus.NewDesc( freq: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "frequency_adjustment"), prometheus.BuildFQName(namespace, subsystem, "frequency_adjustment"),
"Local clock frequency adjustment.", "Local clock frequency adjustment.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
maxerror: typedDesc{prometheus.NewDesc( maxerror: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "maxerror_seconds"), prometheus.BuildFQName(namespace, subsystem, "maxerror_seconds"),
"Maximum error in seconds.", "Maximum error in seconds.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
esterror: typedDesc{prometheus.NewDesc( esterror: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "estimated_error_seconds"), prometheus.BuildFQName(namespace, subsystem, "estimated_error_seconds"),
"Estimated error in seconds.", "Estimated error in seconds.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
status: typedDesc{prometheus.NewDesc( status: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "status"), prometheus.BuildFQName(namespace, subsystem, "status"),
"Value of the status array bits.", "Value of the status array bits.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
constant: typedDesc{prometheus.NewDesc( constant: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "loop_time_constant"), prometheus.BuildFQName(namespace, subsystem, "loop_time_constant"),
"Phase-locked loop time constant.", "Phase-locked loop time constant.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
tick: typedDesc{prometheus.NewDesc( tick: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "tick_seconds"), prometheus.BuildFQName(namespace, subsystem, "tick_seconds"),
"Seconds between clock ticks.", "Seconds between clock ticks.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
ppsfreq: typedDesc{prometheus.NewDesc( ppsfreq: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pps_frequency"), prometheus.BuildFQName(namespace, subsystem, "pps_frequency"),
"Pulse per second frequency.", "Pulse per second frequency.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
jitter: typedDesc{prometheus.NewDesc( jitter: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pps_jitter_seconds"), prometheus.BuildFQName(namespace, subsystem, "pps_jitter_seconds"),
"Pulse per second jitter.", "Pulse per second jitter.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
shift: typedDesc{prometheus.NewDesc( shift: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pps_shift_seconds"), prometheus.BuildFQName(namespace, subsystem, "pps_shift_seconds"),
"Pulse per second interval duration.", "Pulse per second interval duration.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
stabil: typedDesc{prometheus.NewDesc( stabil: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pps_stability"), prometheus.BuildFQName(namespace, subsystem, "pps_stability"),
"Pulse per second stability.", "Pulse per second stability.",
nil, nil, nil, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
jitcnt: typedDesc{prometheus.NewDesc( jitcnt: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pps_jitter_count"), prometheus.BuildFQName(namespace, subsystem, "pps_jitter_count"),
"Pulse per second count of jitter limit exceeded events.", "Pulse per second count of jitter limit exceeded events.",
nil, nil, nil, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
calcnt: typedDesc{prometheus.NewDesc( calcnt: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pps_calibration_count"), prometheus.BuildFQName(namespace, subsystem, "pps_calibration_count"),
"Pulse per second count of calibration intervals.", "Pulse per second count of calibration intervals.",
nil, nil, nil, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
errcnt: typedDesc{prometheus.NewDesc( errcnt: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pps_error_count"), prometheus.BuildFQName(namespace, subsystem, "pps_error_count"),
"Pulse per second count of calibration errors.", "Pulse per second count of calibration errors.",
nil, nil, nil, nil,
), prometheus.CounterValue}, ), prometheus.CounterValue},
stbcnt: typedDesc{prometheus.NewDesc( stbcnt: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pps_stability_exceeded_count"), prometheus.BuildFQName(namespace, subsystem, "pps_stability_exceeded_count"),
"Pulse per second count of stability limit exceeded events.", "Pulse per second count of stability limit exceeded events.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
tai: typedDesc{prometheus.NewDesc( tai: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "tai_offset"), prometheus.BuildFQName(namespace, subsystem, "tai_offset"),
"International Atomic Time (TAI) offset.", "International Atomic Time (TAI) offset.",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},
syncStatus: typedDesc{prometheus.NewDesc( syncStatus: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "sync_status"), prometheus.BuildFQName(namespace, subsystem, "sync_status"),
"Is clock synchronized to a reliable server (1 = yes, 0 = no).", "Is clock synchronized to a reliable server (1 = yes, 0 = no).",
nil, nil, nil, nil,
), prometheus.GaugeValue}, ), prometheus.GaugeValue},

View file

@ -22,7 +22,7 @@ import (
) )
var unameDesc = prometheus.NewDesc( var unameDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "uname", "info"), prometheus.BuildFQName(namespace, "uname", "info"),
"Labeled system information as provided by the uname system call.", "Labeled system information as provided by the uname system call.",
[]string{ []string{
"sysname", "sysname",
@ -38,7 +38,7 @@ var unameDesc = prometheus.NewDesc(
type unameCollector struct{} type unameCollector struct{}
func init() { func init() {
Factories["uname"] = newUnameCollector registerCollector("uname", defaultEnabled, newUnameCollector)
} }
// NewUnameCollector returns new unameCollector. // NewUnameCollector returns new unameCollector.

View file

@ -32,7 +32,7 @@ const (
type vmStatCollector struct{} type vmStatCollector struct{}
func init() { func init() {
Factories["vmstat"] = NewvmStatCollector registerCollector("vmstat", defaultEnabled, NewvmStatCollector)
} }
// NewvmStatCollector returns a new Collector exposing vmstat stats. // NewvmStatCollector returns a new Collector exposing vmstat stats.
@ -57,7 +57,7 @@ func (c *vmStatCollector) Update(ch chan<- prometheus.Metric) error {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc( prometheus.NewDesc(
prometheus.BuildFQName(Namespace, vmStatSubsystem, parts[0]), prometheus.BuildFQName(namespace, vmStatSubsystem, parts[0]),
fmt.Sprintf("/proc/vmstat information field %s.", parts[0]), fmt.Sprintf("/proc/vmstat information field %s.", parts[0]),
nil, nil), nil, nil),
prometheus.UntypedValue, prometheus.UntypedValue,

View file

@ -41,11 +41,11 @@ type wifiCollector struct {
} }
var ( var (
collectorWifi = kingpin.Flag("collector.wifi", "test fixtures to use for wifi collector metrics").Default("").String() collectorWifi = kingpin.Flag("collector.wifi.fixtures", "test fixtures to use for wifi collector metrics").Default("").String()
) )
func init() { func init() {
Factories["wifi"] = NewWifiCollector registerCollector("wifi", defaultEnabled, NewWifiCollector)
} }
var _ wifiStater = &wifi.Client{} var _ wifiStater = &wifi.Client{}
@ -70,70 +70,70 @@ func NewWifiCollector() (Collector, error) {
return &wifiCollector{ return &wifiCollector{
interfaceFrequencyHertz: prometheus.NewDesc( interfaceFrequencyHertz: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "interface_frequency_hertz"), prometheus.BuildFQName(namespace, subsystem, "interface_frequency_hertz"),
"The current frequency a WiFi interface is operating at, in hertz.", "The current frequency a WiFi interface is operating at, in hertz.",
labels, labels,
nil, nil,
), ),
stationInfo: prometheus.NewDesc( stationInfo: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "station_info"), prometheus.BuildFQName(namespace, subsystem, "station_info"),
"Labeled WiFi interface station information as provided by the operating system.", "Labeled WiFi interface station information as provided by the operating system.",
[]string{"device", "bssid", "ssid", "mode"}, []string{"device", "bssid", "ssid", "mode"},
nil, nil,
), ),
stationConnectedSecondsTotal: prometheus.NewDesc( stationConnectedSecondsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "station_connected_seconds_total"), prometheus.BuildFQName(namespace, subsystem, "station_connected_seconds_total"),
"The total number of seconds a station has been connected to an access point.", "The total number of seconds a station has been connected to an access point.",
labels, labels,
nil, nil,
), ),
stationInactiveSeconds: prometheus.NewDesc( stationInactiveSeconds: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "station_inactive_seconds"), prometheus.BuildFQName(namespace, subsystem, "station_inactive_seconds"),
"The number of seconds since any wireless activity has occurred on a station.", "The number of seconds since any wireless activity has occurred on a station.",
labels, labels,
nil, nil,
), ),
stationReceiveBitsPerSecond: prometheus.NewDesc( stationReceiveBitsPerSecond: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "station_receive_bits_per_second"), prometheus.BuildFQName(namespace, subsystem, "station_receive_bits_per_second"),
"The current WiFi receive bitrate of a station, in bits per second.", "The current WiFi receive bitrate of a station, in bits per second.",
labels, labels,
nil, nil,
), ),
stationTransmitBitsPerSecond: prometheus.NewDesc( stationTransmitBitsPerSecond: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "station_transmit_bits_per_second"), prometheus.BuildFQName(namespace, subsystem, "station_transmit_bits_per_second"),
"The current WiFi transmit bitrate of a station, in bits per second.", "The current WiFi transmit bitrate of a station, in bits per second.",
labels, labels,
nil, nil,
), ),
stationSignalDBM: prometheus.NewDesc( stationSignalDBM: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "station_signal_dbm"), prometheus.BuildFQName(namespace, subsystem, "station_signal_dbm"),
"The current WiFi signal strength, in decibel-milliwatts (dBm).", "The current WiFi signal strength, in decibel-milliwatts (dBm).",
labels, labels,
nil, nil,
), ),
stationTransmitRetriesTotal: prometheus.NewDesc( stationTransmitRetriesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "station_transmit_retries_total"), prometheus.BuildFQName(namespace, subsystem, "station_transmit_retries_total"),
"The total number of times a station has had to retry while sending a packet.", "The total number of times a station has had to retry while sending a packet.",
labels, labels,
nil, nil,
), ),
stationTransmitFailedTotal: prometheus.NewDesc( stationTransmitFailedTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "station_transmit_failed_total"), prometheus.BuildFQName(namespace, subsystem, "station_transmit_failed_total"),
"The total number of times a station has failed to send a packet.", "The total number of times a station has failed to send a packet.",
labels, labels,
nil, nil,
), ),
stationBeaconLossTotal: prometheus.NewDesc( stationBeaconLossTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "station_beacon_loss_total"), prometheus.BuildFQName(namespace, subsystem, "station_beacon_loss_total"),
"The total number of times a station has detected a beacon loss.", "The total number of times a station has detected a beacon loss.",
labels, labels,
nil, nil,

View file

@ -27,7 +27,7 @@ type xfsCollector struct {
} }
func init() { func init() {
Factories["xfs"] = NewXFSCollector registerCollector("xfs", defaultEnabled, NewXFSCollector)
} }
// NewXFSCollector returns a new Collector exposing XFS statistics. // NewXFSCollector returns a new Collector exposing XFS statistics.
@ -179,7 +179,7 @@ func (c *xfsCollector) updateXFSStats(ch chan<- prometheus.Metric, s *xfs.Stats)
for _, m := range metrics { for _, m := range metrics {
desc := prometheus.NewDesc( desc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, m.name), prometheus.BuildFQName(namespace, subsystem, m.name),
m.desc, m.desc,
labels, labels,
nil, nil,

View file

@ -29,7 +29,7 @@ var errZFSNotAvailable = errors.New("ZFS / ZFS statistics are not available")
type zfsSysctl string type zfsSysctl string
func init() { func init() {
Factories["zfs"] = NewZFSCollector registerCollector("zfs", defaultEnabled, NewZFSCollector)
} }
type zfsCollector struct { type zfsCollector struct {
@ -80,7 +80,7 @@ func (c *zfsCollector) constSysctlMetric(subsystem string, sysctl zfsSysctl, val
return prometheus.MustNewConstMetric( return prometheus.MustNewConstMetric(
prometheus.NewDesc( prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, metricName), prometheus.BuildFQName(namespace, subsystem, metricName),
string(sysctl), string(sysctl),
nil, nil,
nil, nil,
@ -95,7 +95,7 @@ func (c *zfsCollector) constPoolMetric(poolName string, sysctl zfsSysctl, value
return prometheus.MustNewConstMetric( return prometheus.MustNewConstMetric(
prometheus.NewDesc( prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "zfs_zpool", metricName), prometheus.BuildFQName(namespace, "zfs_zpool", metricName),
string(sysctl), string(sysctl),
[]string{"zpool"}, []string{"zpool"},
nil, nil,

View file

@ -2,7 +2,7 @@
set -euf -o pipefail set -euf -o pipefail
collectors=$(cat << COLLECTORS enabled_collectors=$(cat << COLLECTORS
arp arp
bcache bcache
buddyinfo buddyinfo
@ -36,6 +36,14 @@ collectors=$(cat << COLLECTORS
zfs zfs
COLLECTORS COLLECTORS
) )
disabled_collectors=$(cat << COLLECTORS
filesystem
time
timex
uname
vmstat
COLLECTORS
)
cd "$(dirname $0)" cd "$(dirname $0)"
port="$((10000 + (RANDOM % 10000)))" port="$((10000 + (RANDOM % 10000)))"
@ -74,13 +82,14 @@ then
fi fi
./node_exporter \ ./node_exporter \
--collector.procfs="collector/fixtures/proc" \ --path.procfs="collector/fixtures/proc" \
--collector.sysfs="collector/fixtures/sys" \ --path.sysfs="collector/fixtures/sys" \
--collectors.enabled="$(echo ${collectors} | tr ' ' ',')" \ $(for c in ${enabled_collectors}; do echo --collector.${c} ; done) \
$(for c in ${disabled_collectors}; do echo --no-collector.${c} ; done) \
--collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \ --collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \
--collector.megacli.command="collector/fixtures/megacli" \ --collector.megacli.command="collector/fixtures/megacli" \
--collector.wifi="collector/fixtures/wifi" \ --collector.wifi.fixtures="collector/fixtures/wifi" \
--collector.qdisc="collector/fixtures/qdisc/" \ --collector.qdisc.fixtures="collector/fixtures/qdisc/" \
--web.listen-address "127.0.0.1:${port}" \ --web.listen-address "127.0.0.1:${port}" \
--log.level="debug" > "${tmpdir}/node_exporter.log" 2>&1 & --log.level="debug" > "${tmpdir}/node_exporter.log" 2>&1 &

View file

@ -14,13 +14,8 @@
package main package main
import ( import (
"fmt"
"net/http" "net/http"
_ "net/http/pprof" _ "net/http/pprof"
"sort"
"strings"
"sync"
"time"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
@ -30,103 +25,14 @@ import (
"gopkg.in/alecthomas/kingpin.v2" "gopkg.in/alecthomas/kingpin.v2"
) )
const (
defaultCollectors = "arp,bcache,conntrack,cpu,diskstats,entropy,edac,exec,filefd,filesystem,hwmon,infiniband,ipvs,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,timex,uname,vmstat,wifi,xfs,zfs"
)
var (
scrapeDurationDesc = prometheus.NewDesc(
prometheus.BuildFQName(collector.Namespace, "scrape", "collector_duration_seconds"),
"node_exporter: Duration of a collector scrape.",
[]string{"collector"},
nil,
)
scrapeSuccessDesc = prometheus.NewDesc(
prometheus.BuildFQName(collector.Namespace, "scrape", "collector_success"),
"node_exporter: Whether a collector succeeded.",
[]string{"collector"},
nil,
)
)
// NodeCollector implements the prometheus.Collector interface.
type NodeCollector struct {
collectors map[string]collector.Collector
}
// Describe implements the prometheus.Collector interface.
func (n NodeCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- scrapeDurationDesc
ch <- scrapeSuccessDesc
}
// Collect implements the prometheus.Collector interface.
func (n NodeCollector) Collect(ch chan<- prometheus.Metric) {
wg := sync.WaitGroup{}
wg.Add(len(n.collectors))
for name, c := range n.collectors {
go func(name string, c collector.Collector) {
execute(name, c, ch)
wg.Done()
}(name, c)
}
wg.Wait()
}
func filterAvailableCollectors(collectors string) string {
var availableCollectors []string
for _, c := range strings.Split(collectors, ",") {
_, ok := collector.Factories[c]
if ok {
availableCollectors = append(availableCollectors, c)
}
}
return strings.Join(availableCollectors, ",")
}
func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
begin := time.Now()
err := c.Update(ch)
duration := time.Since(begin)
var success float64
if err != nil {
log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err)
success = 0
} else {
log.Debugf("OK: %s collector succeeded after %fs.", name, duration.Seconds())
success = 1
}
ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name)
ch <- prometheus.MustNewConstMetric(scrapeSuccessDesc, prometheus.GaugeValue, success, name)
}
func loadCollectors(list string) (map[string]collector.Collector, error) {
collectors := map[string]collector.Collector{}
for _, name := range strings.Split(list, ",") {
fn, ok := collector.Factories[name]
if !ok {
return nil, fmt.Errorf("collector '%s' not available", name)
}
c, err := fn()
if err != nil {
return nil, err
}
collectors[name] = c
}
return collectors, nil
}
func init() { func init() {
prometheus.MustRegister(version.NewCollector("node_exporter")) prometheus.MustRegister(version.NewCollector("node_exporter"))
} }
func main() { func main() {
var ( var (
listenAddress = kingpin.Flag("web.listen-address", "Address on which to expose metrics and web interface.").Default(":9100").String() listenAddress = kingpin.Flag("web.listen-address", "Address on which to expose metrics and web interface.").Default(":9100").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String() metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
enabledCollectors = kingpin.Flag("collectors.enabled", "Comma-separated list of collectors to use.").Default(filterAvailableCollectors(defaultCollectors)).String()
printCollectors = kingpin.Flag("collectors.print", "If true, print available collectors and exit.").Bool()
) )
log.AddFlags(kingpin.CommandLine) log.AddFlags(kingpin.CommandLine)
@ -137,29 +43,16 @@ func main() {
log.Infoln("Starting node_exporter", version.Info()) log.Infoln("Starting node_exporter", version.Info())
log.Infoln("Build context", version.BuildContext()) log.Infoln("Build context", version.BuildContext())
if *printCollectors { nc, err := collector.NewNodeCollector()
collectorNames := make(sort.StringSlice, 0, len(collector.Factories))
for n := range collector.Factories {
collectorNames = append(collectorNames, n)
}
collectorNames.Sort()
fmt.Printf("Available collectors:\n")
for _, n := range collectorNames {
fmt.Printf(" - %s\n", n)
}
return
}
collectors, err := loadCollectors(*enabledCollectors)
if err != nil { if err != nil {
log.Fatalf("Couldn't load collectors: %s", err) log.Fatalf("Couldn't create collector: %s", err)
} }
log.Infof("Enabled collectors:") log.Infof("Enabled collectors:")
for n := range collectors { for n := range nc.Collectors {
log.Infof(" - %s", n) log.Infof(" - %s", n)
} }
if err := prometheus.Register(NodeCollector{collectors: collectors}); err != nil { if err := prometheus.Register(nc); err != nil {
log.Fatalf("Couldn't register collector: %s", err) log.Fatalf("Couldn't register collector: %s", err)
} }
handler := promhttp.HandlerFor(prometheus.DefaultGatherer, handler := promhttp.HandlerFor(prometheus.DefaultGatherer,