pass deviceType when running smartctl data collection (for megaraid type disks).

Make DevicePrefix a public function available outside the detect module.
if device type is detected as "ata" or "scsi", dont pass in via -d parameter, can cause issues with missing data.
pull/38/head
Jason Kulatunga 4 years ago
parent 66122778a3
commit 24262f7c8c

@ -10,6 +10,7 @@ import (
"github.com/analogj/scrutiny/collector/pkg/models" "github.com/analogj/scrutiny/collector/pkg/models"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"net/url" "net/url"
"os"
"os/exec" "os/exec"
"strings" "strings"
"sync" "sync"
@ -75,7 +76,7 @@ func (mc *MetricsCollector) Run() error {
for _, device := range deviceRespWrapper.Data { for _, device := range deviceRespWrapper.Data {
// execute collection in parallel go-routines // execute collection in parallel go-routines
wg.Add(1) wg.Add(1)
go mc.Collect(&wg, device.WWN, device.DeviceName) go mc.Collect(&wg, device.WWN, device.DeviceName, device.DeviceType)
} }
mc.logger.Infoln("Main: Waiting for workers to finish") mc.logger.Infoln("Main: Waiting for workers to finish")
@ -97,11 +98,18 @@ func (mc *MetricsCollector) Validate() error {
return nil return nil
} }
func (mc *MetricsCollector) Collect(wg *sync.WaitGroup, deviceWWN string, deviceName string) { func (mc *MetricsCollector) Collect(wg *sync.WaitGroup, deviceWWN string, deviceName string, deviceType string) {
defer wg.Done() defer wg.Done()
mc.logger.Infof("Collecting smartctl results for %s\n", deviceName) mc.logger.Infof("Collecting smartctl results for %s\n", deviceName)
result, err := common.ExecCmd("smartctl", []string{"-a", "-j", fmt.Sprintf("/dev/%s", deviceName)}, "", nil) args := []string{"-a", "-j"}
//only include the device type if its a non-standard one. In some cases ata drives are detected as scsi in docker, and metadata is lost.
if len(deviceType) > 0 && deviceType != "scsi" && deviceType != "ata" {
args = append(args, "-d", deviceType)
}
args = append(args, fmt.Sprintf("%s%s", detect.DevicePrefix(), deviceName))
result, err := common.ExecCmd("smartctl", args, "", os.Environ())
resultBytes := []byte(result) resultBytes := []byte(result)
if err != nil { if err != nil {
if exitError, ok := err.(*exec.ExitError); ok { if exitError, ok := err.(*exec.ExitError); ok {

@ -44,7 +44,7 @@ func (d *Detect) smartctlScan() ([]models.Device, error) {
for _, detectedDevice := range detectedDeviceConns.Devices { for _, detectedDevice := range detectedDeviceConns.Devices {
detectedDevices = append(detectedDevices, models.Device{ detectedDevices = append(detectedDevices, models.Device{
DeviceType: detectedDevice.Type, DeviceType: detectedDevice.Type,
DeviceName: strings.TrimPrefix(detectedDevice.Name, d.devicePrefix()), DeviceName: strings.TrimPrefix(detectedDevice.Name, DevicePrefix()),
}) })
} }
@ -58,10 +58,11 @@ func (d *Detect) smartctlScan() ([]models.Device, error) {
func (d *Detect) smartCtlInfo(device *models.Device) error { func (d *Detect) smartCtlInfo(device *models.Device) error {
args := []string{"--info", "-j"} args := []string{"--info", "-j"}
if len(device.DeviceType) > 0 { //only include the device type if its a non-standard one. In some cases ata drives are detected as scsi in docker, and metadata is lost.
if len(device.DeviceType) > 0 && device.DeviceType != "scsi" && device.DeviceType != "ata" {
args = append(args, "-d", device.DeviceType) args = append(args, "-d", device.DeviceType)
} }
args = append(args, fmt.Sprintf("%s%s", d.devicePrefix(), device.DeviceName)) args = append(args, fmt.Sprintf("%s%s", DevicePrefix(), device.DeviceName))
availableDeviceInfoJson, err := common.ExecCmd("smartctl", args, "", os.Environ()) availableDeviceInfoJson, err := common.ExecCmd("smartctl", args, "", os.Environ())
if err != nil { if err != nil {
@ -78,8 +79,8 @@ func (d *Detect) smartCtlInfo(device *models.Device) error {
//DeviceType and DeviceName are already populated. //DeviceType and DeviceName are already populated.
//WWN //WWN
device.ModelName = availableDeviceInfo.ModelName
//InterfaceType: //InterfaceType:
device.ModelName = availableDeviceInfo.ModelName
device.InterfaceSpeed = availableDeviceInfo.InterfaceSpeed.Current.String device.InterfaceSpeed = availableDeviceInfo.InterfaceSpeed.Current.String
device.SerialNumber = availableDeviceInfo.SerialNumber device.SerialNumber = availableDeviceInfo.SerialNumber
device.Firmware = availableDeviceInfo.FirmwareVersion device.Firmware = availableDeviceInfo.FirmwareVersion

@ -6,7 +6,7 @@ import (
"strings" "strings"
) )
func (d *Detect) devicePrefix() string { func DevicePrefix() string {
return "/dev/" return "/dev/"
} }
@ -69,7 +69,7 @@ func (d *Detect) findMissingDevices(detectedDevices []models.Device) ([]models.D
//check if device is already detected. //check if device is already detected.
alreadyDetected := false alreadyDetected := false
diskName := strings.TrimPrefix(disk.Name, d.devicePrefix()) diskName := strings.TrimPrefix(disk.Name, DevicePrefix())
for _, detectedDevice := range detectedDevices { for _, detectedDevice := range detectedDevices {
if detectedDevice.DeviceName == diskName { if detectedDevice.DeviceName == diskName {

@ -5,7 +5,7 @@ import (
"github.com/jaypipes/ghw" "github.com/jaypipes/ghw"
) )
func (d *Detect) devicePrefix() string { func DevicePrefix() string {
return "/dev/" return "/dev/"
} }

@ -1,6 +1,6 @@
package detect package detect
func (d *Detect) devicePrefix() string { func DevicePrefix() string {
return "" return ""
} }

Loading…
Cancel
Save