From 97cce5ac092ed2a7338205eb5360ff5a1cc9f134 Mon Sep 17 00:00:00 2001 From: Link Date: Tue, 26 Dec 2023 09:38:00 +0000 Subject: [PATCH 1/2] update zip path --- utils/file/file.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/file/file.go b/utils/file/file.go index 66996ef..ddb6da7 100644 --- a/utils/file/file.go +++ b/utils/file/file.go @@ -418,11 +418,14 @@ func AddFile(ar archiver.Writer, path, commonPath string) error { defer file.Close() if path != commonPath { - filename := info.Name() + //filename := info.Name() + fpath := strings.Replace(path, commonPath, "", 1) + fpath = filepath.Join(filepath.Base(commonPath), fpath) + //filename := info.Name() err = ar.Write(archiver.File{ FileInfo: archiver.FileInfo{ FileInfo: info, - CustomName: filename, + CustomName: fpath, }, ReadCloser: file, }) From 3519c0512d4a5170ecba59d33b0854d711eeff1a Mon Sep 17 00:00:00 2001 From: CorrectRoadH Date: Thu, 18 Jan 2024 10:26:08 +0800 Subject: [PATCH 2/2] feat: add gpu infos (#40) --- external/gpu.go | 65 ++++++++++++++++++++++++++++++++++++++++++++ external/gpu_test.go | 15 ++++++++++ 2 files changed, 80 insertions(+) create mode 100644 external/gpu.go create mode 100644 external/gpu_test.go diff --git a/external/gpu.go b/external/gpu.go new file mode 100644 index 0000000..ea89ccf --- /dev/null +++ b/external/gpu.go @@ -0,0 +1,65 @@ +package external + +import ( + "fmt" + "os/exec" + "strconv" + "strings" +) + +type GPUInfo struct { + Index int + UUID string + UtilizationGPU int + MemoryTotal int + MemoryUsed int + MemoryFree int + DriverVersion string + Name string + GPUSerial string + DisplayActive bool + DisplayMode bool + TemperatureGPU int +} + +func GPUsInfo() ([]GPUInfo, error) { + // execute shell + // parse result + GPUInfos := []GPUInfo{} + + output, err := exec.Command("nvidia-smi", "--query-gpu=index,uuid,utilization.gpu,memory.total,memory.used,memory.free,driver_version,name,gpu_serial,display_active,display_mode,temperature.gpu", "--format=csv,noheader,nounits").Output() + if err != nil { + return nil, err + } + lines := strings.Split(string(output), "\n") + fmt.Println(lines) + for _, line := range lines { + value := strings.Split(line, ", ") + if len(value) == 12 { + index, _ := strconv.Atoi(value[0]) + utilizationGPU, _ := strconv.Atoi(value[2]) + memoryTotal, _ := strconv.Atoi(value[3]) + memoryUsed, _ := strconv.Atoi(value[4]) + memoryFree, _ := strconv.Atoi(value[5]) + temperatureGPU, _ := strconv.Atoi(value[11]) + GPUInfos = append(GPUInfos, GPUInfo{ + Index: index, + UUID: value[1], + UtilizationGPU: utilizationGPU, + MemoryTotal: memoryTotal, + MemoryUsed: memoryUsed, + MemoryFree: memoryFree, + DriverVersion: value[6], + Name: value[7], + GPUSerial: value[8], + DisplayActive: value[9] == "Enable", + DisplayMode: value[10] == "Enabled", + TemperatureGPU: temperatureGPU, + }) + } else { + continue + } + } + + return GPUInfos, nil +} diff --git a/external/gpu_test.go b/external/gpu_test.go new file mode 100644 index 0000000..7e3f3ac --- /dev/null +++ b/external/gpu_test.go @@ -0,0 +1,15 @@ +package external_test + +import ( + "testing" + + "github.com/IceWhaleTech/CasaOS-Common/external" + "gotest.tools/v3/assert" +) + +func TestGPUInfos(t *testing.T) { + t.Skip() + GPUsInfo, err := external.GPUsInfo() + assert.NilError(t, err) + assert.Equal(t, len(GPUsInfo), 1) +}