A DBA should be able to review every statement SQLInsight sends to a monitored server before granting it access. "SQL Scripts/<rule-id>.sql" holds, per rule (82 built-in, 16 community), a Danish header (what and why, how C# judges the data, thresholds with config keys, severity, exact GRANTs, versions, collector file and member) and the collector's SQL verbatim, every version variant as its own batch. "_collectors/<Collector>.sql" holds each collector's queries once. The only statement that is not strictly read-only is documented in the scripts: the deadlock collector's session temp table (#system_health). Inline SQL in the collectors moved to internal constants and Build*Sql methods (no text changed), so SqlScriptTests can check that the scripts still contain the SQL the code sends, that every rule has a script, that every collector query is registered, and that nothing writes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
53 lines
3.4 KiB
Transact-SQL
53 lines
3.4 KiB
Transact-SQL
-- ===================================================================================================================
|
|
-- Collector: ReplicationCollector ("replication")
|
|
-- ===================================================================================================================
|
|
-- Hvad: På en distributør: hver distributionsagents seneste status, forsinkelse og besked samt
|
|
-- replikeringsfejl det seneste døgn.
|
|
-- Fil: src/SQLInsight.Collectors/Instance/ReplicationCollector.cs
|
|
-- Interval: 15 min som standard (SQLInsight:CollectorIntervals:replication)
|
|
-- Versioner: SQL Server 2005 og nyere
|
|
--
|
|
-- Rettigheder til agentens login (se db/permissions/grant-least-privilege.sql; [agent] = agentens login):
|
|
-- GRANT VIEW ANY DEFINITION TO [agent]; -- metadata; giver IKKE adgang til data
|
|
-- Kun på en distributør, valgfrit (gives ikke af grant-least-privilege.sql):
|
|
-- USE distribution; CREATE USER [agent] FOR LOGIN [agent];
|
|
-- GRANT SELECT ON dbo.MSdistribution_agents TO [agent]; GRANT SELECT ON dbo.MSdistribution_history TO [agent]; GRANT SELECT ON dbo.MSrepl_errors TO [agent];
|
|
--
|
|
-- Bruges af: SQLI-REPL-001, SQLI-REPL-002
|
|
-- Read-only: Ja: kun SELECT samt USE (skifter sessionens database), SET-sessionsindstillinger. Intet ændrer data,
|
|
-- indstillinger eller objekter.
|
|
-- Kørsel: Kør i SSMS som agentens login. Hver variant er sin egen batch (GO); en variant for en anden SQL Server-version
|
|
-- end din kan fejle - det er forventet. Agenten kører altid med sessionsindstillingerne i _collectors/InstanceProbe.sql.
|
|
-- ===================================================================================================================
|
|
|
|
-- Variant: SQL Server 2005 og nyere
|
|
-- Kilde: ReplicationCollector.DistributionDatabaseSql
|
|
-- Kode: src/SQLInsight.Collectors/Instance/ReplicationCollector.cs : ReplicationCollector.DistributionDatabaseSql
|
|
SELECT TOP 1 name FROM sys.databases WHERE is_distributor = 1 AND state = 0
|
|
GO
|
|
|
|
-- Variant: Kun på en distributør: husk databasen, der skal skiftes tilbage til
|
|
-- Kilde: ReplicationCollector.CurrentDatabaseSql
|
|
-- Kode: src/SQLInsight.Collectors/Db.cs : Db.CurrentDatabaseSql
|
|
SELECT DB_NAME()
|
|
GO
|
|
|
|
-- Variant: Kun på en distributør, i distributionsdatabasen
|
|
-- Kilde: ReplicationCollector.AgentsSql
|
|
-- Kode: src/SQLInsight.Collectors/Instance/ReplicationCollector.cs : ReplicationCollector.AgentsSql
|
|
-- Agenten sender "USE [<distributionsdatabasen>];" foran (navnet fra DistributionDatabaseSql). Ret navnet, hvis det ikke er distribution.
|
|
USE [distribution];
|
|
SELECT TOP 500 a.name, a.publisher_db, h.runstatus, DATEADD(minute, DATEDIFF(minute, GETDATE(), GETUTCDATE()), h.time), h.delivery_latency,
|
|
CAST(h.comments AS nvarchar(500))
|
|
FROM dbo.MSdistribution_agents a
|
|
OUTER APPLY (SELECT TOP 1 x.runstatus, x.time, x.delivery_latency, x.comments FROM dbo.MSdistribution_history x
|
|
WHERE x.agent_id = a.id ORDER BY x.timestamp DESC) h
|
|
GO
|
|
|
|
-- Variant: Kun på en distributør, i distributionsdatabasen
|
|
-- Kilde: ReplicationCollector.ErrorsSql
|
|
-- Kode: src/SQLInsight.Collectors/Instance/ReplicationCollector.cs : ReplicationCollector.ErrorsSql
|
|
-- Agenten sender "USE [<distributionsdatabasen>];" foran (navnet fra DistributionDatabaseSql). Ret navnet, hvis det ikke er distribution.
|
|
USE [distribution];
|
|
SELECT COUNT(*) FROM dbo.MSrepl_errors WHERE time > DATEADD(hour, -24, GETDATE())
|
|
GO
|