Skip to content

Conversation

@dbolcsfoldi
Copy link

Add FreeBSD provider. When I was attempting to use this package on FreeBSD I noticed the provider was completely missing, so I implemented a provider for FreeBSD.

Note that for the system_test.go that test's the current working directory I modified the test code to compare the inodes using os.SameFile instead of straight file comparison. The reason is that os.Getcwd() will return any path to CWD (either symlink or real path) but for any process except the calling pid (i.e. calling C.getcwd()) will return the real path and not the symlink.

I've tested it on FreeBSD 11.2 and 12.0 using 'go test', let me know if you need anything else to be run and please feel free to leave any review comments/reject the pull request etc.

* Add HostInfo support for FreeBSD

Initial implementation of HostInfo for FreeBSD platforms.

* Use os.SameFile to compare cwds

On some platforms (e.g. FreeBSD) user home directories are symlinks
and os.Getcwd will return the symlink path.

On FreeBSD CWD for processes that's not the running process will not
give the symlink but the resolved path causing the test to fail at this
point.

Fix is to use the os.SameFile call to resolve both Os.Getcwd and CWD.

* Add basic support for ProcessInfo on FreeBSD.

Implement Process(), Self() and Processes() to the bare minimum.
That is passing all basic tests.

* Add support for OpenHandleEnumerator and OpenHandleCounter.

* Add support for Environment

* Review fixes.

- Fix issue on FreeBSD 12.
- Minor cosmetic issues.

* Clean up build process.

- Remove cgo build directives from things not needing it.
- Add linker flags into .go files.
Sl int16
_ int16 // cgo doesn't generate the same alignment as C does
Sw int16
Vm int32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct field Vm should be VM

const kernCptimeMIB = "kern.cp_time"
const kernClockrateMIB = "kern.clockrate"

func Cptime() (map[string]uint64, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function Cptime should have comment or be unexported

}
defer C.procstat_close(procstat)

var count C.uint = 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should drop = 0 from declaration of var count; it is the zero value

const osreleaseMIB = "kern.osrelease"
const osrevisionMIB = "kern.osrevision"

func OperatingSystem() (*types.OSInfo, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function OperatingSystem should have comment or be unexported

return numfreebuffers, nil
}

func KvmGetSwapInfo() (kvmSwap, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function KvmGetSwapInfo should have comment or be unexported

const devNull = "/dev/null"
const kvmOpen = "kvm_open"

func PageSize() (uint32, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function PageSize should have comment or be unexported


const kernelHostUUIDMIB = "kern.hostuuid"

func MachineID() (string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function MachineID should have comment or be unexported


const kernelReleaseMIB = "kern.osrelease"

func KernelVersion() (string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function KernelVersion should have comment or be unexported


const kernBoottimeMIB = "kern.boottime"

func BootTime() (time.Time, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function BootTime should have comment or be unexported


const hardwareMIB = "hw.machine"

func Architecture() (string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function Architecture should have comment or be unexported

@lin7sh
Copy link

lin7sh commented Jan 22, 2021

I've encounter the the problem on FreeBSD
- unimplemented github.com/elastic/go-sysinfo/types.init /usr/local/me/go/pkg/mod/github.com/elastic/[email protected]/types/errors.go:23

@dbolcsfoldi
Copy link
Author

@mko-io This pull request is very old, I haven't updated it in a while. If you still need FreeBSD support for sysinfo I'd be happy to review it.

@dasTor
Copy link

dasTor commented Apr 19, 2021

@dbolcsfoldi would be nice, as this would make metricbeats on freebsd usable

@ghost
Copy link

ghost commented Jun 24, 2021

@dbolcsfoldi - I'm interested in having freebsd support included in this module. I might even be able to spare some cycles if help is needed, though I have limited Go experience.

I'm not sure if anybody on this thread is an Elastic employee, but input would be helpful!

@andrewkroh
Copy link
Member

Closing this as we have #126 which incorporates this with some updates.

Thanks @dbolcsfoldi .

@andrewkroh andrewkroh closed this Mar 14, 2024
@andrewkroh andrewkroh mentioned this pull request Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants