問題描述
我需要能夠在 Zabbix 中監(jiān)控?cái)?shù)據(jù)庫文件空間.我已經(jīng)嘗試了許多用于監(jiān)控 SQL Server 的模板,但它們似乎沒有做我需要它們做的事情.本質(zhì)上,我需要知道特定數(shù)據(jù)庫的數(shù)據(jù)庫文件或日志文件(.mdf 或 .ldf)何時(shí)在一定百分比范圍內(nèi)已滿.
I need to be able to monitor database file space in Zabbix. I have tried out many of the templates for monitoring SQL Server and they don't seem to do what I need them to do. Essentially, I need to know when a database file or log file (.mdf or .ldf) for a particular database is within a certain percentage of being full.
基本上我希望:
- 發(fā)現(xiàn)服務(wù)器上每個(gè)數(shù)據(jù)庫中的所有數(shù)據(jù)和日志文件
- 為每個(gè)文件創(chuàng)建兩個(gè)項(xiàng)目,使用空間和最大空間(考慮自動(dòng)增長)
- 為每個(gè)文件創(chuàng)建一個(gè)觸發(fā)器,當(dāng)數(shù)據(jù)或日志文件處于已滿的特定百分比范圍內(nèi)時(shí)會(huì)提醒我(例如,80% 已滿警告,90% 嚴(yán)重)
由于我們的環(huán)境規(guī)模和網(wǎng)絡(luò)限制,不能使用 ODBC.我相信我需要使用 PowerShell 的某種類型的發(fā)現(xiàn)腳本,然后是另一個(gè)腳本來獲取項(xiàng)目的值,但我不確定.
Using ODBC is not an option due to the size of our environment and network restrictions. I believe I need some type of discovery script using PowerShell, then another script to fetch the values for the items, but I'm not sure.
推薦答案
不知道 Zabbix 是什么(稍后我會(huì)看一看),但在 SQL Server 中,你有 sp_MSforeachdb
No idea what Zabbix is (I'll take a peek later), but in SQL Server, you have sp_MSforeachdb
這里我們創(chuàng)建一個(gè)#Temp
表來收集服務(wù)器上每個(gè)數(shù)據(jù)庫的結(jié)果
Here we create a #Temp
table to collect the results from each database on the server
示例
Use Master;
Create table #Temp (DBName varchar(150),FileType varchar(50),MBytes bigint,MBytesMax bigint)
EXEC sp_MSforeachdb '
Insert Into #Temp
Select DBName = ''?''
,FileType = case when physical_name like ''%.mdf'' then ''Database'' else ''Log'' end
,MBytes = try_convert(bigint,size) * 8 / 1024
,MBytesMax = try_convert(bigint,max_size) * 8 / 1024
From [?].sys.database_files
'
Select *
,Pct = convert(decimal(10,1),(MBytes *100.0) / nullif(MBytesMax,0))
From #Temp
退貨
DBName FileType MBytes MBytesMax Pct
master Database 4 0 NULL
master Log 1 0 NULL
tempdb Database 816 0 NULL
tempdb Log 894 0 NULL
msdb Database 201 0 NULL
msdb Log 19 2097152 0.0
xxxxxxx Database 761 4096 18.6
xxxxxxx Log 1 2097152 0.0
yyyyyyy Database 533 4096 13.0
yyyyyyy Log 1 2097152 0.0
zzzzzzz Database 1641 4096 40.1
zzzzzzz Log 1 2097152 0.0
這篇關(guān)于如何使用 Zabbix 監(jiān)控?cái)?shù)據(jù)庫文件大小的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!