func()

in internal/sqlservermetrics/sqlservermetrics_linux.go [34:74]


func (s *SQLServerMetrics) osCollection(ctx context.Context) error {
	if !s.Config.GetCollectionConfiguration().GetCollectGuestOsMetrics() {
		return nil
	}

	wlm, err := s.initCollection(ctx, false)
	if err != nil {
		usagemetrics.Error(usagemetrics.WorkloadManagerConnectionError)
		return err
	}

	// only local collection is supported for linux binary.
	// therefore we only get the first credential from cred list and ignore the followings.
	credentialCfg := s.Config.GetCredentialConfigurations()[0]
	guestCfg := guestConfigFromCredential(credentialCfg)
	if err := validateCredCfgGuest(false, !guestCfg.LinuxRemote, guestCfg, credentialCfg.GetVmProperties().GetInstanceId(), credentialCfg.GetVmProperties().GetInstanceName()); err != nil {
		usagemetrics.Error(usagemetrics.SQLServerInvalidConfigurationsError)
		return err
	}

	targetInstanceProps := sip
	disks, err := allDisks(ctx, targetInstanceProps)
	if err != nil {
		return fmt.Errorf("failed to collect disk info: %w", err)
	}

	c := guestoscollector.NewLinuxCollector(disks, "", "", "", false, 22)
	details := []sqlserverutils.MetricDetails{}
	log.Logger.Debug("Collecting guest rules")
	details = append(details, c.CollectGuestRules(ctx, s.Config.GetCollectionTimeout().AsDuration()))
	if err := guestoscollector.UnknownOsFields(&details); err != nil {
		log.Logger.Warnf("RunOSCollection: Failed to mark unknown collected fields. error: %v", err)
	}
	log.Logger.Debug("Collecting guest rules completes")
	updateCollectedData(wlm, sip, targetInstanceProps, details)

	log.Logger.Debugf("Source vm %s is sending os collected data on target machine, %s, to workload manager.", sip.Instance, targetInstanceProps.Instance)
	sendRequestToWLM(ctx, wlm, sip.Name, s.Config.GetMaxRetries(), s.Config.GetRetryFrequency().AsDuration())

	return nil
}