gopsutil
gopsutil copied to clipboard
Can I get the disk model number?
Is your feature request related to a problem? Please describe. [A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]]
Describe the solution you'd like [A clear and concise description of what you want to happen.]
Describe alternatives you've considered This is currently how it gets the job done
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("wmic", "diskdrive", "get", "model")
} else if runtime.GOOS == "linux" {
cmd = exec.Command("sh", "-c", "lsblk -d -o name,model | grep '^sd' | awk '{print $2}'")
} else if runtime.GOOS == "darwin" {
cmd = exec.Command("sh", "-c", "system_profiler SPSerialATADataType | awk '/Revision/ {print $3}'")
} else {
fmt.Println("Unsupported OS")
return
}
out, err := cmd.Output()
if err != nil {
fmt.Println("Error:", err)
return
}
model := strings.TrimSpace(string(out))
fmt.Println("Disk Model:", model)
Additional context [Add any other context or screenshots about the feature request here.]
Thank you for your suggestion. I've given it some thought.
- This function can be obtained on 3 different operating systems: windows, linux, darwin
- There is no model number in psutil.
- However, there are already functions SerialNumber and Label in disk package.
As for No. 1, it MUST be done, but it is accomplished. As for No. 2, it is a negative point. However, for the reason of No. 3, adding ModelNumber() here seems to be OK.
Therefore, if there are no objections, I will try to implement it in the near future. However, I am not sure how much time I will have, so the completion schedule is unknown (PR is always welcome).
The function signature should be like this.
func Model(name string) (string, error)
On an M2 Mac, with OSX 13.4.1 and an NVMe HDD, you'll have to modify the command to:
me@mymac ~ % system_profiler -detaillevel mini SPNVMeDataType
NVMExpress:
Apple SSD Controller:
APPLE SSD AP0512Z:
Capacity: 500.28 GB (500,277,792,768 bytes)
TRIM Support: Yes
Model: APPLE SSD AP0512Z
Revision: 874.120.
Detachable Drive: No
BSD Name: disk0
Partition Map Type: GPT (GUID Partition Table)
Removable Media: No
S.M.A.R.T. status: Verified