zabbix-zabbix上使用官方模版监控windows上的mysql数据库

    从zabbix3.4开始,zabbix上就自带mysql的监控模版,可以很方便对linux上的mysql数据库进行直接监控,基本不需要任何配置.但m是对windows上的mysql数据库却需要配置,不能直接进行监控。经过不断查询,找到了监控方法,参考https://blog.51cto.com/11575637/2056976


创建vbs脚本

在windows主机上,新建两个VB脚本,名称为mysql-ping.vbs和mysql-status.vbs,名称和路径自己可以随意定义,我的如下所示

image.png

mysql-ping.vbs脚本,主要是检测mysql程序是否存活,内容如下

Set objFS =CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqladmin.exe -uroot -pxxxxx ping")     #这里注意写明mysqladmin程序的绝对路径和root用户密码
 
If Instr(str1,"alive") > 0 Then
WScript.Echo 1
Else
WScript.Echo 0
End If
 
Function getCommandOutput(theCommand)
 
Dim objShell, objCmdExec
Set objShell =CreateObject("WScript.Shell")
Set objCmdExec = objshell.exec(thecommand)
getCommandOutput =objCmdExec.StdOut.ReadAll
end Function

mysql-status.vbs脚本,主要是配置zabbix键值,采集mysql相关状态

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqladmin.exe -uroot -pxxxx  extended-status")     #这里注意写明mysqladmin程序的绝对路径和root用户密码
Arg = objArgs(0)
str2 = Split(str1,"|")
 
For i = LBound(str2) to UBound(str2)
 
If Trim(str2(i)) = Arg Then   
WScript.Echo TRIM(str2(i+1))
Exit For
End If
next
 
 
Function getCommandOutput(theCommand)
 
Dim objShell, objCmdExec
Set objShell =CreateObject("WScript.Shell")
Set objCmdExec = objshell.exec(thecommand)
getCommandOutput =objCmdExec.StdOut.ReadAll
 
end Function


然后配置zabbix-agent程序配置文件

修改需要被监控的mysql所在服务器上的zabbix_agent.conf

UnsafeUserParameters=1


添加键值

UserParameter=mysql.status[*], cscript/nologo C:\Users\Administrator\Desktop\zabbix_agents_3.4.0.win\Scripts\mysql-status.vbs $1 
UserParameter=mysql.ping, cscript /nologo C:\Users\Administrator\Desktop\zabbix_agents_3.4.0.win\Scripts\mysql-ping.vbs


如下所示:

image.png

然后在zabbix服务器上哪测试

zabbix_get -s 172.31.102.111 -k mysql.ping
zabbix_get -s 172.31.102.111 -k mysql.status[Com_commit]

image.png


最后在zabbix服务上,套用mysql模版,同时自己绘制一套图形,最终结果如下所示:

image.png

猜你喜欢

转载自blog.51cto.com/11555417/2396170