remove concurrency for collector, it causes issues on systems with lots of devices. Just retrieve the data in order for now (eventually we may do it in batches).

pull/41/head
Jason Kulatunga 4 years ago
parent 286ec25a94
commit 8b139ad157

@ -13,7 +13,6 @@ import (
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"sync"
) )
type MetricsCollector struct { type MetricsCollector struct {
@ -71,16 +70,19 @@ func (mc *MetricsCollector) Run() error {
return errors.ApiServerCommunicationError("An error occurred while retrieving filtered devices") return errors.ApiServerCommunicationError("An error occurred while retrieving filtered devices")
} else { } else {
mc.logger.Debugln(deviceRespWrapper) mc.logger.Debugln(deviceRespWrapper)
var wg sync.WaitGroup //var wg sync.WaitGroup
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, device.DeviceType) //go mc.Collect(&wg, device.WWN, device.DeviceName, device.DeviceType)
go mc.Collect(device.WWN, device.DeviceName, device.DeviceType)
// TODO: we may need to sleep for between each call to smartctl -a
//time.Sleep(30 * time.Millisecond)
} }
mc.logger.Infoln("Main: Waiting for workers to finish") //mc.logger.Infoln("Main: Waiting for workers to finish")
wg.Wait() //wg.Wait()
mc.logger.Infoln("Main: Completed") mc.logger.Infoln("Main: Completed")
} }
@ -98,8 +100,9 @@ func (mc *MetricsCollector) Validate() error {
return nil return nil
} }
func (mc *MetricsCollector) Collect(wg *sync.WaitGroup, deviceWWN string, deviceName string, deviceType string) { //func (mc *MetricsCollector) Collect(wg *sync.WaitGroup, deviceWWN string, deviceName string, deviceType string) {
defer wg.Done() func (mc *MetricsCollector) Collect(deviceWWN string, deviceName string, deviceType string) {
//defer wg.Done()
mc.logger.Infof("Collecting smartctl results for %s\n", deviceName) mc.logger.Infof("Collecting smartctl results for %s\n", deviceName)
args := []string{"-a", "-j"} args := []string{"-a", "-j"}

@ -0,0 +1,15 @@
package detect_test
import (
"github.com/analogj/scrutiny/collector/pkg/detect"
"testing"
)
func TestDevicePrefix(t *testing.T) {
//setup
//test
//assert
require.Equal(t, "/dev/", detect.DevicePrefix())
}
Loading…
Cancel
Save