go-sysinfo icon indicating copy to clipboard operation
go-sysinfo copied to clipboard

Feat/load average implementation

Open ariasmn opened this issue 3 years ago • 5 comments

This should close #120

As I said on the issue, I had some problems for the darwin implementation, since I had to do it from a VM. I tested it without CGO (CGO_ENABLED=0) and still worked.

The way the load is parsed seems a bit tricky, although it's the standard way of doing so for BSD systems using Golang. I tried parsing the values the same way you did on others SysctlRaw without any luck (I'd appreciate an explanation if you know the reason, I'm still pretty new to Golang)

If anything needs some changes, please let me know!

Linux host: Fedora 36 Workstation, Kernel 5.19.15-201 Darwin host: macOS Catalina, Version 10.15.7

ariasmn avatar Oct 19 '22 17:10 ariasmn

💚 CLA has been signed

:green_heart: Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-10-27T22:49:25.775+0000

  • Duration: 9 min 43 sec

Test stats :test_tube:

Test Results
Failed 0
Passed 206
Skipped 4
Total 210

elasticmachine avatar Oct 19 '22 17:10 elasticmachine

I also put up a PR #41 that adds a little CLI that makes it a bit easier to test and demonstrate the package.

prologic avatar Oct 19 '22 22:10 prologic

Hey @ariasmn I tested this on my Mac and everything you've done here is working great ok_hand -- Except for one minor patch/change you forgot to add sweat_smile

commit 93d5e2259916ce787119d86ca91669125fbf6490
Author: James Mills <[email protected]>
Date:   Thu Oct 20 08:43:26 2022 +1000

    Fix missing embedding of LoadAverage interface in Host interface

diff --git a/types/host.go b/types/host.go
index d2911ee..2ffee7b 100644
--- a/types/host.go
+++ b/types/host.go
@@ -24,6 +24,7 @@ import "time"
 // implementation is unable to collect all of the necessary data.
 type Host interface {
        CPUTimer
+       LoadAverage
        Info() HostInfo
        Memory() (*HostMemoryInfo, error)
 }

Woops, you are right! Glad that everything is working for you. Let's wait for the review from the people at Elastic so I can fix everything in one go.

Thanks for your time!

ariasmn avatar Oct 20 '22 05:10 ariasmn

No worries 🤗

prologic avatar Oct 20 '22 07:10 prologic

@ariasmn Can you see to the above? 🙏 I'd really like to see this PR merged 👌

prologic avatar Oct 26 '22 02:10 prologic

@prologic @andrewkroh Done!

Let me know if anything still needs some work.

ariasmn avatar Oct 26 '22 16:10 ariasmn

/test

andrewkroh avatar Oct 26 '22 16:10 andrewkroh

Didn't even think about Windows now that I see the tests failing to be honest.

@andrewkroh If I'm not mistaken, the only thing that I should do is just implement the LoadAverage function on the host_windows.go? Something like:

func (h *host) LoadAverage() (*types.LoadAverageInfo, error) {
	return nil, fmt.Errorf("LoadAverage is not available for this platform %w", types.ErrNotImplemented)
}

ariasmn avatar Oct 26 '22 17:10 ariasmn

I just added a commit to the PR, adding the missing functions on Windows and AIX hosts. Also, I updated the README as well to note the new LoadAverage interface support.

Let me know if anything is still left (sorry that the PR is bouncing back and forth this much, completely my fault!)

ariasmn avatar Oct 27 '22 17:10 ariasmn

/test

andrewkroh avatar Oct 27 '22 20:10 andrewkroh

/test

andrewkroh avatar Oct 27 '22 22:10 andrewkroh

/test

andrewkroh avatar Oct 27 '22 22:10 andrewkroh

@andrewkroh What's the status of this? Just asking to know if there's anything left I should do on my side.

ariasmn avatar Nov 03 '22 10:11 ariasmn