Merge uname and os collectors

Merge the `uname` collector into the `os` collector.
* Add an aliasing function to make flags for deprecated collector names.
* Alias `uname` to `os` collctor.

Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
Ben Kochie 2021-10-14 11:53:50 +02:00
parent df7ea981f7
commit 6dd7fa55bf
No known key found for this signature in database
GPG Key ID: C646B23C9E3245F1
7 changed files with 31 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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 (

View File

@ -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 (

View File

@ -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.

View File

@ -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

View File

@ -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