|
@@ -27,11 +27,11 @@ type SMARTData struct {
|
|
|
Temperature int
|
|
|
|
|
|
/* NVME specific fields */
|
|
|
- NVMENameSpace []smart.NvmeIdentNamespace
|
|
|
- PowerOnHours uint64
|
|
|
- PowerCycles uint64
|
|
|
- UnsafeShutdowns uint64
|
|
|
- MediaErrors uint64
|
|
|
+ NameSpaceUtilizations []uint64
|
|
|
+ PowerOnHours uint64
|
|
|
+ PowerCycles uint64
|
|
|
+ UnsafeShutdowns uint64
|
|
|
+ MediaErrors uint64
|
|
|
|
|
|
/* SATA specific fields */
|
|
|
SATAAttrs []*SATAAttrData
|
|
@@ -66,6 +66,26 @@ func GetSMARTData(disk string) (*SMARTData, error) {
|
|
|
return nil, errors.New("unsupported disk type")
|
|
|
}
|
|
|
|
|
|
+// Check if the disk is a SATA device
|
|
|
+func IsSATADevice(disk string) bool {
|
|
|
+ if !strings.HasPrefix(disk, "/dev/") {
|
|
|
+ disk = filepath.Join("/dev", disk)
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err := smart.OpenSata(disk)
|
|
|
+ return err == nil
|
|
|
+}
|
|
|
+
|
|
|
+// Check if the disk is a NVMe device
|
|
|
+func IsNVMeDevice(disk string) bool {
|
|
|
+ if !strings.HasPrefix(disk, "/dev/") {
|
|
|
+ disk = filepath.Join("/dev", disk)
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err := smart.OpenNVMe(disk)
|
|
|
+ return err == nil
|
|
|
+}
|
|
|
+
|
|
|
func getSATASMART(diskpath string) (*SMARTData, error) {
|
|
|
dev, err := smart.OpenSata(diskpath)
|
|
|
if err != nil {
|
|
@@ -131,18 +151,22 @@ func getNVMESMART(diskpath string) (*SMARTData, error) {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
+ NameSpaceUtilizations := []uint64{}
|
|
|
+ for _, ns := range nss {
|
|
|
+ NameSpaceUtilizations = append(NameSpaceUtilizations, ns.Nuse*ns.LbaSize())
|
|
|
+ }
|
|
|
+
|
|
|
sm, _ := dev.ReadSMART()
|
|
|
smartData := SMARTData{
|
|
|
- ModelNumber: c.ModelNumber(),
|
|
|
- SerialNumber: c.SerialNumber(),
|
|
|
- Size: c.Tnvmcap.Val[0],
|
|
|
- Temperature: int(sm.Temperature),
|
|
|
- PowerOnHours: sm.PowerOnHours.Val[0],
|
|
|
- PowerCycles: sm.PowerCycles.Val[0],
|
|
|
- UnsafeShutdowns: sm.UnsafeShutdowns.Val[0],
|
|
|
- MediaErrors: sm.MediaErrors.Val[0],
|
|
|
-
|
|
|
- NVMENameSpace: nss,
|
|
|
+ ModelNumber: c.ModelNumber(),
|
|
|
+ SerialNumber: c.SerialNumber(),
|
|
|
+ Size: c.Tnvmcap.Val[0],
|
|
|
+ NameSpaceUtilizations: NameSpaceUtilizations,
|
|
|
+ Temperature: int(sm.Temperature),
|
|
|
+ PowerOnHours: sm.PowerOnHours.Val[0],
|
|
|
+ PowerCycles: sm.PowerCycles.Val[0],
|
|
|
+ UnsafeShutdowns: sm.UnsafeShutdowns.Val[0],
|
|
|
+ MediaErrors: sm.MediaErrors.Val[0],
|
|
|
}
|
|
|
|
|
|
return &smartData, nil
|