{"id":93434,"date":"2024-04-14T18:22:14","date_gmt":"2024-04-14T10:22:14","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=93434"},"modified":"2024-04-14T18:22:14","modified_gmt":"2024-04-14T10:22:14","slug":"zabbix-monitor-custom","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/zabbix-monitor-custom.html","title":{"rendered":"\u5982\u4f55\u7528zabbix\u521b\u5efa\u81ea\u5b9a\u4e49\u76d1\u63a7\u9879"},"content":{"rendered":"
\u80cc\u666f\uff1a<\/strong><\/span><\/div>\n

zabbix\u672c\u8eab\u63d0\u4f9b\u4e86\u5f88\u591a\u53ef\u9009\u7684\u76d1\u63a7\u9879\uff0c\u53ef\u4ee5\u6ee1\u8db3\u7edd\u5927\u90e8\u5206\u7684\u76d1\u63a7\u9700\u6c42\u3002\u6709\u65f6\u5019\u7531\u4e8e\u4e1a\u52a1\u9700\u6c42\uff0c\u9700\u8981\u81ea\u5b9a\u4e49\u76d1\u63a7\u9879\u3002 \u4e0b\u9762\u4ee5\u521b\u5efamysql\u81ea\u5b9a\u4e49\u76d1\u63a7\u9879\u4e3a\u4f8b\uff0c\u5206\u4eab\u5982\u4f55\u521b\u5efazabbix\u81ea\u5b9a\u4e49\u76d1\u63a7\u9879\u3002<\/p>\n

\u73af\u5883\u8bf4\u660e\uff1a<\/strong><\/span><\/div>\n

zabbix\u7248\u672c\uff1a3.0.3 \u64cd\u4f5c\u7cfb\u7edf\uff1aCentOS 7 mysql\u7248\u672c\uff1a5.7.1<\/p>\n

\u5b9e\u73b0\u6b65\u9aa4\uff1a<\/strong><\/span><\/div>\n

1\u3001\u4fee\u6539 zabbix_agentd.conf\uff0c\u6dfb\u52a0zabbix_agent \u914d\u7f6e\u76ee\u5f55\uff0c\u4ee5\u4e0b\u662f\u6211\u672c\u673a\u7684zabbix\u7684\u914d\u7f6e\uff1a \u5c06\u4ee5\u4e0b\u884c\u7684\u6ce8\u91ca\u53bb\u6389<\/p>\n

   #Include<\/span>=\/usr\/<\/span>local\/etc\/<\/span>zabbix_agentd.conf.d\/*.conf \r\n<\/span><\/pre>\n

\u53d8\u6210\uff1a<\/p>\n

   Include<\/span>=\/usr\/<\/span>local\/etc\/<\/span>zabbix_agentd.conf.d\/*.conf \r\n<\/span><\/pre>\n

\u5c06\u6b64\u884c\u6ce8\u91ca\u53bb\u6389\u540e\uff0czabbix_agentd\u542f\u52a8\u540e\u4f1a\u81ea\u52a8\u626b\u63cf\/usr\/local\/etc\/zabbix_agentd.conf.d\/\u76ee\u5f55\u4e0b\u6240\u6709\u7684.conf\u6587\u4ef6\uff0c\u5e76\u52a0\u8f7d\u3002<\/p>\n

2\u3001\u7f16\u5199\u76d1\u63a7\u811a\u672c\/usr\/local\/zabbix\/zabbix-script\/get_mysql_status.sh\uff0c\u811a\u672c\u5982\u4e0b(\u811a\u672c\u5b58\u653e\u76ee\u5f55\u53ef\u4ee5\u81ea\u5b9a\u4e49)\uff1a<\/p>\n

#!\/bin\/sh\r\n<\/span>\r\ncase<\/span> $3<\/span> in<\/span>\r\nuptime)\r\nmysqladmin -u$1<\/span> -p$2<\/span> status 2>\/dev\/nul | awk -F '[:| ]'<\/span>+ '{print $2}'<\/span>\r\n;;\r\nthreads)\r\nmysqladmin -u$1<\/span> -p$2<\/span> status 2>\/dev\/nul | awk -F '[:| ]'<\/span>+ '{print $4}'<\/span>\r\n;;\r\nquestion)\r\nmysqladmin -u$1<\/span> -p$2<\/span> status 2>\/dev\/nul | awk -F '[:| ]'<\/span>+ '{print $6}'<\/span>\r\n;;\r\nsq)\r\nmysqladmin -u$1<\/span> -p$2<\/span> status 2>\/dev\/nul | awk -F '[:| ]'<\/span>+ '{print $9}'<\/span>\r\n;;\r\nopen)\r\nmysqladmin -u$1<\/span> -p$2<\/span> status 2>\/dev\/nul | awk -F '[:| ]'<\/span>+ '{print $11}'<\/span>\r\n;;\r\nftable)\r\nmysqladmin -u$1<\/span> -p$2<\/span> status 2>\/dev\/nul | awk -F '[:| ]'<\/span>+ '{print $14}'<\/span>\r\n;;\r\nopent)\r\nmysqladmin -u$1<\/span> -p$2<\/span> status 2>\/dev\/nul | awk -F '[:| ]'<\/span>+ '{print $17}'<\/span>\r\n;;\r\nqps)\r\nmysqladmin -u$1<\/span> -p$2<\/span> status 2>\/dev\/nul | awk -F '[:| ]'<\/span>+ '{print $22}'<\/span>\r\n;;\r\n*)\r\n<\/pre>\n

\u811a\u672c\u8bf4\u660e\uff0c\u811a\u672c\u9700\u8981\u8f93\u5165\u4e09\u4e2a\u53c2\u6570\u5206\u522b\u662f\uff1amysql\u7528\u6237\u3001mysql\u7528\u6237\u5bc6\u7801\u3001mysql\u72b6\u6001\u5404\u9879\u6307\u6807\u5982\u4e0b\uff1a uptime:\u8fd0\u884c\u65f6\u957f\u5355\u4f4ds\u3001 threads\uff1a\u5f00\u542f\u7684\u4f1a\u8bdd\u6570\u3001 question\uff08questions\uff09\uff1a\u670d\u52a1\u5668\u542f\u52a8\u4ee5\u6765\u5ba2\u6237\u7684\u95ee\u9898(\u67e5\u8be2)\u6570\u76ee sq\uff08Slow queries\uff09: \u6162\u67e5\u8be2\u6570\u91cf open\uff08opens\uff09\uff1a\u670d\u52a1\u5668\u5df2\u7ecf\u6253\u5f00\u7684\u6570\u636e\u5e93\u8868\u7684\u6570\u91cf ftable(Flush tables):\u670d\u52a1\u5668\u5df2\u7ecf\u6267\u884c\u7684flush ...\u3001refresh\u548creload\u547d\u4ee4\u7684\u6570\u91cf opent(open tables):\u901a\u8fc7\u547d\u4ee4\u662f\u7528\u7684\u6570\u636e\u5e93\u7684\u8868\u7684\u6570\u91cf\uff0c\u4ee5\u670d\u52a1\u5668\u542f\u52a8\u5f00\u59cb qps\uff08Queries per second avg\uff09\uff1aselect\u8bed\u53e5\u5e73\u5747\u67e5\u8be2\u65f6\u95f4<\/p>\n

3\u3001\u5728\/usr\/local\/etc\/zabbix_agentd.conf.d\/\u76ee\u5f55\u4e0b\u6dfb\u52a0\u76d1\u63a7\u9879\u914d\u7f6e\u6587\u4ef6get_mysql_status.conf\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n

UserParameter=get_mysql_status[*],\/usr\/local<\/span>\/zabbix\/zabbix<\/span>-script\/get_mysql_status.sh $1<\/span> $2<\/span> $3<\/span>\r\n<\/pre>\n

4\u3001\u91cd\u542fzabbix_agent\u548czabbix_server\uff0c\u4f7f\u7528zabbix_get\u6d4b\u8bd5\uff0c\u5982\u4e0b\uff1a<\/p>\n

   #zabbix_get<\/span> -s<\/span> 127.0<\/span>.0<\/span>.1<\/span> -k<\/span> get_mysql_status<\/span>[root,weiming,open]<\/span>\r\n   679\r\n<\/pre>\n

5\u3001web\u7aef\u6dfb\u52a0\u76d1\u63a7\u9879\uff1a \u5728\u4e3b\u673a\u4e0a\u6dfb\u52a0\u76d1\u63a7\u9879\uff1a
\n\"\"<\/a><\/p>\n

\u6dfb\u52a0\u5b8c\u6210\u540e\u53ef\u4ee5\u770b\u5230\u65b0\u589e\u76d1\u63a7\u9879\u5982\u4e0b\uff1a<\/p>\n

\"\"<\/a><\/p>\n

\u6dfb\u52a0\u56fe\u5f62\uff1a<\/p>\n

\"\"<\/a><\/p>\n

\u56fe\u5f62\u9884\u89c8\uff1a<\/p>\n

\"\"<\/a><\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/my.oschina.net\/u\/3567396\/blog\/1594128<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/zabbix-monitor-custom.html<\/a>\u7f16\u8f91\uff1a\u5f20\u96c4\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u80cc\u666f\uff1a zabbix\u672c\u8eab\u63d0\u4f9b\u4e86\u5f88\u591a\u53ef\u9009\u7684\u76d1\u63a7\u9879\uff0c\u53ef\u4ee5\u6ee1\u8db3\u7edd\u5927\u90e8\u5206\u7684\u76d1\u63a7\u9700\u6c42\u3002\u6709\u65f6\u5019\u7531\u4e8e\u4e1a\u52a1\u9700\u6c42\uff0c\u9700\u8981\u81ea\u5b9a\u4e49\u76d1\u63a7 […]<\/p>\n","protected":false},"author":643,"featured_media":93444,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-93434","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/93434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=93434"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/93434\/revisions"}],"predecessor-version":[{"id":93474,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/93434\/revisions\/93474"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/93444"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=93434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=93434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=93434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}