diff --git a/go.mod b/go.mod index 127f529..c422655 100644 --- a/go.mod +++ b/go.mod @@ -18,8 +18,10 @@ require ( github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/ebitengine/purego v0.8.1 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.20.0 // indirect @@ -35,9 +37,12 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect + github.com/shirou/gopsutil/v4 v4.24.10 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect + github.com/yusufpapurcu/wmi v1.2.4 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.29.0 // indirect diff --git a/go.sum b/go.sum index 57e5746..090881b 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/ebitengine/purego v0.8.1 h1:sdRKd6plj7KYW33EH5As6YKfe8m9zbN9JMrOjNVF/BE= +github.com/ebitengine/purego v0.8.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/cors v1.7.2 h1:oLDHxdg8W/XDoN/8zamqk/Drgt4oVZDvaV0YmvVICQw= @@ -23,6 +25,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -67,9 +71,13 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/shirou/gopsutil/v4 v4.24.10 h1:7VOzPtfw/5YDU+jLEoBwXwxJbQetULywoSV4RYY7HkM= +github.com/shirou/gopsutil/v4 v4.24.10/go.mod h1:s4D/wg+ag4rG0WO7AiTj2BeYCRhym0vM7DHbZRxnIT8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -85,6 +93,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2 github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -108,7 +118,9 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/pkg/data/data.go b/pkg/data/data.go index 8dd97a4..016598b 100644 --- a/pkg/data/data.go +++ b/pkg/data/data.go @@ -9,10 +9,10 @@ import ( "time" "github.com/cloudcloud/roadie/pkg/destinations" - "github.com/cloudcloud/roadie/pkg/info" "github.com/cloudcloud/roadie/pkg/sources" "github.com/cloudcloud/roadie/pkg/types" humanize "github.com/dustin/go-humanize" + "github.com/shirou/gopsutil/v4/disk" ) const ( @@ -150,12 +150,17 @@ func (d *Data) GetDestinationsWithDetails() []any { destinations := d.Content.Destinations for _, v := range destinations { + usage, err := disk.Usage(v.Store.GetLocation()) + if err != nil { + d.c.GetLogger().With("error_message", err, "path", v.Store.GetLocation()).Error("Unable to determine free disk space.") + } + output = append(output, map[string]interface{}{ "config": v.Config, "href": v.Href, "name": v.Name, "type": v.Type, - "disk_free": humanize.Bytes(info.DiskDetails(v.Store.GetLocation()).Free), // disk.GetInfo(v.Store.GetLocation())), + "disk_free": humanize.Bytes(usage.Free), }) } diff --git a/pkg/info/disk.go b/pkg/info/disk.go deleted file mode 100644 index 6dccf05..0000000 --- a/pkg/info/disk.go +++ /dev/null @@ -1,37 +0,0 @@ -//go:build !windows - -// Package info is a house for gathering further information about specific -// components relevant to roadie. -package info - -import "syscall" - -// Disk is a structure to capture some space utilisation details about a -// specific disk. -type Disk struct { - Free uint64 `json:"free"` - Path string `json:"path"` - Size uint64 `json:"size"` - Used uint64 `json:"used"` - - stat *syscall.Statfs_t -} - -// DiskDetails will accept a string that represents a path in the local -// file system, to then provide usage information for it. -func DiskDetails(d string) Disk { - if len(d) < 1 { - return Disk{} - } - - var stat syscall.Statfs_t - syscall.Statfs(d, &stat) - - return Disk{ - stat: &stat, - Free: stat.Bfree * uint64(stat.Bsize), - Path: d, - Size: uint64(stat.Blocks) * uint64(stat.Bsize), - Used: (uint64(stat.Blocks) * uint64(stat.Bsize)) - (stat.Bfree * uint64(stat.Bsize)), - } -} diff --git a/pkg/info/disk_test.go b/pkg/info/disk_test.go deleted file mode 100644 index fd7605c..0000000 --- a/pkg/info/disk_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package info - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestDiskDetailsEmpty(t *testing.T) { - assert := assert.New(t) - - input := "" - assert.NotPanics(func() { - response := DiskDetails(input) - - assert.Empty(response, "There should be no response from the function call.") - }) -} - -func TestDiskDetailsCWD(t *testing.T) { - assert := assert.New(t) - - input := "." - assert.NotPanics(func() { - response := DiskDetails(input) - - assert.NotEqual(Disk{}, response, "The output should not be empty.") - assert.NotEqual(uint64(0), response.Used, "There should be a non-zero amount of Used space.") - assert.Equal(input, response.Path, "The input path should be in the response result.") - }) -} diff --git a/pkg/info/disk_windows.go b/pkg/info/disk_windows.go deleted file mode 100644 index b9297b3..0000000 --- a/pkg/info/disk_windows.go +++ /dev/null @@ -1,39 +0,0 @@ -//go:build windows - -// Package info is a house for gathering further information about specific -// components relevant to roadie. -package info - -import ( - "syscall" - "unsafe" -) - -// Disk is a structure to capture some space utilisation details about a -// specific disk. -type Disk struct { - Available int64 `json:"available"` - Free int64 `json:"free"` - Path string `json:"path"` - Size int64 `json:"size"` - Used int64 `json:"used"` -} - -// DiskDetails will accept a string that represents a path in the local -// file system, to then provide usage information for it. -func DiskDetails(d string) Disk { - h := syscall.MustLoadDLL("kernel32.dll") - c := h.MustFindProc("GetDiskFreeSpaceExW") - - disk := Disk{} - - c.Call( - uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(d))), - uintptr(unsafe.Pointer(&disk.Free)), - uintptr(unsafe.Pointer(&disk.Size)), - uintptr(unsafe.Pointer(&disk.Available))) - - disk.Used = disk.Size - disk.Free - - return disk -}