From cded1805c1be4d25dfd274999cd96eee64ae1d28 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Wed, 20 Mar 2024 21:42:44 -0400 Subject: [PATCH] Total Processes in `MiscStat` Corrected The `ProcsTotal` in the `MiscStat` structure was very inaccurate. It was reading a value which is the total number of kernel scheduling entities. This includes both processes and threads significantly overcounting. This instead uses an existing method already in common to count the number of processes via the /proc filesystem where any directory is a number. This should still be a single syscall to read that directory entry. This fixes #1606. --- load/load_linux.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/load/load_linux.go b/load/load_linux.go index 06bceeb84..daf2614c2 100644 --- a/load/load_linux.go +++ b/load/load_linux.go @@ -107,7 +107,7 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) { } - procsTotal, err := getProcsTotal(ctx) + procsTotal, err := common.NumProcsWithContext(ctx) if err != nil { return ret, err } @@ -116,14 +116,6 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) { return ret, nil } -func getProcsTotal(ctx context.Context) (int64, error) { - values, err := readLoadAvgFromFile(ctx) - if err != nil { - return 0, err - } - return strconv.ParseInt(strings.Split(values[3], "/")[1], 10, 64) -} - func readLoadAvgFromFile(ctx context.Context) ([]string, error) { loadavgFilename := common.HostProcWithContext(ctx, "loadavg") line, err := os.ReadFile(loadavgFilename)