From 6ad94ae4bc5527037ce0e6b8462f58cb3b8ccef3 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 18 Feb 2020 14:14:35 +0100 Subject: [PATCH] Implement loadavg on all BSDs without cgo (#1584) Reuse the Go-only implementation already in place for FreeBSD (#385) on Darwin, DragonflyBSD, NetBSD and OpenBSD. Tested on all affected platforms. Signed-off-by: Tobias Klauser --- .../{loadavg_freebsd.go => loadavg_bsd.go} | 1 + collector/loadavg_unix.go | 33 ------------------- 2 files changed, 1 insertion(+), 33 deletions(-) rename collector/{loadavg_freebsd.go => loadavg_bsd.go} (95%) delete mode 100644 collector/loadavg_unix.go diff --git a/collector/loadavg_freebsd.go b/collector/loadavg_bsd.go similarity index 95% rename from collector/loadavg_freebsd.go rename to collector/loadavg_bsd.go index e919c50e..38215aab 100644 --- a/collector/loadavg_freebsd.go +++ b/collector/loadavg_bsd.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// +build darwin dragonfly freebsd netbsd openbsd // +build !noloadavg package collector diff --git a/collector/loadavg_unix.go b/collector/loadavg_unix.go deleted file mode 100644 index 4d658852..00000000 --- a/collector/loadavg_unix.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2015 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build darwin dragonfly netbsd openbsd -// +build !noloadavg - -package collector - -import ( - "errors" -) - -// #include -import "C" - -func getLoad() ([]float64, error) { - var loadavg [3]C.double - samples := C.getloadavg(&loadavg[0], 3) - if samples != 3 { - return nil, errors.New("failed to get load average") - } - return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil -}