git: a26ef1167887 - main - sysutils/beats8: upgrade to 8.14.3
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 21 Jul 2024 12:18:19 UTC
The branch main has been updated by samm: URL: https://cgit.FreeBSD.org/ports/commit/?id=a26ef116788796fbc4d601d5990456b35d7e5638 commit a26ef116788796fbc4d601d5990456b35d7e5638 Author: Oleksii Samorukov <samm@FreeBSD.org> AuthorDate: 2024-07-21 12:10:12 +0000 Commit: Oleksii Samorukov <samm@FreeBSD.org> CommitDate: 2024-07-21 12:16:24 +0000 sysutils/beats8: upgrade to 8.14.3 - fix beats by integrating patch from the https://github.com/elastic/go-sysinfo/pull/126 - upgrade to the latest version ChangeLog: https://www.elastic.co/guide/en/beats/libbeat/current/release-notes.html Approved by: otis (elastic) PR: 272701 --- sysutils/beats8/Makefile | 3 +- sysutils/beats8/distinfo | 30 +- .../beats8/files/patch-dev-tools_mage_settings.go | 12 +- sysutils/beats8/files/patch-go-sysinfo | 1327 ++++++++++++++++++++ ...libbeat_autodiscover_providers_docker_config.go | 8 +- ...libbeat_autodiscover_providers_docker_docker.go | 10 +- ...eat_autodiscover_providers_kubernetes_config.go | 8 +- ...autodiscover_providers_kubernetes_kubernetes.go | 8 +- .../beats8/files/patch-libbeat_scripts_Makefile | 10 +- ...com_godbus_dbus_transport__unixcred__freebsd.go | 4 +- 10 files changed, 1369 insertions(+), 51 deletions(-) diff --git a/sysutils/beats8/Makefile b/sysutils/beats8/Makefile index 63c2287f91e3..9b9f46259734 100644 --- a/sysutils/beats8/Makefile +++ b/sysutils/beats8/Makefile @@ -1,7 +1,6 @@ PORTNAME= beats DISTVERSIONPREFIX= v -DISTVERSION= 8.8.2 -PORTREVISION= 9 +DISTVERSION= 8.14.3 CATEGORIES= sysutils MASTER_SITES= https://raw.githubusercontent.com/${GH_ACCOUNT}/${GH_PROJECT}/${DISTVERSIONFULL}/:gomod PKGNAMESUFFIX?= 8 diff --git a/sysutils/beats8/distinfo b/sysutils/beats8/distinfo index 7f6429e1169c..35b506baf697 100644 --- a/sysutils/beats8/distinfo +++ b/sysutils/beats8/distinfo @@ -1,15 +1,15 @@ -TIMESTAMP = 1688894132 -SHA256 (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/go.mod) = 23630aa548aebbe00236b3ad6e15508acfec8dbae683d0d5e9476e49776903cc -SIZE (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/go.mod) = 19317 -SHA256 (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/auditbeat-8.8.2-darwin-x86_64.tar.gz) = e60e5131c23431f5c06f989cd4f1a4f2540a861b75964d621dea979496a9e1e9 -SIZE (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/auditbeat-8.8.2-darwin-x86_64.tar.gz) = 28368935 -SHA256 (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/filebeat-8.8.2-darwin-x86_64.tar.gz) = a7e131387c277c9223c9b2356e944450c38dbaaedf069a0521ca75b40f0a6c74 -SIZE (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/filebeat-8.8.2-darwin-x86_64.tar.gz) = 38669362 -SHA256 (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/heartbeat-8.8.2-darwin-x86_64.tar.gz) = 0cc3585b9e85d09441b746a3d812849f50727d2f57f821bfea01c936dc003bb4 -SIZE (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/heartbeat-8.8.2-darwin-x86_64.tar.gz) = 28278125 -SHA256 (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/metricbeat-8.8.2-darwin-x86_64.tar.gz) = 2de4c1e6057fa5aae354c511f6d6a0553913573f263dfe5a6ea0c5b4fb59116e -SIZE (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/metricbeat-8.8.2-darwin-x86_64.tar.gz) = 43743769 -SHA256 (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/packetbeat-8.8.2-darwin-x86_64.tar.gz) = dbf59643dd06bc75663259b011e980103ee448017fa773163792844d726fa94d -SIZE (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/packetbeat-8.8.2-darwin-x86_64.tar.gz) = 29652391 -SHA256 (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/elastic-beats-v8.8.2_GH0.tar.gz) = 7f85ef70cfa84e9959a803e1cc490d2a3dea7bd23902e3c992bbeaec9d8daf0a -SIZE (go/sysutils_beats8/elastic-beats-v8.8.2_GH0/elastic-beats-v8.8.2_GH0.tar.gz) = 115594288 +TIMESTAMP = 1721561711 +SHA256 (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/go.mod) = 5ac53d72ec047685257e305055a61c0fe58dd64fa4809401bca4e9cd820765d1 +SIZE (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/go.mod) = 22285 +SHA256 (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/auditbeat-8.14.3-darwin-x86_64.tar.gz) = ab2ed29e547dcac6f85d73738a29d3133288d25057c4b16e96ea0c8d2df1e179 +SIZE (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/auditbeat-8.14.3-darwin-x86_64.tar.gz) = 29504818 +SHA256 (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/filebeat-8.14.3-darwin-x86_64.tar.gz) = 40f1b913eaede43afcf73cb669b4db57f98f1147f52fda7bfee0752eb0325651 +SIZE (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/filebeat-8.14.3-darwin-x86_64.tar.gz) = 44226004 +SHA256 (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/heartbeat-8.14.3-darwin-x86_64.tar.gz) = 5b9adf542af50dfc3f0766cd79bca0379c9c7675e81c451d910d27b5fe6d0a53 +SIZE (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/heartbeat-8.14.3-darwin-x86_64.tar.gz) = 29600533 +SHA256 (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/metricbeat-8.14.3-darwin-x86_64.tar.gz) = f79e4bc722b1e97025dfca427923c975539efe268686d7b53af75b758f573b87 +SIZE (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/metricbeat-8.14.3-darwin-x86_64.tar.gz) = 47395194 +SHA256 (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/packetbeat-8.14.3-darwin-x86_64.tar.gz) = 88fca4b5c955a6bba3a4fa28bff5faeda1676c7e5354679e4ce6be8dc4d87265 +SIZE (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/packetbeat-8.14.3-darwin-x86_64.tar.gz) = 30766046 +SHA256 (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/elastic-beats-v8.14.3_GH0.tar.gz) = 146fcd1d7a9ea951e362662c9d43bfd65bbdfad3e58dc315573bd6e62065e8fe +SIZE (go/sysutils_beats8/elastic-beats-v8.14.3_GH0/elastic-beats-v8.14.3_GH0.tar.gz) = 112258023 diff --git a/sysutils/beats8/files/patch-dev-tools_mage_settings.go b/sysutils/beats8/files/patch-dev-tools_mage_settings.go index db8c9ed4cbe1..86e470f90315 100644 --- a/sysutils/beats8/files/patch-dev-tools_mage_settings.go +++ b/sysutils/beats8/files/patch-dev-tools_mage_settings.go @@ -1,20 +1,20 @@ ---- dev-tools/mage/settings.go.orig 2022-09-27 13:19:27 UTC -+++ dev-tools/mage/settings.go -@@ -30,7 +30,6 @@ import ( +--- dev-tools/mage/settings.go.orig 2024-07-09 00:00:36.000000000 +0200 ++++ dev-tools/mage/settings.go 2024-07-13 21:26:19.383768000 +0200 +@@ -31,7 +31,6 @@ "sync" "time" - "github.com/magefile/mage/sh" - "github.com/pkg/errors" "golang.org/x/tools/go/vcs" -@@ -249,7 +248,8 @@ var ( + "github.com/elastic/beats/v7/dev-tools/mage/gotool" +@@ -251,7 +250,8 @@ func CommitHash() (string, error) { var err error commitHashOnce.Do(func() { - commitHash, err = sh.Output("git", "rev-parse", "HEAD") + err = nil -+ commitHash = "%%BEATSVERSION%%" ++ commitHash = "v8.14.3" }) return commitHash, err } diff --git a/sysutils/beats8/files/patch-go-sysinfo b/sysutils/beats8/files/patch-go-sysinfo new file mode 100644 index 000000000000..240a59633c38 --- /dev/null +++ b/sysutils/beats8/files/patch-go-sysinfo @@ -0,0 +1,1327 @@ +diff -urN vendor.orig/github.com/elastic/go-sysinfo/internal/cgo/disabled.go vendor/github.com/elastic/go-sysinfo/internal/cgo/disabled.go +--- vendor.orig/github.com/elastic/go-sysinfo/internal/cgo/disabled.go 1970-01-01 01:00:00.000000000 +0100 ++++ vendor/github.com/elastic/go-sysinfo/internal/cgo/disabled.go 2024-07-13 20:28:36.060882000 +0200 +@@ -0,0 +1,23 @@ ++// Licensed to Elasticsearch B.V. under one or more contributor ++// license agreements. See the NOTICE file distributed with ++// this work for additional information regarding copyright ++// ownership. Elasticsearch B.V. licenses this file to you 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. ++ ++//go:build !cgo ++ ++package cgo ++ ++// Enabled is true if cgo was enabled at compile-time. ++const Enabled = false +diff -urN vendor.orig/github.com/elastic/go-sysinfo/internal/cgo/enabled.go vendor/github.com/elastic/go-sysinfo/internal/cgo/enabled.go +--- vendor.orig/github.com/elastic/go-sysinfo/internal/cgo/enabled.go 1970-01-01 01:00:00.000000000 +0100 ++++ vendor/github.com/elastic/go-sysinfo/internal/cgo/enabled.go 2024-07-13 20:28:36.060953000 +0200 +@@ -0,0 +1,23 @@ ++// Licensed to Elasticsearch B.V. under one or more contributor ++// license agreements. See the NOTICE file distributed with ++// this work for additional information regarding copyright ++// ownership. Elasticsearch B.V. licenses this file to you 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. ++ ++//go:build cgo ++ ++package cgo ++ ++// Enabled is true if cgo was enabled at compile-time. ++const Enabled = true +diff -urN vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/defs_freebsd.go vendor/github.com/elastic/go-sysinfo/providers/freebsd/defs_freebsd.go +--- vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/defs_freebsd.go 1970-01-01 01:00:00.000000000 +0100 ++++ vendor/github.com/elastic/go-sysinfo/providers/freebsd/defs_freebsd.go 2024-07-13 20:28:36.065106000 +0200 +@@ -0,0 +1,33 @@ ++// Licensed to Elasticsearch B.V. under one or more contributor ++// license agreements. See the NOTICE file distributed with ++// this work for additional information regarding copyright ++// ownership. Elasticsearch B.V. licenses this file to you 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. ++ ++//go:build ignore ++// +build ignore ++ ++package freebsd ++ ++/* ++#include <sys/types.h> ++#include <sys/vmmeter.h> ++#include <sys/time.h> ++#include <kvm.h> ++*/ ++import "C" ++ ++type kvmSwap C.struct_kvm_swap ++ ++type clockInfo C.struct_clockinfo +diff -urN vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/doc.go vendor/github.com/elastic/go-sysinfo/providers/freebsd/doc.go +--- vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/doc.go 1970-01-01 01:00:00.000000000 +0100 ++++ vendor/github.com/elastic/go-sysinfo/providers/freebsd/doc.go 2024-07-13 20:28:36.065203000 +0200 +@@ -0,0 +1,22 @@ ++// Licensed to Elasticsearch B.V. under one or more contributor ++// license agreements. See the NOTICE file distributed with ++// this work for additional information regarding copyright ++// ownership. Elasticsearch B.V. licenses this file to you 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. ++ ++// Package freebsd implements the HostProvider and ProcessProvider interfaces ++// for providing information about FreeBSD. ++package freebsd ++ ++//go:generate sh -c "go tool cgo -godefs defs_freebsd.go > ztypes_freebsd.go" +diff -urN vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/host_freebsd_cgo.go vendor/github.com/elastic/go-sysinfo/providers/freebsd/host_freebsd_cgo.go +--- vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/host_freebsd_cgo.go 1970-01-01 01:00:00.000000000 +0100 ++++ vendor/github.com/elastic/go-sysinfo/providers/freebsd/host_freebsd_cgo.go 2024-07-13 20:28:36.065317000 +0200 +@@ -0,0 +1,238 @@ ++// Licensed to Elasticsearch B.V. under one or more contributor ++// license agreements. See the NOTICE file distributed with ++// this work for additional information regarding copyright ++// ownership. Elasticsearch B.V. licenses this file to you 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. ++ ++//go:build freebsd && cgo ++ ++package freebsd ++ ++import ( ++ "context" ++ "errors" ++ "os" ++ "path/filepath" ++ "time" ++ ++ "github.com/prometheus/procfs" ++ ++ "github.com/elastic/go-sysinfo/internal/registry" ++ "github.com/elastic/go-sysinfo/providers/shared" ++ "github.com/elastic/go-sysinfo/types" ++) ++ ++func init() { ++ registry.Register(newFreeBSDSystem()) ++} ++ ++type freebsdSystem struct{} ++ ++func newFreeBSDSystem() freebsdSystem { ++ return freebsdSystem{} ++} ++ ++func (s freebsdSystem) Host() (types.Host, error) { ++ return newHost() ++} ++ ++type host struct { ++ procFS procFS ++ info types.HostInfo ++} ++ ++func (h *host) Info() types.HostInfo { ++ return h.info ++} ++ ++func (h *host) CPUTime() (types.CPUTimes, error) { ++ cpu := types.CPUTimes{} ++ r := &reader{} ++ r.cpuTime(&cpu) ++ return cpu, r.Err() ++} ++ ++func (h *host) Memory() (*types.HostMemoryInfo, error) { ++ m := &types.HostMemoryInfo{} ++ r := &reader{} ++ r.memInfo(m) ++ return m, r.Err() ++} ++ ++func (h *host) FQDNWithContext(ctx context.Context) (string, error) { ++ return shared.FQDNWithContext(ctx) ++} ++ ++func (h *host) FQDN() (string, error) { ++ return h.FQDNWithContext(context.Background()) ++} ++ ++func newHost() (*host, error) { ++ h := &host{} ++ r := &reader{} ++ r.architecture(h) ++ r.bootTime(h) ++ r.hostname(h) ++ r.network(h) ++ r.kernelVersion(h) ++ r.os(h) ++ r.time(h) ++ r.uniqueID(h) ++ return h, r.Err() ++} ++ ++type reader struct { ++ errs []error ++} ++ ++func (r *reader) addErr(err error) bool { ++ if err != nil { ++ if !errors.Is(err, types.ErrNotImplemented) { ++ r.errs = append(r.errs, err) ++ } ++ return true ++ } ++ return false ++} ++ ++func (r *reader) Err() error { ++ return errors.Join(r.errs...) ++} ++ ++func (r *reader) cpuTime(cpu *types.CPUTimes) { ++ times, err := cpuStateTimes() ++ if r.addErr(err) { ++ return ++ } ++ *cpu = *times ++} ++ ++func (r *reader) memInfo(m *types.HostMemoryInfo) { ++ // Memory counter calculations: ++ // total = physical memory ++ // used = active + wired ++ // free = free ++ // available = buffers + inactive + cache + free ++ ++ pageSize, err := pageSizeBytes() ++ if r.addErr(err) { ++ return ++ } ++ ++ m.Total = totalPhysicalMem(r) ++ activePages := activePageCount(r) ++ ++ m.Metrics = make(map[string]uint64, 6) ++ m.Metrics["active_bytes"] = activePages * pageSize ++ ++ wirePages := wirePageCount(r) ++ m.Metrics["wired_bytes"] = wirePages * pageSize ++ ++ inactivePages := inactivePageCount(r) ++ m.Metrics["inactive_bytes"] = inactivePages * pageSize ++ ++ cachePages := cachePageCount(r) ++ m.Metrics["cache_bytes"] = cachePages * pageSize ++ ++ freePages := freePageCount(r) ++ m.Metrics["free_bytes"] = freePages * pageSize ++ ++ buffers := buffersUsedBytes(r) ++ m.Metrics["buffer_bytes"] = buffers ++ ++ m.Used = (activePages + wirePages) * pageSize ++ m.Free = freePages * pageSize ++ m.Available = (inactivePages+cachePages+freePages)*pageSize + buffers ++ ++ // Virtual (swap) Memory ++ swap, err := kvmGetSwapInfo() ++ if r.addErr(err) { ++ return ++ } ++ ++ m.VirtualTotal = uint64(swap.Total) * pageSize ++ m.VirtualUsed = uint64(swap.Used) * pageSize ++ m.VirtualFree = m.VirtualTotal - m.VirtualUsed ++} ++ ++func (r *reader) architecture(h *host) { ++ v, err := architecture() ++ if r.addErr(err) { ++ return ++ } ++ h.info.Architecture = v ++} ++ ++func (r *reader) bootTime(h *host) { ++ v, err := bootTime() ++ if r.addErr(err) { ++ return ++ } ++ h.info.BootTime = v ++} ++ ++func (r *reader) hostname(h *host) { ++ v, err := os.Hostname() ++ if r.addErr(err) { ++ return ++ } ++ h.info.Hostname = v ++} ++ ++func (r *reader) network(h *host) { ++ ips, macs, err := shared.Network() ++ if r.addErr(err) { ++ return ++ } ++ h.info.IPs = ips ++ h.info.MACs = macs ++} ++ ++func (r *reader) kernelVersion(h *host) { ++ v, err := kernelVersion() ++ if r.addErr(err) { ++ return ++ } ++ h.info.KernelVersion = v ++} ++ ++func (r *reader) os(h *host) { ++ v, err := operatingSystem() ++ if r.addErr(err) { ++ return ++ } ++ h.info.OS = v ++} ++ ++func (r *reader) time(h *host) { ++ h.info.Timezone, h.info.TimezoneOffsetSec = time.Now().Zone() ++} ++ ++func (r *reader) uniqueID(h *host) { ++ v, err := machineID() ++ if r.addErr(err) { ++ return ++ } ++ h.info.UniqueID = v ++} ++ ++type procFS struct { ++ procfs.FS ++ mountPoint string ++} ++ ++func (fs *procFS) path(p ...string) string { ++ elem := append([]string{fs.mountPoint}, p...) ++ return filepath.Join(elem...) ++} +diff -urN vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/host_freebsd_cgo_test.go vendor/github.com/elastic/go-sysinfo/providers/freebsd/host_freebsd_cgo_test.go +--- vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/host_freebsd_cgo_test.go 1970-01-01 01:00:00.000000000 +0100 ++++ vendor/github.com/elastic/go-sysinfo/providers/freebsd/host_freebsd_cgo_test.go 2024-07-13 20:28:36.065385000 +0200 +@@ -0,0 +1,53 @@ ++// Licensed to Elasticsearch B.V. under one or more contributor ++// license agreements. See the NOTICE file distributed with ++// this work for additional information regarding copyright ++// ownership. Elasticsearch B.V. licenses this file to you 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. ++ ++//go:build freebsd && cgo ++ ++package freebsd ++ ++import ( ++ "encoding/json" ++ "testing" ++ ++ "github.com/elastic/go-sysinfo/internal/registry" ++) ++ ++var _ registry.HostProvider = freebsdSystem{} ++ ++func TestHost(t *testing.T) { ++ host, err := newFreeBSDSystem().Host() ++ if err != nil { ++ t.Fatal(err) ++ } ++ ++ t.Run("Info", func(t *testing.T) { ++ info := host.Info() ++ ++ data, _ := json.MarshalIndent(info, "", " ") ++ t.Log(string(data)) ++ }) ++ ++ t.Run("Memory", func(t *testing.T) { ++ mem, err := host.Memory() ++ if err != nil { ++ t.Fatal(err) ++ } ++ ++ data, _ := json.MarshalIndent(mem, "", " ") ++ t.Log(string(data)) ++ }) ++} +diff -urN vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/kvm_freebsd_cgo.go vendor/github.com/elastic/go-sysinfo/providers/freebsd/kvm_freebsd_cgo.go +--- vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/kvm_freebsd_cgo.go 1970-01-01 01:00:00.000000000 +0100 ++++ vendor/github.com/elastic/go-sysinfo/providers/freebsd/kvm_freebsd_cgo.go 2024-07-13 20:28:36.065498000 +0200 +@@ -0,0 +1,58 @@ ++// Licensed to Elasticsearch B.V. under one or more contributor ++// license agreements. See the NOTICE file distributed with ++// this work for additional information regarding copyright ++// ownership. Elasticsearch B.V. licenses this file to you 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. ++ ++//go:build freebsd && cgo ++ ++package freebsd ++ ++/* ++#cgo LDFLAGS: -lkvm ++#include <sys/cdefs.h> ++#include <sys/types.h> ++#include <sys/sysctl.h> ++ ++#include <paths.h> ++#include <kvm.h> ++#include <stdlib.h> ++*/ ++import "C" ++ ++import ( ++ "fmt" ++ "unsafe" ++ ++ "golang.org/x/sys/unix" ++) ++ ++// kvmGetSwapInfo returns swap summary statistics for the system. It accesses ++// the kernel virtual memory (kvm) images by using libkvm. ++func kvmGetSwapInfo() (*kvmSwap, error) { ++ // Obtain a KVM file descriptor. ++ var errstr *C.char ++ kd := C.kvm_open(nil, nil, nil, unix.O_RDONLY, errstr) ++ if errstr != nil { ++ return nil, fmt.Errorf("failed calling kvm_open: %s", C.GoString(errstr)) ++ } ++ defer C.kvm_close(kd) ++ ++ var swap kvmSwap ++ if n, err := C.kvm_getswapinfo(kd, (*C.struct_kvm_swap)(unsafe.Pointer(&swap)), 1, 0); n != 0 { ++ return nil, fmt.Errorf("failed to get kvm_getswapinfo: %w", err) ++ } ++ ++ return &swap, nil ++} +diff -urN vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/process_freebsd_cgo.go vendor/github.com/elastic/go-sysinfo/providers/freebsd/process_freebsd_cgo.go +--- vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/process_freebsd_cgo.go 1970-01-01 01:00:00.000000000 +0100 ++++ vendor/github.com/elastic/go-sysinfo/providers/freebsd/process_freebsd_cgo.go 2024-07-13 20:28:36.065578000 +0200 +@@ -0,0 +1,386 @@ ++// Licensed to Elasticsearch B.V. under one or more contributor ++// license agreements. See the NOTICE file distributed with ++// this work for additional information regarding copyright ++// ownership. Elasticsearch B.V. licenses this file to you 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. ++ ++//go:build freebsd && cgo ++ ++package freebsd ++ ++import "C" ++ ++/* ++#cgo LDFLAGS: -lprocstat ++#include <sys/types.h> ++#include <sys/sysctl.h> ++#include <sys/time.h> ++#include <sys/param.h> ++#include <sys/queue.h> ++#include <sys/socket.h> ++#include <sys/user.h> ++ ++#include <libprocstat.h> ++#include <string.h> ++ ++struct kinfo_proc getProcInfoAt(struct kinfo_proc *procs, unsigned int index) { ++ return procs[index]; ++} ++ ++unsigned int countArrayItems(char **items) { ++ unsigned int i = 0; ++ for (i = 0; items[i] != NULL; ++i); ++ return i; ++} ++ ++char * itemAtIndex(char **items, unsigned int index) { ++ return items[index]; ++} ++ ++unsigned int countFileStats(struct filestat_list *head) { ++ unsigned int count = 0; ++ struct filestat *fst; ++ STAILQ_FOREACH(fst, head, next) { ++ ++count; ++ } ++ ++ return count; ++} ++ ++void copyFileStats(struct filestat_list *head, struct filestat *out, unsigned int size) { ++ unsigned int index = 0; ++ struct filestat *fst; ++ if (size == 0) { ++ return; ++ } ++ STAILQ_FOREACH(fst, head, next) { ++ memcpy(out, fst, sizeof(*fst)); ++ ++out; ++ --size; ++ } ++} ++*/ ++import "C" ++ ++import ( ++ "errors" ++ "fmt" ++ "os" ++ "strconv" ++ "strings" ++ "time" ++ ++ "github.com/elastic/go-sysinfo/types" ++) ++ ++func getProcInfo(op, arg int) ([]process, error) { ++ procstat, err := C.procstat_open_sysctl() ++ if procstat == nil { ++ return nil, fmt.Errorf("failed to open procstat sysctl: %w", err) ++ } ++ defer C.procstat_close(procstat) ++ ++ var count C.uint = 0 ++ kprocs, err := C.procstat_getprocs(procstat, C.int(op), C.int(arg), &count) ++ if kprocs == nil { ++ return nil, fmt.Errorf("getprocs failed: %w", err) ++ } ++ defer C.procstat_freeprocs(procstat, kprocs) ++ ++ procs := make([]process, count) ++ var index C.uint ++ for index = 0; index < count; index++ { ++ proc := C.getProcInfoAt(kprocs, index) ++ procs[index].kinfo = proc ++ procs[index].pid = int(proc.ki_pid) ++ } ++ ++ return procs, nil ++} ++ ++func copyArray(from **C.char) []string { ++ if from == nil { ++ return nil ++ } ++ ++ count := C.countArrayItems(from) ++ out := make([]string, count) ++ ++ for index := C.uint(0); index < count; index++ { ++ out[index] = C.GoString(C.itemAtIndex(from, index)) ++ } ++ ++ return out ++} ++ ++func makeMap(from []string) map[string]string { ++ out := make(map[string]string, len(from)) ++ ++ for _, env := range from { ++ parts := strings.Split(env, "=") ++ if len(parts) > 1 { ++ out[parts[0]] = parts[1] ++ } ++ } ++ ++ return out ++} ++ ++func getProcEnv(p *process) (map[string]string, error) { ++ procstat, err := C.procstat_open_sysctl() ++ ++ if procstat == nil { ++ return nil, fmt.Errorf("failed to open procstat sysctl: %w", err) ++ } ++ defer C.procstat_close(procstat) ++ ++ env, err := C.procstat_getenvv(procstat, &p.kinfo, 0) ++ defer C.procstat_freeenvv(procstat) ++ ++ return makeMap(copyArray(env)), err ++} ++ ++func getProcArgs(p *process) ([]string, error) { ++ procstat, err := C.procstat_open_sysctl() ++ ++ if procstat == nil { ++ return nil, fmt.Errorf("failed to open procstat sysctl: %w", err) ++ } ++ defer C.procstat_close(procstat) ++ ++ args, err := C.procstat_getargv(procstat, &p.kinfo, 0) ++ defer C.procstat_freeargv(procstat) ++ ++ return copyArray(args), err ++} ++ ++func getProcPathname(p *process) (string, error) { ++ procstat, err := C.procstat_open_sysctl() ++ ++ if procstat == nil { ++ return "", fmt.Errorf("failed to open procstat sysctl: %w", err) ++ } ++ defer C.procstat_close(procstat) ++ ++ const maxlen = uint(1024) ++ out := make([]C.char, maxlen) ++ if res, err := C.procstat_getpathname(procstat, &p.kinfo, &out[0], C.ulong(maxlen)); res != 0 { ++ return "", err ++ } ++ return C.GoString(&out[0]), nil ++} ++ ++func getFileStats(fileStats *C.struct_filestat_list) []C.struct_filestat { ++ count := C.countFileStats(fileStats) ++ ++ if count < 1 { ++ return nil ++ } ++ ++ out := make([]C.struct_filestat, count) ++ ++ C.copyFileStats(fileStats, &out[0], count) ++ return out ++} ++ ++func getProcCWD(p *process) (string, error) { ++ procstat, err := C.procstat_open_sysctl() ++ ++ if procstat == nil { ++ return "", fmt.Errorf("failed to open procstat sysctl: %w", err) ++ } ++ defer C.procstat_close(procstat) ++ ++ fs, err := C.procstat_getfiles(procstat, &p.kinfo, 0) ++ if fs == nil { ++ return "", fmt.Errorf("failed to get files: %w", err) ++ } ++ ++ defer C.procstat_freefiles(procstat, fs) ++ ++ files := getFileStats(fs) ++ for _, f := range files { ++ if f.fs_uflags == C.PS_FST_UFLAG_CDIR { ++ return C.GoString(f.fs_path), nil ++ } ++ } ++ ++ return "", nil ++} ++ ++type process struct { ++ pid int ++ kinfo C.struct_kinfo_proc ++} ++ ++func timevalToDuration(tm C.struct_timeval) time.Duration { ++ return time.Duration(tm.tv_sec)*time.Second + ++ time.Duration(tm.tv_usec)*time.Microsecond ++} ++ ++func (p *process) CPUTime() (types.CPUTimes, error) { ++ procs, err := getProcInfo(C.KERN_PROC_PID, p.PID()) ++ if err != nil { ++ return types.CPUTimes{}, err ++ } ++ p.kinfo = procs[0].kinfo ++ ++ return types.CPUTimes{ ++ User: timevalToDuration(p.kinfo.ki_rusage.ru_utime), ++ System: timevalToDuration(p.kinfo.ki_rusage.ru_stime), ++ }, nil ++} ++ ++func (p *process) Info() (types.ProcessInfo, error) { ++ procs, err := getProcInfo(C.KERN_PROC_PID, p.PID()) ++ if err != nil { ++ return types.ProcessInfo{}, err ++ } ++ p.kinfo = procs[0].kinfo ++ ++ cwd, err := getProcCWD(p) ++ if err != nil { ++ return types.ProcessInfo{}, err ++ } ++ ++ args, err := getProcArgs(p) ++ if err != nil { ++ return types.ProcessInfo{}, err ++ } ++ ++ exe, _ := getProcPathname(p) ++ ++ return types.ProcessInfo{ ++ Name: C.GoString(&p.kinfo.ki_comm[0]), ++ PID: int(p.kinfo.ki_pid), ++ PPID: int(p.kinfo.ki_ppid), ++ CWD: cwd, ++ Exe: exe, ++ Args: args, ++ StartTime: time.Unix(int64(p.kinfo.ki_start.tv_sec), int64(p.kinfo.ki_start.tv_usec)*1000), ++ }, nil ++} ++ ++func (p *process) Memory() (types.MemoryInfo, error) { ++ pageSize, err := pageSizeBytes() ++ if err != nil { ++ return types.MemoryInfo{}, err ++ } ++ ++ procs, err := getProcInfo(C.KERN_PROC_PID, p.PID()) ++ if err != nil { ++ return types.MemoryInfo{}, err ++ } ++ p.kinfo = procs[0].kinfo ++ ++ return types.MemoryInfo{ ++ Resident: uint64(p.kinfo.ki_rssize) * pageSize, ++ Virtual: uint64(p.kinfo.ki_size), ++ }, nil ++} ++ ++func (p *process) User() (types.UserInfo, error) { ++ procs, err := getProcInfo(C.KERN_PROC_PID, p.PID()) ++ if err != nil { ++ return types.UserInfo{}, err ++ } ++ ++ p.kinfo = procs[0].kinfo ++ ++ return types.UserInfo{ ++ UID: strconv.FormatUint(uint64(p.kinfo.ki_ruid), 10), ++ EUID: strconv.FormatUint(uint64(p.kinfo.ki_uid), 10), ++ SUID: strconv.FormatUint(uint64(p.kinfo.ki_svuid), 10), ++ GID: strconv.FormatUint(uint64(p.kinfo.ki_rgid), 10), ++ EGID: strconv.FormatUint(uint64(p.kinfo.ki_groups[0]), 10), ++ SGID: strconv.FormatUint(uint64(p.kinfo.ki_svgid), 10), ++ }, nil ++} ++ ++func (p *process) PID() int { ++ return p.pid ++} ++ ++func (p *process) OpenHandles() ([]string, error) { ++ procstat := C.procstat_open_sysctl() ++ if procstat == nil { ++ return nil, errors.New("failed to open procstat sysctl") ++ } ++ defer C.procstat_close(procstat) ++ ++ fs := C.procstat_getfiles(procstat, &p.kinfo, 0) ++ defer C.procstat_freefiles(procstat, fs) ++ ++ files := getFileStats(fs) ++ names := make([]string, 0, len(files)) ++ ++ for _, file := range files { ++ if file.fs_type == 1 { ++ if path := C.GoString(file.fs_path); path != "" { ++ names = append(names, path) ++ } ++ } ++ } ++ ++ return names, nil ++} ++ ++func (p *process) OpenHandleCount() (int, error) { ++ procstat := C.procstat_open_sysctl() ++ if procstat == nil { ++ return 0, errors.New("failed to open procstat sysctl") ++ } ++ defer C.procstat_close(procstat) ++ ++ fs := C.procstat_getfiles(procstat, &p.kinfo, 0) ++ defer C.procstat_freefiles(procstat, fs) ++ return int(C.countFileStats(fs)), nil ++} ++ ++func (p *process) Environment() (map[string]string, error) { ++ return getProcEnv(p) ++} ++ ++func (s freebsdSystem) Processes() ([]types.Process, error) { ++ procs, err := getProcInfo(C.KERN_PROC_PROC, 0) ++ out := make([]types.Process, 0, len(procs)) ++ ++ for _, proc := range procs { ++ out = append(out, &process{ ++ pid: proc.pid, ++ kinfo: proc.kinfo, ++ }) ++ } ++ ++ return out, err ++} ++ ++func (s freebsdSystem) Process(pid int) (types.Process, error) { ++ return &process{pid: pid}, nil ++} ++ ++func (s freebsdSystem) Self() (types.Process, error) { ++ return s.Process(os.Getpid()) ++} ++ ++func (p *process) Parent() (types.Process, error) { ++ info, err := p.Info() ++ if err != nil { ++ return nil, err ++ } ++ ++ proc := process{pid: info.PPID} ++ ++ return &proc, nil ++} +diff -urN vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/sysctl_freebsd.go vendor/github.com/elastic/go-sysinfo/providers/freebsd/sysctl_freebsd.go +--- vendor.orig/github.com/elastic/go-sysinfo/providers/freebsd/sysctl_freebsd.go 1970-01-01 01:00:00.000000000 +0100 *** 583 LINES SKIPPED ***