Skip to content

Commit

Permalink
Merge pull request #40 from marcingminski/development
Browse files Browse the repository at this point in the history
Merge into master
  • Loading branch information
marcingminski authored Sep 14, 2018
2 parents e9857bd + 2aeae64 commit b85b0cc
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 23 deletions.
Binary file modified SQL Performance Dashboard.pbit
Binary file not shown.
23 changes: 23 additions & 0 deletions SQLWATCHDB/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Reflection;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with the SQLCLR assembly.
[assembly: AssemblyTitle("SQLWATCH")]
[assembly: AssemblyDescription("https://sqlwatch.io")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SQLWATCH")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]
45 changes: 45 additions & 0 deletions SQLWATCHDB/SQLWATCH.refactorlog
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<Operations Version="1.0" xmlns="http://schemas.microsoft.com/sqlserver/dac/Serialization/2012/02">
<Operation Name="Rename Refactor" Key="c534c532-3535-4583-b656-4313fd610487" ChangeDateTime="09/10/2018 00:44:04">
<Property Name="ElementName" Value="[dbo].[logger_disk_utilisation_database].[database_size_mb]" />
<Property Name="ElementType" Value="SqlSimpleColumn" />
<Property Name="ParentElementName" Value="[dbo].[logger_disk_utilisation_database]" />
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="[database_size_bytes]" />
</Operation>
<Operation Name="Rename Refactor" Key="cd735168-9dc3-4663-ab30-0dc80b6b0299" ChangeDateTime="09/10/2018 00:44:22">
<Property Name="ElementName" Value="[dbo].[logger_disk_utilisation_database].[unallocated_space_mb]" />
<Property Name="ElementType" Value="SqlSimpleColumn" />
<Property Name="ParentElementName" Value="[dbo].[logger_disk_utilisation_database]" />
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="[unallocated_space_bytes]" />
</Operation>
<Operation Name="Rename Refactor" Key="273db7fd-a1aa-4037-8f92-591d2ce83321" ChangeDateTime="09/10/2018 00:44:37">
<Property Name="ElementName" Value="[dbo].[logger_disk_utilisation_database].[reserved_kb]" />
<Property Name="ElementType" Value="SqlSimpleColumn" />
<Property Name="ParentElementName" Value="[dbo].[logger_disk_utilisation_database]" />
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="[reserved_bytes]" />
</Operation>
<Operation Name="Rename Refactor" Key="8081db13-e048-4c18-acf2-42c777f82979" ChangeDateTime="09/10/2018 00:44:44">
<Property Name="ElementName" Value="[dbo].[logger_disk_utilisation_database].[data_kb]" />
<Property Name="ElementType" Value="SqlSimpleColumn" />
<Property Name="ParentElementName" Value="[dbo].[logger_disk_utilisation_database]" />
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="[data_bytes]" />
</Operation>
<Operation Name="Rename Refactor" Key="76b6643e-0886-492b-b6c5-3b3922613175" ChangeDateTime="09/10/2018 00:44:55">
<Property Name="ElementName" Value="[dbo].[logger_disk_utilisation_database].[index_size_kb]" />
<Property Name="ElementType" Value="SqlSimpleColumn" />
<Property Name="ParentElementName" Value="[dbo].[logger_disk_utilisation_database]" />
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="[index_size_bytes]" />
</Operation>
<Operation Name="Rename Refactor" Key="98d2b180-f8d9-466a-ae84-e61b01395f6e" ChangeDateTime="09/10/2018 00:45:02">
<Property Name="ElementName" Value="[dbo].[logger_disk_utilisation_database].[unused_kb]" />
<Property Name="ElementType" Value="SqlSimpleColumn" />
<Property Name="ParentElementName" Value="[dbo].[logger_disk_utilisation_database]" />
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="[unused_bytes]" />
</Operation>
</Operations>
26 changes: 25 additions & 1 deletion SQLWATCHDB/SQLWATCH.sqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<DefineTrace>true</DefineTrace>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunSqlCodeAnalysis>False</RunSqlCodeAnalysis>
</PropertyGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
Expand Down Expand Up @@ -90,7 +91,10 @@
<Build Include="dbo\Procedures\sp_sql_perf_mon_logger.sql" />
<Build Include="dbo\Procedures\sp_sql_perf_mon_retention.sql" />
<Build Include="dbo\Procedures\sp_sql_perf_mon_add_database.sql" />
<Build Include="dbo\Tables\sql_perf_mon_config_snapshot_header_type.sql" />
<Build Include="dbo\Tables\sql_perf_mon_config_snapshot_type.sql" />
<Build Include="dbo\Tables\sql_perf_mon_master_files.sql" />
<Build Include="dbo\Tables\logger_disk_utilisation_database.sql" />
<Build Include="dbo\Procedures\usp_logger_disk_utilisation.sql" />
</ItemGroup>
<ItemGroup>
<PostDeploy Include="Script.PostDeployment1.sql" />
Expand All @@ -107,4 +111,24 @@
<DatabaseVariableLiteralValue>msdb</DatabaseVariableLiteralValue>
</ArtifactReference>
</ItemGroup>
<ItemGroup>
<RefactorLog Include="SQLWATCH.refactorlog" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Target Name="SetDacVersionToAssemblyVersion" AfterTargets="CoreCompile">
<GetAssemblyIdentity AssemblyFiles="$(IntermediateTargetFullFileName)">
<Output TaskParameter="Assemblies" PropertyName="IntermediateTargetAssembly" />
</GetAssemblyIdentity>
<PropertyGroup>
<DacVersion>
$(IntermediateTargetAssembly.Split(',')[1].Split('=')[1])
</DacVersion>
</PropertyGroup>
<Message Text="DacVersion set to $(DacVersion)" Importance="high" />
</Target>
</Project>
4 changes: 4 additions & 0 deletions SQLWATCHDB/SQLWATCH.sqlproj.user
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<StartupScript>(Blank)</StartupScript>
<StartAction>StartNone</StartAction>
</PropertyGroup>
</Project>
86 changes: 78 additions & 8 deletions SQLWATCHDB/Script.PostDeployment1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ if (select count(*) from [dbo].[sql_perf_mon_config_who_is_active_age]) = 0
--------------------------------------------------------------------------------------
--
--------------------------------------------------------------------------------------
/* databases with create_date = '1970-01-01' are from previous
versions of SQLWATCH and we will now update create_date to the actual
create_date (this will only apply to upgrades) */
update swd
set [database_create_date] = db.[create_date]
from [dbo].[sql_perf_mon_database] swd
inner join sys.databases db
on db.[name] = swd.[database_name]
and swd.[database_create_date] = '1970-01-01'

/* now add new databases */
exec [dbo].[sp_sql_perf_mon_add_database]

--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -50,7 +61,7 @@ create nonclustered index tmp_idx_sql_perf_mon_perf_counters_types on #sql_perf_
/* based on https://blogs.msdn.microsoft.com/dfurman/2015/04/02/collecting-performance-counter-values-from-a-sql-azure-database/ */
insert into #sql_perf_mon_config_perf_counters([collect],[object_name],[counter_name], [instance_name],[base_counter_name])
values
(0,'Access Methods','Forwarded Records/sec','',NULL)
(0,'Access Methods','Forwarded Records/sec','',NULL)
,(1,'Access Methods','Full Scans/sec','',NULL)
,(1,'Access Methods','Page Splits/sec','',NULL)
,(1,'Access Methods','Pages Allocated/sec','',NULL)
Expand Down Expand Up @@ -619,14 +630,23 @@ if (select count(*) from [dbo].[sql_perf_mon_config_report_time_interval]) = 0
end

--------------------------------------------------------------------------------------
--
-- add snapshot types
--------------------------------------------------------------------------------------
if (select count(*) from [dbo].[sql_perf_mon_config_snapshot_type]) = 0
begin
insert into [dbo].[sql_perf_mon_config_snapshot_type]
values (1, 'Performance', 7),
(2, 'Growth', 365)
end
;merge [dbo].[sql_perf_mon_config_snapshot_type] as target
using (
/* performance data logger */
select [snapshot_type_id] = 1, [snapshot_type_desc] = 'Performance', [snapshot_retention_days] = 7
union
/* size data logger */
select [snapshot_type_id] = 2, [snapshot_type_desc] = 'Disk Utilisation', [snapshot_retention_days] = 365
) as source
on (source.[snapshot_type_id] = target.[snapshot_type_id])
when matched and source.[snapshot_type_desc] <> target.[snapshot_type_desc] then
update set [snapshot_type_desc] = source.[snapshot_type_desc]
when not matched then
insert ([snapshot_type_id],[snapshot_type_desc],[snapshot_retention_days])
values (source.[snapshot_type_id],source.[snapshot_type_desc],source.[snapshot_retention_days])
;

--------------------------------------------------------------------------------------
--
Expand Down Expand Up @@ -791,3 +811,53 @@ if (select name from sysjobs where name = 'DBA-PERF-AUTO-CONFIG') is null
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT
select @schedule_id
end

if (select name from sysjobs where name = 'SQLWATCH-LOGGER-DISK-UTILISATION') is null
begin
set @jobId = null
EXEC msdb.dbo.sp_add_job @job_name=N'SQLWATCH-LOGGER-DISK-UTILISATION',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=2,
@notify_level_page=2,
@delete_level=0,
@category_name=N'Data Collector',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
EXEC msdb.dbo.sp_add_jobserver @job_name=N'SQLWATCH-LOGGER-DISK-UTILISATION', @server_name = @server;
EXEC msdb.dbo.sp_add_jobstep @job_name=N'SQLWATCH-LOGGER-DISK-UTILISATION', @step_name=N'exec dbo.usp_logger_disk_utilisation',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_fail_action=2,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'exec [dbo].[usp_logger_disk_utilisation]',
@database_name=@database,
@flags=0
EXEC msdb.dbo.sp_update_job @job_name=N'SQLWATCH-LOGGER-DISK-UTILISATION',
@enabled=1,
@start_step_id=1,
@notify_level_eventlog=0,
@notify_level_email=2,
@notify_level_page=2,
@delete_level=0,
@description=N'',
@category_name=N'Data Collector',
@owner_login_name=N'sa',
@notify_email_operator_name=N'',
@notify_page_operator_name=N''
set @schedule_id = null
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'SQLWATCH-LOGGER-DISK-UTILISATION', @name=N'SQLWATCH-LOGGER-DISK-UTILISATION',
@enabled=1,
@freq_type=4,
@freq_interval=1,
@freq_subday_type=8,
@freq_subday_interval=1,
@freq_relative_interval=0,
@freq_recurrence_factor=1,
@active_start_date=20180909,
@active_end_date=99991231,
@active_start_time=437,
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT
end
Binary file modified SQLWATCHDB/bin/Debug/SQLWATCH.dacpac
Binary file not shown.
Binary file modified SQLWATCHDB/bin/Debug/SQLWATCHDB.dll
Binary file not shown.
38 changes: 27 additions & 11 deletions SQLWATCHDB/dbo/Procedures/sp_sql_perf_mon_add_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,36 @@ as
set nocount on;

declare @databases table (
[database_name] sysname primary key
)
[database_name] sysname not null,
[database_create_date] datetime not null default '1970-01-01',
primary key clustered (
[database_name],[database_create_date]
)
)

