in internal/sqlservermetrics/sqlservermetrics.go [147:176]
func CollectionService(p string, collection func(cfg *configpb.Configuration, onetime bool) error, collectionType CollectionType) {
for {
cfg, err := LoadConfiguration(p)
if cfg == nil {
log.Logger.Errorw("Failed to load configuration", "error", err)
UsageMetricsLogger.Error(agentstatus.ProtoJSONUnmarshalError)
time.Sleep(time.Duration(time.Hour))
continue
}
// Init UsageMetricsLogger for each collection cycle.
UsageMetricsLogger = UsageMetricsLoggerInit(internal.ServiceName, internal.AgentVersion, internal.AgentUsageLogPrefix, !cfg.GetDisableLogUsage())
// Set onetime to false for running collection as service
if err := collection(cfg, false); err != nil {
log.Logger.Errorw("Failed to run collection", "collection type", collectionType, "error", err)
if collectionType == OS {
UsageMetricsLogger.Error(agentstatus.GuestCollectionFailure)
} else {
UsageMetricsLogger.Error(agentstatus.SQLCollectionFailure)
}
time.Sleep(time.Duration(time.Hour))
continue
}
// Sleep for collection interval.
if collectionType == OS {
time.Sleep(time.Duration(cfg.GetCollectionConfiguration().GetGuestOsMetricsCollectionIntervalInSeconds()) * time.Second)
} else if collectionType == SQL {
time.Sleep(time.Duration(cfg.GetCollectionConfiguration().GetSqlMetricsCollectionIntervalInSeconds()) * time.Second)
}
}
}