Using official template to monitor mysql database on windows on ZABBIX ZABBIX

Starting from zabbix 3.4, zabbix has its own monitoring template for mysql, which is convenient for direct monitoring of mysql database on linux without any configuration. However, m is required for mysql database on windows, which cannot be directly monitored. After continuous inquiry, the monitoring method has been found, refer to https://blog.51cto.com/11575637/2056976


Create vbs script

On the windows host, create two new VB scripts named mysql-ping.vbs and mysql-status.vbs. The names and paths can be defined at will. My scripts are as follows

The mysql-ping.vbs script is mainly used to check whether the MySQL program survives. The content is as follows

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")     #Note the absolute path and root password of mysqladmin program
 
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

The mysql-status.vbs script is mainly used to configure the zabbix key value and collect MySQL related status

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")     #Note the absolute path and root password of mysqladmin program
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


Then configure the ZABBIX agent configuration file

stay

Modify ZABBIX [agent.conf] on the server where mysql needs to be monitored

UnsafeUserParameters=1


Add key value

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


As follows:

Then where to test on zabbix server

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


Finally, on the zabbix service, apply mysql template and draw a set of graphs by yourself. The final results are as follows:

Tags: Operation & Maintenance MySQL Zabbix mysqladmin Database

Posted on Sat, 09 Nov 2019 08:20:42 -0800 by babygodzilla