insert into @databases
select [name] from sys.databases
select [name], [create_date]
from sys.databases
union all
/* mssqlsystemresource database appears in the performance counters
so we need it as a dimensions to be able to filter in the report */
select 'mssqlsystemresource'
select 'mssqlsystemresource', '1970-01-01'

;merge [dbo].[sql_perf_mon_database] as target
using @databases as source
on (
source.[database_name] = target.[database_name]
and source.[database_create_date] = target.[database_create_date]
)
/* dropped databases are going to be updated to current = 0 */
when not matched by source then
update set [database_current] = 0
/* new databases are going to be inserted */
when not matched by target then
insert ([database_name], [database_create_date])
values (source.[database_name], source.[database_create_date]);

insert into [dbo].[sql_perf_mon_database]
select s.[database_name]
from @databases s
left join [dbo].[sql_perf_mon_database] t
on s.[database_name] = t.[database_name]
where t.[database_name] is null

/* the above only accounts for databases that have been removed and re-added
if you rename database it will be treated as if it was removed and new
database created so you will lose history continuation. Why would you
rename a database anyway */
3 changes: 1 addition & 2 deletions SQLWATCHDB/dbo/Procedures/sp_sql_perf_mon_logger.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare @sql nvarchar(4000)
--------------------------------------------------------------------------------------------------------------
-- detect which version of sql we are running as some dmvs are different in different versions of sql
--------------------------------------------------------------------------------------------------------------
set @product_version = convert(nvarchar(128),serverproperty('productversioN'));
set @product_version = convert(nvarchar(128),serverproperty('productversion'));

select
@product_version_major = substring(@product_version, 1,charindex('.', @product_version) + 1 )
Expand Down Expand Up @@ -56,7 +56,6 @@ declare @sql nvarchar(4000)
set @date_snapshot_current = getdate();
insert into [dbo].[sql_perf_mon_snapshot_header]
values (@date_snapshot_current, 1)


--------------------------------------------------------------------------------------------------------------
-- 1. get cpu
Expand Down
Loading

0 comments on commit b85b0cc

Please sign in to comment.