Most of available mysql monitoring template uses one user parameter per item. To collect values for 10 items, they will run 10 mysql command (or same command 10 times and get extract desired information from result). These monitoring templates instead get complete result in one item as json content and then uses dependent items to create multiple items on zabbix server
Github links:
Installation
- Zabbix client (mysql slave server) host must have jq installed. If not, please install using
- Add following line in zabbix client configuration. Mysql credentials are stored in /etc/zabbix/.my.cnf for me. Make sure zabbix user has read access to mysql password file
- Myql Template
- Mysql Slave Template
- Import template into zabbix
- Apply "Mysql Slave" template to any mysql slave
sudo apt install jq
UserParameter=Mysql.Server-Status, mysql --defaults-file=/etc/zabbix/.my.cnf --defaults-group-suffix=_monitoring -N -e "show global status" | jq -c '. | split("\n")[:-1] | map (split("\t") | {(.[0]) : .[1]} ) | add ' -R -s
UserParameter=Mysql.Slave-Status, mysql --defaults-file=/etc/zabbix/.my.cnf --defaults-group-suffix=_monitoring -e "show slave status \G" | sed -e "s/^\s*//g" | sed -e "s/:\s*/:/g" | jq -c '. | split("\n")[1:-1] | map (split(":") | {(.[0]) : .[1]} ) | add ' -R -s
Template Contents
Mysql Template: Items |
Mysql Template Triggers |
Mysql Tempalte Graph |
Mysql Slave Template Items |
Mysql Slave Tempalte Triggers |
Mysql Slave Template Graph |
Hi Nitin,
ReplyDeleteI have tried your MySQL server template but it gives me error in zabbxi portal:
error: split is not defined
. | split("\n")[:-1] | map (split("\t") | {(.[0]) : .[1]} ) | add
^^^^^
error: split is not defined
. | split("\n")[:-1] | map (split("\t") | {(.[0]) : .[1]} ) | add
^^^^^
2 compile errors
Can you please suggest what should I do?
Hi Priyank. Can you please check version of jq on your linux server? You can check this by running command 'jq --version'. If it is less than 1.5.1, please upgrade to latest version.
DeleteHi Nitin, Above seems interesting and getting the json data.
ReplyDeleteBut not able to get items details in zabbix UI. May I know where is this JSON Path(preprocessing) storing the json data which is eventually queried by jq?
It is stored in item mysql_server_status or mysql_slave_status. Please check if your zabbix client is configured to work as active client.
DeleteThanks for the response, configuring zabbix client active made it working.
ReplyDeleteGlad to hear that. Good luck.
ReplyDeleteHi Nitin,
ReplyDeleteMy zabbix client configuration is as following:-
UserParameter=mysql_server_status, mysql --defaults-file=/var/lib/zabbix/.my.cnf --defaults-group-suffix=_monitoring -N -e "show global status" | jq -c '. | split("\n")[:-1] | map (split("\t") | {(.[0]) : .[1]} ) | add ' -R -s
and with above configuration "zabbix_agent -t mysql_server_status" is working fine and giving expected result. But zabbix server GUI is not showing any data. Please help.
Is your zabbix configured to work as active agent? Please ensure ServerActive and Hostname is defined in zabbix agent configuration.
DeleteI think you need to change the beginning: UserParameter=mysql_server_status to UserParameter=Mysql.Server-Status
DeleteOtherwise you'll get errors about unsupported item.
Hello,
ReplyDeleteI have issue when importing MySQL Slave template. I have opened issue at Github:
https://github.com/nitzien/zabbix-misc/issues/4
Update: got it resolved. Issue closed :-)
DeleteHi.
ReplyDeletethe thing is that, my server-status is on https, hence i keep getting this response
400 Bad Request
Bad Request
Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.
Apache/2.4.18 (Ubuntu) Server at server.com Port 443
How can i resolve this
any idea?
sorry commented in the wrong window
DeleteThis involve communication only between agent and zabbix. I do not understand SSL issue that you are facing here. Please elaborate more on your problem.
Deletesorry commented in the wrong window
ReplyDeleteHi,
ReplyDeleteI'm getting this error after installing using your instructions.
Details Cannot send request
Cannot send request: wrong item type.
Kindly advise how to troubleshoot this error. thank you!
Can you please post where are you seeing this error and logs if you have them?
DeleteHi Mr. Nitin. Thank you for your reply. I'm getting this error after editing userparameter_mysql.conf on my slave server:
Delete:/etc/zabbix/zabbix_agentd.d]$ cat userparameter_mysql.conf | grep slave
UserParameter=Mysql.Slave-Status, mysql --defaults-file=/etc/zabbix/.my.cnf --defaults-group-suffix=_monitoring -e "show slave status \G" | sed -e "s/^\s*//g" | sed -e "s/:\s*/:/g" | jq -c '. | split("\n")[1:-1] | map (split(":") | {(.[0]) : .[1]} ) | add ' -R -s
UPON RESTART:
journalctl -xn
Oct 03 11:21:54 KPGACSDBPRD zabbix_agentd[22711]: zabbix_agentd [22711]: ERROR: cannot add user parameter "Mysql.Slave-Status, mysql --defaults-fi
Oct 03 11:21:54 KPGACSDBPRD systemd[1]: zabbix-agent.service: control process exited, code=exited status=1
Thank you in advance.
OK, I managed to make the client run now. items in the templates are already in the portal. But I'm getting this error
ReplyDelete25728:20191003:113441.206 discovery rule "KPGACSDBPRD:0" became not supported: Unsupported item key.
25729:20191003:113441.571 discovery rule "KPGACSDBPRD:1" became not supported: Unsupported item key.
Does this require discovery rules?
Thank you in advance
I don't understand these errors. Is there any other item configured for this host which may be causing this?
DeleteAdding comment so that I get a notification. :)
ReplyDeleteHi. I have tried your MySQL server template but it gives me error.
ReplyDeletezabbix_agentd -t Mysql.Server-Status
Mysql.Server-Status [t|mysql: [ERROR] unknown variable 'defaults-group-suffix=_monitoring'
This must be because you don't have mysql client config my.cnf. Please check that.
DeleteThis comment has been removed by the author.
ReplyDeleteHi Nitin, mysql slave data not coming where server data coming in graph. All configuration are as same as you mentioned in your blog. I used both mysql & mysql slave in zabbix client configuration and both template are attached with mysql master & master replication server model
ReplyDeleteCan you please check if you have set up your client for active mode?
DeleteHello,
ReplyDeleteI use mysqldump script with --dump-slave option. This option stop SQL Theard for dump and script triggering useful notifications. Can u know, how disable trigger when mysqldump is running?
You may set up maintenance window for that time period in Zabbix.
DeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeletehello Nitin, I have zabbix 4.4.3 and the template does not work, when seeing the data it shows me an error and says no data.
ReplyDeleteIs your zabbix configured to work as active agent? Please ensure ServerActive and Hostname is defined in zabbix agent configuration.
DeleteAlso, can you please check zabbix agent logs to check what is error?
Thank you for you tutorial, I'd really appreciate it. Wold you mind answering how different is for monitoring a dbin Windows. I like to monitor my db server which runs in Windows. (Engine database Mysql)
ReplyDeleteShould not be different because this uses mysql commandline to get data. As long as you can run mysql command from commandline, this should work.
DeleteHello Nitin Jain. I'm writing a question because I found this is the only place I can ask a question related to MySQL Zabbix Slave monitoring template. I have tried many templates: yours and others, but mostly I have one common problem. May be it is not directly related to exactly this one template, but I have the same problem with all the other templates. The problem as follows:
ReplyDeletewhen I try get the value of this:
zabbix_agentd -t "mysql.slave_status[Slave_IO_Running]"
I have clear and correct expected response:
mysql.slave_status[Slave_IO_Running] [t|Yes]
But if I try to get the value of this:
zabbix_agentd -t "mysql.slave_status[Slave_SQL_Running]"
The response is not as expected:
mysql.slave_status[Slave_SQL_Running] [t|Yes
Reading]
There is a new line and some additional words in response, so zabbix complains:
Preprocessing failed for: Yes.System
1. Failed: cannot convert value of type "string" from boolean format: invalid value format
But in case if the slave is stopped the response as expected:
mysql.slave_status[Slave_SQL_Running] [t|No]
Can you suggest what is wrong with that?
Any update on Zabbix 5.4?
ReplyDelete