Skip to content

Commit

Permalink
Schedule Configuration & Service Config tool improvements.
Browse files Browse the repository at this point in the history
Allow easy configuration of collection schedules.
Improve service config tool to make it easier to add a large number of instances.
  • Loading branch information
DavidWiseman committed Oct 11, 2021
1 parent bbdc738 commit 2016aca
Show file tree
Hide file tree
Showing 30 changed files with 7,771 additions and 767 deletions.
23 changes: 17 additions & 6 deletions DBADash/CollectionConfig.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using DBADashService;
using Microsoft.SqlServer.Management.Smo;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using static DBADash.DBADashConnection;
using System.Linq;
using Serilog;

namespace DBADash
{

Expand Down Expand Up @@ -64,6 +64,19 @@ public class CollectionConfig:BasicConfig

public bool AutoUpdateDatabase { get; set; } = true;
public bool LogInternalPerformanceCounters = false;
public CollectionSchedules CollectionSchedules;

public CollectionSchedules GetSchedules()
{
if (CollectionSchedules == null)
{
return CollectionSchedules.DefaultSchedules;
}
else
{
return CollectionSchedules.CombineWithDefault();
}
}

public List<DBADashSource> SourceConnections = new List<DBADashSource>();

Expand Down Expand Up @@ -198,9 +211,9 @@ public DBADashSource GetSourceFromConnectionString(string connectionString,bool?

if (s.SourceConnection.Type == findConnection.Type)
{
if (s.SourceConnection.Type == ConnectionType.SQL && s.SourceConnection.DataSource() == findConnection.DataSource()) {
if (s.SourceConnection.Type == ConnectionType.SQL && s.SourceConnection.DataSource().ToLower() == findConnection.DataSource().ToLower()) {
// normally we can treat as same connection if we just vary by initial catalog. For AzureDB, a different DB is a different instance
if (s.SourceConnection.InitialCatalog() == findConnection.InitialCatalog()) {
if (s.SourceConnection.InitialCatalog().ToLower() == findConnection.InitialCatalog().ToLower()) {
return s;
}
else
Expand Down Expand Up @@ -285,7 +298,7 @@ public List<DBADashSource> GetNewAzureDBConnections(DBADashSource masterConnecti
builder.InitialCatalog = rdr.GetString(0);
DBADashSource dbCn = new DBADashSource(builder.ConnectionString)
{
Schedules = masterConnection.Schedules,
CollectionSchedules = masterConnection.CollectionSchedules,
SlowQueryThresholdMs = masterConnection.SlowQueryThresholdMs,
SlowQuerySessionMaxMemoryKB = masterConnection.SlowQuerySessionMaxMemoryKB,
UseDualEventSession = masterConnection.UseDualEventSession,
Expand All @@ -294,8 +307,6 @@ public List<DBADashSource> GetNewAzureDBConnections(DBADashSource masterConnecti
if (masterConnection.SchemaSnapshotDBs == "*")
{
dbCn.SchemaSnapshotDBs = masterConnection.SchemaSnapshotDBs;
dbCn.SchemaSnapshotCron = masterConnection.SchemaSnapshotCron;
dbCn.SchemaSnapshotOnServiceStart = masterConnection.SchemaSnapshotOnServiceStart;
}
if (!SourceExists(dbCn.SourceConnection.ConnectionString,true))
{
Expand Down
39 changes: 0 additions & 39 deletions DBADash/CollectionConfigSchedule.cs

This file was deleted.

128 changes: 128 additions & 0 deletions DBADash/CollectionSchedule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using DBADash;
using System.Collections.Generic;
using System.Linq;
namespace DBADashService
{

public class CollectionSchedules: Dictionary<CollectionType, CollectionSchedule>
{
private const string every1min = "0 * * ? * *";
private const string hourly = "0 0 * ? * *";
private const string midnight = "0 0 0 1/1 * ? *";
private const string elevenPm = "0 0 23 1/1 * ? *";

public static CollectionSchedules DefaultSchedules
= new CollectionSchedules() {
{CollectionType.ServerProperties, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.Databases, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.SysConfig, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.Drives, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.DBFiles, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.Backups, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.LogRestores, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.ServerExtraProperties, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.DBConfig, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.Corruption, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.OSInfo, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.TraceFlags, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.DBTuningOptions, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.AzureDBServiceObjectives, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.LastGoodCheckDB, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.Alerts, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.CustomChecks, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.DatabaseMirroring, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.Jobs, new CollectionSchedule(){ Schedule = hourly } },
{CollectionType.AzureDBResourceGovernance, new CollectionSchedule(){ Schedule = hourly } },

{CollectionType.ObjectExecutionStats, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.CPU, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.IOStats, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.Waits, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.AzureDBResourceStats, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.AzureDBElasticPoolResourceStats, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.SlowQueries, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.PerformanceCounters, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.JobHistory, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.RunningQueries, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.DatabasesHADR, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.AvailabilityGroups, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.AvailabilityReplicas, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },
{CollectionType.MemoryUsage, new CollectionSchedule(){ Schedule = every1min,RunOnServiceStart=false } },

{CollectionType.ServerPrincipals, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.ServerRoleMembers, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.ServerPermissions, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.DatabasePrincipals, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.DatabaseRoleMembers, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.DatabasePermissions, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.VLF, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.DriversWMI, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.OSLoadedModules, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.ResourceGovernorConfiguration, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.DatabaseQueryStoreOptions, new CollectionSchedule(){ Schedule = midnight } },
{CollectionType.SchemaSnapshot, new CollectionSchedule(){Schedule=elevenPm} }

};

public CollectionSchedules CombineWithDefault()
{
return Combine(DefaultSchedules, this);
}

public static CollectionSchedules Combine(CollectionSchedules baseSchedule, CollectionSchedules overrideSchedule)
{
var combined = new CollectionSchedules();
if (overrideSchedule != null)
{
foreach (var s in overrideSchedule)
{
combined.Add(s.Key, s.Value);
}
}
foreach (var s in baseSchedule) {
if (overrideSchedule==null || !overrideSchedule.ContainsKey(s.Key))
{
combined.Add(s.Key, s.Value);
}
}
return combined;
}

public Dictionary<string, CollectionType[]> GroupedBySchedule
{
get {
var groupedSchedule = new Dictionary<string, CollectionType[]>();
var schedules= this.Where(s=>s.Key != CollectionType.SchemaSnapshot).Select(s => s.Value.Schedule).Distinct().ToArray();
foreach(var schedule in schedules)
{
groupedSchedule.Add(schedule, this.Where(s => s.Value.Schedule == schedule).Select(s=>s.Key).ToArray());
}
return groupedSchedule;
}
}

public CollectionType[] OnServiceStartCollection
{
get
{
return this.Where(s => s.Key != CollectionType.SchemaSnapshot && s.Value.RunOnServiceStart).Select(s => s.Key).ToArray();
}
}

}

public class CollectionSchedule{

public string Schedule;
public bool RunOnServiceStart = true;

private const string every1min = "0 * * ? * *";

public static CollectionSchedule DefaultImportSchedule = new CollectionSchedule() { Schedule = every1min };



}


}
2 changes: 1 addition & 1 deletion DBADash/DBADash.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
<ItemGroup>
<Compile Include="AWSTools.cs" />
<Compile Include="CollectionConfig.cs" />
<Compile Include="CollectionConfigSchedule.cs" />
<Compile Include="CollectionSchedule.cs" />
<Compile Include="DBADashAgent.cs" />
<Compile Include="DBConnection.cs">
<SubType>Form</SubType>
Expand Down
Loading

0 comments on commit 2016aca

Please sign in to comment.