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
commit 859a825bb8
58 changed files with 410 additions and 406 deletions

View file

@ -26,7 +26,7 @@ import (
)
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"
)
@ -48,7 +48,7 @@ type ntpCollector struct {
}
func init() {
Factories["ntp"] = NewNtpCollector
registerCollector("ntp", defaultDisabled, NewNtpCollector)
}
// NewNtpCollector returns a new Collector exposing sanity of local NTP server.
@ -58,7 +58,7 @@ func init() {
func NewNtpCollector() (Collector, error) {
ipaddr := net.ParseIP(*ntpServer)
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 {
@ -71,42 +71,42 @@ func NewNtpCollector() (Collector, error) {
return &ntpCollector{
stratum: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "stratum"),
prometheus.BuildFQName(namespace, ntpSubsystem, "stratum"),
"NTPD stratum.",
nil, nil,
), prometheus.GaugeValue},
leap: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "leap"),
prometheus.BuildFQName(namespace, ntpSubsystem, "leap"),
"NTPD leap second indicator, 2 bits.",
nil, nil,
), prometheus.GaugeValue},
rtt: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "rtt_seconds"),
prometheus.BuildFQName(namespace, ntpSubsystem, "rtt_seconds"),
"RTT to NTPD.",
nil, nil,
), prometheus.GaugeValue},
offset: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "offset_seconds"),
prometheus.BuildFQName(namespace, ntpSubsystem, "offset_seconds"),
"ClockOffset between NTP and local clock.",
nil, nil,
), prometheus.GaugeValue},
reftime: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "reference_timestamp_seconds"),
prometheus.BuildFQName(namespace, ntpSubsystem, "reference_timestamp_seconds"),
"NTPD ReferenceTime, UNIX timestamp.",
nil, nil,
), prometheus.GaugeValue},
rootDelay: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "root_delay_seconds"),
prometheus.BuildFQName(namespace, ntpSubsystem, "root_delay_seconds"),
"NTPD RootDelay.",
nil, nil,
), prometheus.GaugeValue},
rootDispersion: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "root_dispersion_seconds"),
prometheus.BuildFQName(namespace, ntpSubsystem, "root_dispersion_seconds"),
"NTPD RootDispersion.",
nil, nil,
), prometheus.GaugeValue},
sanity: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(Namespace, ntpSubsystem, "sanity"),
prometheus.BuildFQName(namespace, ntpSubsystem, "sanity"),
"NTPD sanity according to RFC5905 heuristics and configured limits.",
nil, nil,
), prometheus.GaugeValue},