diff --git a/README.md b/README.md index 594941b5..f9a17d96 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ netstat | Exposes network statistics from `/proc/net/netstat`. This is the same nfs | Exposes NFS client statistics from `/proc/net/rpc/nfs`. This is the same information as `nfsstat -c`. | Linux nfsd | Exposes NFS kernel server statistics from `/proc/net/rpc/nfsd`. This is the same information as `nfsstat -s`. | Linux nvme | Exposes NVMe info from `/sys/class/nvme/` | Linux -os | Expose OS release info from `/etc/os-release` or `/usr/lib/os-release` | _any_ +os | Expose OS release info from `uname` syscall and `/etc/os-release` or `/usr/lib/os-release` | _any_ powersupplyclass | Exposes Power Supply statistics from `/sys/class/power_supply` | Linux pressure | Exposes pressure stall statistics from `/proc/pressure/`. | Linux (kernel 4.20+ and/or [CONFIG\_PSI](https://www.kernel.org/doc/html/latest/accounting/psi.html)) rapl | Exposes various statistics from `/sys/class/powercap`. | Linux @@ -131,7 +131,7 @@ thermal\_zone | Exposes thermal zone & cooling device statistics from `/sys/clas time | Exposes the current system time. | _any_ timex | Exposes selected adjtimex(2) system call stats. | Linux udp_queues | Exposes UDP total lengths of the rx_queue and tx_queue from `/proc/net/udp` and `/proc/net/udp6`. | Linux -uname | Exposes system information as provided by the uname system call. | Darwin, FreeBSD, Linux, OpenBSD +uname | Deprecated, now part of the "os" collector | Darwin, FreeBSD, Linux, OpenBSD vmstat | Exposes statistics from `/proc/vmstat`. | Linux xfs | Exposes XFS runtime statistics. | Linux (kernel 4.4+) zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics. | [Linux](http://zfsonlinux.org/), Solaris diff --git a/collector/collector.go b/collector/collector.go index 54f0ff6d..12b5e312 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -75,6 +75,22 @@ func registerCollector(collector string, isDefaultEnabled bool, factory func(log factories[collector] = factory } +func registerCollectorAlias(collector string, isDefaultEnabled bool, alias string) { + 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) (alias for %s).", alias, helpDefaultState, collector) + defaultValue := fmt.Sprintf("%v", isDefaultEnabled) + + flag := kingpin.Flag(flagName, flagHelp).Default(defaultValue).Action(collectorFlagAction(alias)).Bool() + collectorState[collector] = flag +} + // NodeCollector implements the prometheus.Collector interface. type NodeCollector struct { Collectors map[string]Collector diff --git a/collector/os_release.go b/collector/os.go similarity index 99% rename from collector/os_release.go rename to collector/os.go index cda1eb1f..b06ff6cb 100644 --- a/collector/os_release.go +++ b/collector/os.go @@ -11,6 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !noos +// +build !noos + package collector import ( diff --git a/collector/os_release_test.go b/collector/os_test.go similarity index 98% rename from collector/os_release_test.go rename to collector/os_test.go index e37cc34c..523d4b21 100644 --- a/collector/os_release_test.go +++ b/collector/os_test.go @@ -11,6 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !noos +// +build !noos + package collector import ( diff --git a/collector/uname.go b/collector/uname.go index 14cfefb3..f42cfe06 100644 --- a/collector/uname.go +++ b/collector/uname.go @@ -11,9 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (darwin || freebsd || openbsd || linux) && !nouname +//go:build (darwin || freebsd || openbsd || linux) && !noos // +build darwin freebsd openbsd linux -// +build !nouname +// +build !noos package collector @@ -49,7 +49,7 @@ type uname struct { } func init() { - registerCollector("uname", defaultEnabled, newUnameCollector) + registerCollectorAlias("uname", defaultEnabled, "os") } // NewUnameCollector returns new unameCollector. diff --git a/collector/uname_bsd.go b/collector/uname_bsd.go index 77d47877..a7681bbe 100644 --- a/collector/uname_bsd.go +++ b/collector/uname_bsd.go @@ -11,9 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (darwin || freebsd || openbsd) && !nouname +//go:build (darwin || freebsd || openbsd) && !noos // +build darwin freebsd openbsd -// +build !nouname +// +build !noos package collector diff --git a/collector/uname_linux.go b/collector/uname_linux.go index 549c221a..323f36b6 100644 --- a/collector/uname_linux.go +++ b/collector/uname_linux.go @@ -11,8 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !nouname -// +build !nouname +//go:build !noos +// +build !noos package collector