in internal/sqlservermetrics/sqlservermetrics_linux.go [47:101]
func OSCollection(ctx context.Context, path, logPrefix string, cfg *configpb.Configuration, onetime bool) error {
if !cfg.GetCollectionConfiguration().GetCollectGuestOsMetrics() {
return nil
}
if cfg.GetRemoteCollection() {
return fmt.Errorf("remote collection from a linux vm is not supported; please use a windows vm to collect on other remote machines or turn off the remote collection flag")
}
if cfg.GetCredentialConfiguration() == nil || len(cfg.GetCredentialConfiguration()) == 0 {
return fmt.Errorf("empty credentials")
}
wlm, err := initCollection(ctx)
if err != nil {
return err
}
if !onetime {
if err := checkAgentStatus(wlm, path); err != nil {
return err
}
}
log.Logger.Info("Guest os rules collection starts.")
// only local collection is supported for linux binary.
// therefore we only get the first credential from cred list and ignore the followings.
credentialCfg := cfg.GetCredentialConfiguration()[0]
guestCfg := guestConfigFromCredential(credentialCfg)
if err := validateCredCfgGuest(false, !guestCfg.LinuxRemote, guestCfg, credentialCfg.GetInstanceId(), credentialCfg.GetInstanceName()); err != nil {
return err
}
sourceInstanceProps := SIP
targetInstanceProps := sourceInstanceProps
disks, err := allDisks(ctx, targetInstanceProps)
if err != nil {
return fmt.Errorf("failed to collect disk info: %w", err)
}
c := guestcollector.NewLinuxCollector(disks, "", "", "", false, 22, UsageMetricsLogger)
timeout := time.Duration(cfg.GetCollectionTimeoutSeconds()) * time.Second
details := runOSCollection(ctx, c, timeout)
updateCollectedData(wlm, sourceInstanceProps, targetInstanceProps, details)
if onetime {
target := "localhost"
persistCollectedData(wlm, filepath.Join(filepath.Dir(logPrefix), fmt.Sprintf("%s-%s.json", target, "guest")))
} else {
log.Logger.Debugf("Source vm %s is sending os collected data on target machine, %s, to workload manager.", sourceInstanceProps.Instance, targetInstanceProps.Instance)
interval := time.Duration(cfg.GetRetryIntervalInSeconds()) * time.Second
sendRequestToWLM(wlm, sourceInstanceProps.Name, cfg.GetMaxRetries(), interval)
}
log.Logger.Info("Guest os rules collection ends.")
return nil
}