How to monitor database file size using Zabbix(如何使用 Zabbix 监控数据库文件大小)
问题描述
我需要能够在 Zabbix 中监控数据库文件空间.我已经尝试了许多用于监控 SQL Server 的模板,但它们似乎没有做我需要它们做的事情.本质上,我需要知道特定数据库的数据库文件或日志文件(.mdf 或 .ldf)何时在一定百分比范围内已满.
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.
基本上我希望:
- 发现服务器上每个数据库中的所有数据和日志文件
- 为每个文件创建两个项目,使用空间和最大空间(考虑自动增长)
- 为每个文件创建一个触发器,当数据或日志文件处于已满的特定百分比范围内时会提醒我(例如,80% 已满警告,90% 严重)
由于我们的环境规模和网络限制,不能使用 ODBC.我相信我需要使用 PowerShell 的某种类型的发现脚本,然后是另一个脚本来获取项目的值,但我不确定.
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 是什么(稍后我会看一看),但在 SQL Server 中,你有 sp_MSforeachdb
No idea what Zabbix is (I'll take a peek later), but in SQL Server, you have sp_MSforeachdb
这里我们创建一个#Temp表来收集服务器上每个数据库的结果
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
这篇关于如何使用 Zabbix 监控数据库文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Zabbix 监控数据库文件大小
基础教程推荐
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
