您的位置:首页 > 数据库 > SQL

zabbix监控mysql (windows平台下的mysql)

2021-04-23 22:02 1436 查看

zabbix 监控 windows上的mysql


一、前期准备。
1.zabbix-server服务端准备就绪。
2.准备zabbix-agent.win.conf文件。
3.在windows上开启zabbix-agent。

二、windows上安装mysql。
mysql 下载链接:http://soft.onlinedown.net/soft/3573.htm

安装成功,找到mysql的路径,比如我的:
C:\Program Files (x86)\MySQL\MySQL Server 5.7
cmd 运行

>cd C:\Program Files (x86)\MySQL\MySQL Server 5.7\bin 
>mysql (直接进入mysql,没有密码)

进入以后,创建监控用户zabbix

>grant all privileges on *.* to zabbix@'%' idenfitied by 'passwd';
>flush privileges;

写bat脚本,方便以后打开进入mysql的界面:

#mysqlstart.bat
echo off
cd /d C:\Program Files (x86)\MySQL\MySQL Server 5.7\bin
mysql -uzabbix -p
cmd

三、在MySQL服务器的 C:\Infinit-Server\zabbix\script 目录下新建三个脚本文件,获取数据。

  • mysql_ping.vbs
Set objFS =CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("C:\Program Files (x86)\MySQL\MySQL Server 5.7\bin mysqladmin.exe -umysql_monitor -pNt8eWv ping 2>c:\zabbix\warning.txt")
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
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("C:\Program Files (x86)\MySQL\MySQL Server 5.7\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.vbs
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("C:\Program Files (x86)\MySQL\MySQL Server 5.7\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

四、 在MySQL服务器上修改windows上的zabbix_agentd.win.conf文件
在zabbix_agentd.win.conf末尾处添加,此处的三个key要记住,后面需要在服务端添加监控项需要用到。

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

最后,重启zabbix-sgent,正常启动,如果不能启动,查看zabbix-agent.log,一般查看(10050端口是否打开、conf里的三个ip)。

五、在zabbix-server 上通过zabbix-get 看看能不能获取数据。

六、web 添加mysql主机,添加自定义的监控项、创建触发器、生成动作(告警信息)。


这里的键值和agent.conf里一致。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: