如何使用 Zabbix 监控数据库文件大小 [英] How to monitor database file size using Zabbix

查看:25
本文介绍了如何使用 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.

基本上我希望:

  1. 发现服务器上每个数据库中的所有数据和日志文件
  2. 为每个文件创建两个项目,使用空间和最大空间(考虑自动增长)
  3. 为每个文件创建一个触发器,当数据或日志文件处于已满的特定百分比范围内时会提醒我(例如,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 监控数据库文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