zabbix监控windows下的mysql

1.创建监控账号

GRANT SELECT,PROCESS,REPLICATION CLIENT ON *.* TO zabbix@'localhost' IDENTIFIED BY 'zabbix';

2.创建脚本文件(mysql路径按照自己的安装路径)
在D:\zabbix-agent\conf下创建
ping.vbs

Set objFS =CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("D:\software\mysql5.6.26\mysql-5.6.26-winx64\bin\mysqladmin.exe -uzabbix -pzabbix")

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

status.vbs

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("D:\software\mysql5.6.26\mysql-5.6.26-winx64\bin\mysqladmin.exe -uzabbix -pzabbix extended-status")
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
' Wscript.Echo getCommandOutput 
end Function

version.vbs

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("D:\software\mysql5.6.26\mysql-5.6.26-winx64\bin\mysql.exe -V")

WScript.Echo str1

Function getCommandOutput(theCommand)
Dim objShell, objCmdExec
Set objShell = CreateObject("WScript.Shell")
Set objCmdExec = objshell.exec(thecommand)
getCommandOutput = objCmdExec.StdOut.ReadAll
end Function

3.修改zabbix_agentd.win.conf
在zabbix_agentd.win.conf末尾处添加

UnsafeUserParameters=1
UserParameter=mysql.status[*], cscript/nologo D:\zabbix-agent\conf\status.vbs $1 
UserParameter=mysql.ping, cscript /nologo D:\zabbix-agent\conf\ping.vbs
UserParameter=mysql.version, cscript /nologo  D:\zabbix-agent\conf\version.vbs

4.在zabbix界面添加自带模板Template App MySQL
5.重启zabbix agent

猜你喜欢

转载自blog.csdn.net/u014609263/article/details/91375611