using SQLInsight.Core.Data; namespace SQLInsight.Collectors.Instance; public sealed class ConfigurationCollector : Collector { internal const string Sql2005 = "SELECT name, CAST(value AS bigint), CAST(value_in_use AS bigint) FROM sys.configurations"; // What sp_configure itself reads on SQL Server 2000. internal const string Sql2000 = """ SELECT v.name, CAST(c.value AS bigint), CAST(r.value AS bigint) FROM master.dbo.spt_values v JOIN master.dbo.sysconfigures c ON c.config = v.number JOIN master.dbo.syscurconfigs r ON r.config = v.number WHERE v.type = 'C' """; public override string Name => "configuration"; public override TimeSpan DefaultInterval => TimeSpan.FromMinutes(15); protected override async Task CollectAsync(CollectorContext context, ConfigurationSnapshot? previous) { var sql = context.Instance.Version.Major >= 9 ? Sql2005 : Sql2000; var options = await Db.QueryAsync(context.Connection, sql, r => new ConfigurationOption(r.String(0), r.Long(1), r.Long(2)), context.CancellationToken) .ConfigureAwait(false); return new ConfigurationSnapshot { CapturedAt = context.Now, Options = options }; } }