基于生產環(huán)境 SQL Server 業(yè)務數(shù)據(jù)庫的特性,需要針對 SQL Server 生產環(huán)境幾組 AlwaysOn AG 的 Primary Replica 部署如下監(jiān)控:
1. Windows集群節(jié)點不正常
2. 任一業(yè)務數(shù)據(jù)庫沒加入可用性組
3. AG中任一數(shù)據(jù)庫狀態(tài)異常
4. 任一數(shù)據(jù)庫延時超過閾值
目前創(chuàng)新互聯(lián)已為近千家的企業(yè)提供了網站建設、域名、網站空間、網站托管運營、企業(yè)網站設計、平羅網站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
1. primary replica 檢查Windows集群狀態(tài)不正常的節(jié)點數(shù)(>0 告警)
SELECT COUNT (*) as NotHealtyCount FROM sys.dm_hadr_cluster_members WHERE member_state_desc !='UP';
2. primary replica 檢查副本可用數(shù)據(jù)庫個數(shù) 與 需要加入AG的業(yè)務數(shù)據(jù)庫數(shù) 對比 (<后者告警)
SELECT COUNT(*) as DBCount FROM sys.availability_databases_cluster;
3. primary replica 檢查任一數(shù)據(jù)庫狀態(tài)異常(>0 告警)
SELECT COUNT (*) as NotHealtyCount FROM [master].[sys].[dm_hadr_database_replica_states] WHERE [synchronization_health_desc] != N'HEALTHY'
4. primary replica 檢查任一數(shù)據(jù)庫延時(>900 告警)
;WITH AG_Stats AS ( SELECT AR.replica_server_name, HARS.role_desc, Db_name(DRS.database_id) [DBName], DRS.last_commit_time FROM sys.dm_hadr_database_replica_states DRS INNER JOIN sys.availability_replicas AR ON DRS.replica_id = AR.replica_id INNER JOIN sys.dm_hadr_availability_replica_states HARS ON AR.group_id = HARS.group_id AND AR.replica_id = HARS.replica_id ), Pri_CommitTime AS ( SELECTreplica_server_name , DBName , last_commit_time FROMAG_Stats WHERErole_desc = 'PRIMARY' ), Sec_CommitTime AS ( SELECTreplica_server_name , DBName , last_commit_time FROMAG_Stats WHERErole_desc = 'SECONDARY' ) SELECT ISNULL(DATEDIFF(ss,s.last_commit_time,p.last_commit_time),0) AS [Sync_Lag_Secs] FROM Pri_CommitTime p LEFT JOIN Sec_CommitTime s ON [s].[DBName] = [p].[DBName]
Zabbix參數(shù)配置示例:
UserParameter=MSSQL.SyncHealth,"C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\SQLCMD.EXE" -d Master -U zabbix -P zabbix -h -1 -W -Q "SELECT COUNT (*) as NotHealtyCount
FROM [master].[sys].[dm_hadr_database_replica_states]
WHERE [synchronization_health_desc] != N''HEALTHY''
"
建議,將1、3、4項配置為模板,2項需要單獨配置4個參數(shù)。