Zabbix 监控 Windows下MySQL

1. 在MySQL里建立监控的帐号

GRANT PROCESS,REPLICATION CLIENT ON *.* TO mysql_monitor@'localhost' IDENTIFIED BY 'Nt8eWv';

# process经过这个权限,用户能够执行SHOW PROCESSLIST和KILL命令。 # replication client拥有此权限能够查询master server、slave server状态。

2. 在MySQL服务器的 C:\Infinit-Server\zabbix\script 目录下新建三个脚本文件

mysql_ping.vbsmysql

Set objFS =CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqladmin.exe -umysql_monitor -pNt8eWv ping")

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.vbsweb

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqladmin.exe -umysql_monitor -pNt8eWv 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 //这一句能够打印出全部内容,执行 mysql_status.vbs $1 便可
end Function


mysql_version.vbssql

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("C:\Program Files\MySQL\MySQL Server 5.5\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. 在MySQL服务器上修改windows上的zabbix_agentd.win.conf文件

在zabbix_agentd.win.conf末尾处添加shell

UnsafeUserParameters=1
UserParameter=mysql.status[*], cscript/nologo C:\Infinit-Server\zabbix\script\mysql_status.vbs $1 UserParameter=mysql.ping, cscript /nologo C:\Infinit-Server\zabbix\script\mysql_ping.vbs UserParameter=mysql.version, cscript /nologo C:\Infinit-Server\zabbix\script\mysql_version.vbs

4. 在zabbix主机测试并添加模板

测试是否能从脚本获取到数据windows

/usr/bin/zabbix_get -s 192.168.10.61 -k "mysql.ping"
/usr/bin/zabbix_get -s 192.168.10.61 -k "mysql.version"
/usr/bin/zabbix_get -s 192.168.10.61 -k "mysql.status[Bytes_received]"

重启zabbix_agentd,并给主机添加Template App MySQL模版,查看items状态服务器

监控项目:svg

Com_update:     mysql执行的更新个数
Com_select:     mysql执行的查询个数
Com_insert:     mysql执行插入的个数
Com_delete:     执行删除的个数
Com_rollback:   执行回滚的操做个数
Bytes_received:  接受的字节数
Bytes_sent:     发送的字节数
Slow_queries:   慢查询语句的个数
Com_commit:     确认的事物个数
Com_begin:      开始的事物个数
Uptime:         服务器已启动的秒数
Questions:      客户端发送到服务器的语句个数
相关文章
相关标签/搜索