zabbix監控mysql (windows平臺下的mysql)

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裏一致。
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章