zabbix监控mysql5.7---python3版

本文详细介绍了在CentOS 7.8系统上使用Zabbix 4.2.8监控MySQL 5.7的全过程,包括Python3环境搭建、MySQL安装与配置、Zabbix-agent部署及监控脚本编写,最终实现数据库性能指标如TPS、QPS及流量监控。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

zabbix监控mysql5.7—python3版

一、环境要求,及安装相关环境软件

1、服务器及相关软件环境要求

操作系统及服务版本IP
linux系统centos7.810.1.1.3
mysql5.7.3110.1.1.3
zabbix-server4.2.810.1.1.135
python33.6.8-18.el710.1.1.3

2、在数据库服务器安装相关软件(python3,mysql5.7,zabbix-agent等)

01、安装python3

yum -y install python3这里是引用

02、安装mysql5.7

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
systemctl start mysqld.service
systemctl status mysqld.service

查看密码

grep “password” /var/log/mysqld.log

修改密码

mysql -uroot -p
ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘XXXXXXX’;

查看密码策略

show variables like ‘%password%’;

修改密码策略

vim /etc/my.cnf
#添加validate_password_policy配置
validate_password_policy=0
#关闭密码策略

重启服务

systemctl restart mysqld

03、zabbix-agent安装

rpm -ivh http://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-2.el7.noarch.rpm
yum install -y zabbix-agent zabbix-sender
vim /etc/zabbix/zabbix_agentd.conf #修改配置文件
Passive checks related 被动监测相关配置项
Server=10.1.1.135 服务端地址或proxy端地址,多个用,隔开
ListenIP=0.0.0.0 监听的地址,默认所有地址
StartAgents=3 启动agent数量,默认3
Active checks related 主动监测相关配置
ServerActive=10.1.1.135 发送到的服务端IP
Hostname=zabbixserver 本机的hostname
其他默认即可

快速修改方式:

sed -i s#‘Server=127.0.0.1’#‘Server=10.1.1.135’#g /etc/zabbix/zabbix_agentd.conf
sed -i s#‘ServerActive=127.0.0.1’#‘ServerActive=10.1.1.135’#g /etc/zabbix/zabbix_agentd.conf
sed -i s#‘Hostname=Zabbix server’#“Hostname=hostname”#g /etc/zabbix/zabbix_agentd.conf
sed -i s/’# HostMetadata=’/‘HostMetadata=yuegowu.com’/g /etc/zabbix/zabbix_agentd.conf
grep -v -E “#|$” /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent
systemctl status zabbix-agent

二、在mysql数据库服务器编写监控数据获取脚本及配置zabbix-agent

1、编写python3脚本,一共三个脚本文件

01、监控需要获取每隔2秒(我这里取得每隔2秒获取一次数据)得数据
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time    : 2021/3/4 11:00
# @Author  : lufei
import re
import subprocess
import time
import sys
import warnings
warnings.filterwarnings('ignore')
def mysql_init():
    return_code = subprocess.check_output("mysqladmin -uroot -p'xxxxxxx' -h'10.1.1.8' extended-status", shell=True)
    return_code = str(return_code)
    return_code_list = return_code.split('---+')
    mysql_status_str = return_code_list[4]
    mysql_status_list = mysql_status_str.split('\\n')

    return mysql_status_list

for nn in mysql_init():
    # 此循环中的数据需要每隔2秒计算一次,然后再将计算后的数值除以2,计算得出每秒的数据,此为第一次循环
    if re.search('Aborted_clients',nn) :
        # Aborted_clients 由于客户没有正确关闭连接已经死掉,已经放弃的连接数量
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Aborted_clients1 = re.findall(regx,nn)[0]

    if re.search('Aborted_connects',nn):
        # Aborted_connects尝试已经失败的MySQL服务器的连接的次数
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Aborted_connects1 = re.findall(regx,nn)[0]

    if re.search('Binlog_cache_disk_use',nn):
        # Binlog_cache_disk_use表示因为我们binlog_cache_size设计的内存不足导致缓存二进制日志用到了临时文件的次数(做监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Binlog_cache_disk_use1 = re.findall(regx,nn)[0]

    if re.search('Bytes_received',nn):
        # 从所有客户端接收到的字节数。结合bytes sent, 可以作为数据库网卡吞吐量的评测指标,单位字节
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Bytes_received1 = re.findall(regx,nn)[0]

    if re.search('Bytes_sent',nn):
        # 发送给所有客户端的字节数。结合bytes received,可以作为数据库网卡吞吐量的评测指标,单位字节
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Bytes_sent1 = re.findall(regx,nn)[0]

    if re.search('Com_commit',nn):
        # MySQL提交的事务数量,可以用来统计TPS(每秒事务数),计算公式:Com_commit/S+Com_rollback/S(做监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_commit1 = re.findall(regx,nn)[0]

    if re.search('Com_rollback ',nn):
        # MySQL回滚的事务数量,可以用来统计TPS(每秒事务数),计算公式:Com_commit/S+Com_rollback/S(做监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_rollback1 = re.findall(regx,nn)[0]

    if re.search('Com_delete ',nn):
        # MySQL删除的数量,可以用来统计qps,计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s(做监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_delete1 = re.findall(regx,nn)[0]

    if re.search('Com_insert ',nn):
        # MySQL插入的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s (做监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_insert1 = re.findall(regx,nn)[0]

    if re.search('Com_update ',nn):
        # MySQL更新的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s(监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_update1 = re.findall(regx,nn)[0]

    if re.search('Com_select',nn):
        # MySQL查询的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s(监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_select1 = re.findall(regx,nn)[0]

    if re.search('Handler_delete',nn):
        # 请求从一张表中删除行的次数。(监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Handler_delete1 = re.findall(regx,nn)[0]

    if re.search('Questions',nn):
        # 发往服务器的查询的数量。(监控),即mysql的QPS
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Questions1 = re.findall(regx,nn)[0]

time.sleep(2)

for nn in mysql_init():
    # 此循环中的数据需要每隔60秒计算一次,然后再将计算后的数值除以60,计算得出每秒的数据,此为第二次循环
    if re.search('Aborted_clients',nn) :
        # Aborted_clients 由于客户没有正确关闭连接已经死掉,已经放弃的连接数量
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Aborted_clients2 = re.findall(regx,nn)[0]

    if re.search('Aborted_connects',nn):
        # Aborted_connects尝试已经失败的MySQL服务器的连接的次数
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Aborted_connects2 = re.findall(regx,nn)[0]

    if re.search('Binlog_cache_disk_use',nn):
        # Binlog_cache_disk_use表示因为我们binlog_cache_size设计的内存不足导致缓存二进制日志用到了临时文件的次数(做监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Binlog_cache_disk_use2 = re.findall(regx,nn)[0]

    if re.search('Bytes_received',nn):
        # Bytes_received从所有客户端接收到的字节数。结合bytes sent, 可以作为数据库网卡吞吐量的评测指标,单位字节
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Bytes_received2 = re.findall(regx,nn)[0]

    if re.search('Bytes_sent',nn):
        # Bytes_sent发送给所有客户端的字节数。结合bytes received,可以作为数据库网卡吞吐量的评测指标,单位字节
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Bytes_sent2 = re.findall(regx,nn)[0]

    if re.search('Com_commit',nn):
        # MySQL提交的事务数量,可以用来统计TPS(每秒事务数),计算公式:Com_commit/S+Com_rollback/S(做监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_commit2 = re.findall(regx,nn)[0]

    if re.search('Com_rollback ',nn):
        # MySQL回滚的事务数量,可以用来统计TPS(每秒事务数),计算公式:Com_commit/S+Com_rollback/S(做监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_rollback2 = re.findall(regx,nn)[0]

    if re.search('Com_delete ',nn):
        # MySQL删除的数量,可以用来统计qps,计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s(做监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_delete2 = re.findall(regx,nn)[0]

    if re.search('Com_insert ',nn):
        # MySQL插入的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s (做监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_insert2 = re.findall(regx,nn)[0]

    if re.search('Com_update ',nn):
        # MySQL更新的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s(监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_update2 = re.findall(regx,nn)[0]

    if re.search('Com_select',nn):
        # MySQL查询的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s(监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Com_select2 = re.findall(regx,nn)[0]

    if re.search('Handler_delete',nn):
        # 请求从一张表中删除行的次数。(监控)
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Handler_delete2 = re.findall(regx,nn)[0]

    if re.search('Questions',nn):
        # Questions发往服务器的查询的数量。(监控),即mysql的QPS
        # 这个数值需要在2秒后再做一次取值然后让其数值相减算出2秒的取值
        regx = '(\d+) '
        Questions2 = re.findall(regx,nn)[0]

def Mysql_TPS():
    # TPS = round(((int(Com_commit2) + int(Com_rollback2)) - (int(Com_commit1) + int(Com_rollback1))) / 60)   # 每秒的TPS,不是实时的每秒是平均的,意义不大
    TPS = ((int(Com_commit2) + int(Com_rollback2)) - (int(Com_commit1) + int(Com_rollback1)))     # 2秒的TPS
    return TPS

def Aborted_clients():
    # 由于客户没有正确关闭连接已经死掉,已经放弃的连接数量
    Abortedcli = int(Aborted_clients2) -int(Aborted_clients1)
    return Abortedcli

def Aborted_connect():
    # Aborted_connects尝试已经失败的MySQL服务器的连接的次数
    Aborted_conn = int(Aborted_connects2) - int(Aborted_connects1)
    return Aborted_conn

def Binlog_cache_disk_use():
    # Binlog_cache_disk_use表示因为我们binlog_cache_size设计的内存不足导致缓存二进制日志用到了临时文件的次数
    Binlog_to_disk = int(Binlog_cache_disk_use2) - int(Binlog_cache_disk_use1)
    return Binlog_to_disk

def Bytes_received():
    # Bytes_received从所有客户端接收到的字节数。结合bytes sent, 可以作为数据库网卡吞吐量的评测指标,单位字节
    Bytes_rec = int(Bytes_received2) - int(Bytes_received1)
    return Bytes_rec

def Bytes_sent():
    # Bytes_sent发送给所有客户端的字节数。结合bytes received,可以作为数据库网卡吞吐量的评测指标,单位字节
    Bytes_st = int(Bytes_sent2) - int(Bytes_sent1)
    return Bytes_st

def totle_Bytes():
    totlebyte = ((int(Bytes_sent2)+int(Bytes_received2)) - (int(Bytes_sent1)+int(Bytes_received1)))
    # 网卡的流出流入的字节总和,2秒内的。
    return totlebyte

def Com_commit():
    # MySQL提交的事务数量,可以用来统计TPS(每秒事务数),计算公式:Com_commit/S+Com_rollback/S
    Com_commit_new = int(Com_commit2) - int(Com_commit1)
    return Com_commit_new

def Com_rollback():
    # MySQL回滚的事务数量,可以用来统计TPS(每秒事务数),计算公式:Com_commit/S+Com_rollback/S
    Com_rollback_new = int(Com_rollback2) - int(Com_rollback1)
    return Com_rollback_new

def Com_delete():
    # MySQL删除的数量,可以用来统计qps,计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s
    Com_delete_new = int(Com_delete2) - int(Com_delete1)
    return Com_delete_new

def Com_insert():
    # MySQL插入的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s
    Com_insert_new = int(Com_insert2) - int(Com_insert1)
    return Com_insert_new

def Com_update():
    # MySQL更新的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s
    Com_update_new = int(Com_update2) - int(Com_update1)
    return Com_update_new

def Com_select():
    # MySQL查询的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s
    Com_select_new = int(Com_select2) - int(Com_select1)
    return Com_select_new

def Questions():
    # Questions发往服务器的查询的数量。(监控),即mysql的QPS
    Questions_new = int(Questions2) - int(Questions1)
    return Questions_new

switch = {'Mysql_TPS': Mysql_TPS,                # 注意此处不要加括号
          'Aborted_clients': Aborted_clients,
          'Aborted_connect': Aborted_connect,
          'Binlog_cache_disk_use': Binlog_cache_disk_use,
          'Bytes_received': Bytes_received,
          'Bytes_sent': Bytes_sent,
          'totle_Bytes': totle_Bytes,
          'Com_commit': Com_commit,
          'Com_rollback': Com_rollback,
          'Com_delete': Com_delete,
          'Com_insert': Com_insert,
          'Com_update': Com_update,
          'Com_select': Com_select,
          'Questions': Questions,
          }
# choice = sys.argv[1]
choice = 'Questions'
print(switch.get(choice)())

备注:脚本中的数据库密码需要自行填写。

02、获取数据库存活及链接状态脚本
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time    : 2021/3/5 14:25
# @Author  : lufei
import re
import os
import subprocess
import time
import sys
def mysql_init():
    return_code = subprocess.check_output("mysqladmin -uroot -p'xxxxxxx' -h'10.1.1.8' extended-status", shell=True)
    return_code = str(return_code)
    return_code_list = return_code.split('---+')
    mysql_status_str = return_code_list[4]
    mysql_status_list = mysql_status_str.split('\\n')

    return mysql_status_list

def mysql_status():
    mysql_sta = subprocess.check_output("mysqladmin -uroot -p'xxxxxxx' -h'10.1.1.8'  ping|grep 'mysqld is alive'|wc -l", shell=True)
    # mysql_stat_num = filter(str.isdigit,  str(mysql_sta) )
    mysql_stat_num = int(re.findall(r'\d+', str(mysql_sta))[0])
    return mysql_stat_num

for one_data in mysql_init():
    # 此循环为只需一次获得的结果
    if re.search('Com_create_procedure', one_data):
        # Com_create_procedure创建存储过程个数(监控)
        regx = '(\d+) '
        Com_create_procedure = re.findall(regx, one_data)[0]

    if re.search('Max_used_connections ',one_data):
        # Max_used_connections同时使用的连接的最大数目。(监控)
        regx = '(\d+) '
        Max_used_connections = re.findall(regx,one_data)[0]

    if re.search('Com_create_table', one_data):
        # Com_create_table创建数据表个数(监控)
        regx = '(\d+) '
        Com_create_table = re.findall(regx, one_data)[0]

    if re.search('Com_lock_tables', one_data):
        # Com_lock_tables锁表lock tables,解锁命令unlock tables
        regx = '(\d+) '
        Com_lock_tables = re.findall(regx, one_data)[0]

    if re.search('Open_tables', one_data):
        # Open_tables打开表的数量。(监控)
        regx = '(\d+) '
        Open_tables = re.findall(regx, one_data)[0]

    if re.search('Open_files', one_data):
        # Open_files打开文件的数量。(监控)
        regx = '(\d+) '
        Open_files = re.findall(regx, one_data)[0]

    if re.search('Threads_connected', one_data):
        # Threads_connected当前打开的连接的数量。(监控)
        regx = '(\d+) '
        Threads_connected = re.findall(regx, one_data)[0]

    if re.search('Threads_running', one_data):
        # Threads_running不在睡眠的线程数量。(监控)
        regx = '(\d+) '
        Threads_running = re.findall(regx, one_data)[0]

    if re.search('Uptime ', one_data):
        # Uptime 不在睡眠的线程数量。(监控)
        regx = '(\d+) '
        Uptime = round(int(re.findall(regx, one_data)[0]) / 86400)


def Com_create_proc():
    # Com_create_procedure创建存储过程个数
    return Com_create_procedure

def Max_used_conn():
    # Max_used_connections同时使用的连接的最大数目
    return Max_used_connections

def Com_create_tab():
    # Com_create_table创建数据表个数
    return Com_create_table

def Com_lock_tab():
    # Com_lock_tables锁表lock tables,解锁命令unlock tables
    return Com_lock_tables

def Open_tab():
    # Open_tables打开表的数量
    return Open_tables

def Open_file():
    # Open_files打开文件的数量
    return Open_files

def Threads_conn():
    # Threads_connected当前打开的连接的数量
    return Threads_connected

def Threads_run():
    # Threads_running不在睡眠的线程数量
    return Threads_running

def UpTime():
    # Uptime 不在睡眠的线程数量
    return int(Uptime)


switch = {'Com_create_proce': Com_create_proc,                # 注意此处不要加括号
          'Max_used_connections': Max_used_conn,
          'Com_create_table': Com_create_tab,
          'Com_lock_tables': Com_lock_tab,
          'Open_tables': Open_tab,
          'Open_files': Open_file,
          'Threads_connected': Threads_conn,
          'Threads_running': Threads_run,
          'Uptime': UpTime,
          'mysql_stat': mysql_status,
          }
choice = sys.argv[1]
# choice = 'mysql_slave_delay'
print(switch.get(choice)())

备注:脚本中的数据库密码需要自行填写。

03、获取数据库主从同步状态及延时脚本
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time    : 2021/3/8 10:47
# @Author  : lufei

import re
import os
import subprocess
import time
import sys

def mysql_master_slave_status():
    mysql_slave_status = subprocess.check_output("mysql -uroot -p'xxxxxxx' -h'10.1.1.3' -e 'show slave status\G'|grep '_Running: Yes' |wc -l", shell=True)
    mysql_slave_num = int(re.findall(r'\d+', str(mysql_slave_status))[0])
    return mysql_slave_num

def mysql_slave_delay():
    mysql_slave_delay_new = subprocess.check_output("mysql -uroot -p'xxxxxxx' -h'10.1.1.3' -e 'show slave status\G'|grep 'Seconds_Behind_Master'", shell=True)
    mysql_slave_delay_num = int(re.findall(r'\d+', str(mysql_slave_delay_new))[0])
    return mysql_slave_delay_num

switch = {'mysql_slave_status': mysql_master_slave_status,
          'mysql_slave_delay': mysql_slave_delay
          }
choice = sys.argv[1]
# choice = 'mysql_slave_delay'
print(switch.get(choice)())

备注:脚本中的数据库密码需要自行填写。

04、将脚本添加执行权限

chmod +x /etc/zabbix/zabbix_agentd.d/bin/*

2、配置mysql服务器得zabbix-agent客户端

创建脚本存放目录
cd /etc/zabbix/zabbix_agentd.d/
mkdir bin

将脚本文件考本指定得目录
脚本存放位置
创建配置文件

cd …
vim mysql_status57_3.conf
UserParameter=mysql_status_57[*],python3 -W ignore /etc/zabbix/zabbix_agentd.d/bin/monitor_mysql57_3.py $1 2>/dev/null

vim mysql_status_monitor_3.conf
UserParameter=mysql_status[*],python3 -W ignore /etc/zabbix/zabbix_agentd.d/bin/monitor_mysql57_time2_3.py $1 2>/dev/null

vim mysql_slave.conf
UserParameter=mysql_slave[*],python3 -W ignore /etc/zabbix/zabbix_agentd.d/bin/monitor_mysql_slave.py $1 2>/dev/null

重启服务:

systemctl restart zabbix-agent

服务端测试:

zabbix_get -s 10.1.1.3 -p10050 -k “mysql_status_57_8[mysql_stat]”
在这里插入图片描述

三、zabbix-server端的web界面配置

在这里插入图片描述

1、配置模板

在这里插入图片描述在这里插入图片描述创建完成后点击进入模板后创建监控项:
在这里插入图片描述在这里插入图片描述其他值不变,
其他监控项自行添加

创建触发器:
在这里插入图片描述在这里插入图片描述
在这里插入图片描述图形创建:
在这里插入图片描述在这里插入图片描述
配置主机监控:
在这里插入图片描述
找到相应主机,如没有则添加(添加过程略):
在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述添加完成,这样就完成mysql的监控,其他监控项需要自行添加操作

2、模板文件

01、mysql_slave_python.xml 主从监控

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>4.2</version>
    <date>2021-03-15T01:13:40Z</date>
    <groups>
        <group>
            <name>Templates/Databases</name>
        </group>
    </groups>
    <templates>
        <template>
            <template>mysql_slave_python</template>
            <name>mysql_slave_python</name>
            <description/>
            <groups>
                <group>
                    <name>Templates/Databases</name>
                </group>
            </groups>
            <applications>
                <application>
                    <name>mysql_python</name>
                </application>
            </applications>
            <items>
                <item>
                    <name>mysql主从延迟时间</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_slave[mysql_slave_delay]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>mysql_slave_status数据库监控状态</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_slave[mysql_slave_status]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
            </items>
            <discovery_rules/>
            <httptests/>
            <macros/>
            <templates/>
            <screens/>
            <tags/>
        </template>
    </templates>
    <triggers>
        <trigger>
            <expression>{mysql_slave_python:mysql_slave[mysql_slave_status].last()}&lt;2</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>mysql_slave_status</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>4</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
        <trigger>
            <expression>{mysql_slave_python:mysql_slave[mysql_slave_delay].last()}&gt;900</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>mysql主从延迟900</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>3</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
        <trigger>
            <expression>{mysql_slave_python:mysql_slave[mysql_slave_status].last()}&gt;1200</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>mysql主从延迟1200</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>4</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
    </triggers>
    <graphs>
        <graph>
            <name>mysql主从同步图形</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_slave_python</host>
                        <key>mysql_slave[mysql_slave_status]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>mysql主从延迟</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_slave_python</host>
                        <key>mysql_slave[mysql_slave_delay]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
    </graphs>
</zabbix_export>

02、mysql_status_python_57.xml mysql数据库状态监控

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>4.2</version>
    <date>2021-03-15T01:14:03Z</date>
    <groups>
        <group>
            <name>Templates/Databases</name>
        </group>
    </groups>
    <templates>
        <template>
            <template>mysql_status_python_57</template>
            <name>mysql_status_python_57</name>
            <description/>
            <groups>
                <group>
                    <name>Templates/Databases</name>
                </group>
            </groups>
            <applications>
                <application>
                    <name>msyql_python</name>
                </application>
            </applications>
            <items>
                <item>
                    <name>Com_create_procedure创建存储过程个数</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status57[Com_create_proce]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Com_create_table创建数据表个数</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status57[Com_create_table]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Com_lock_tables锁表lock tables</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status57[Com_lock_tables]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Max_used_connections同时使用的连接的最大数目</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status57[Max_used_connections]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>mysql存活状态</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status57[mysql_stat]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Open_files打开文件的数量</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status57[Open_files]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Open_tables打开表的数量</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status57[Open_tables]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Threads_connected当前打开的连接的数量</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status57[Threads_connected]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Threads_running不在睡眠的线程数量</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status57[Threads_running]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Uptime 数据库启动到现在的时间(秒)</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status57[Uptime]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
            </items>
            <discovery_rules/>
            <httptests/>
            <macros/>
            <templates/>
            <screens/>
            <tags/>
        </template>
    </templates>
    <triggers>
        <trigger>
            <expression>{mysql_status_python_57:mysql_status57[mysql_stat].last()}&lt;1</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>mysql运行状态</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>4</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
        <trigger>
            <expression>{mysql_status_python_57:mysql_status57[Com_lock_tables].last()}&gt;1</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>mysql锁表状态数量</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>3</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
        <trigger>
            <expression>{mysql_status_python_57:mysql_status57[Threads_connected].last()}&gt;1000</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>Threads_connected全部连接数</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>3</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
        <trigger>
            <expression>{mysql_status_python_57:mysql_status57[Threads_running].last()}&gt;100</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>Threads_running正在运行的连接数</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>3</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
    </triggers>
    <graphs>
        <graph>
            <name>mysql锁表图形</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_python_57</host>
                        <key>mysql_status57[Com_lock_tables]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>mysq连接数</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_python_57</host>
                        <key>mysql_status57[Threads_connected]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>F63100</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_python_57</host>
                        <key>mysql_status57[Threads_running]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>数据库运行状态</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_python_57</host>
                        <key>mysql_status57[mysql_stat]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
    </graphs>
</zabbix_export>

03、mysql_status_time2_python.xml 监控数据库流量及TPS等

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>4.2</version>
    <date>2021-03-15T01:14:27Z</date>
    <groups>
        <group>
            <name>Templates/Databases</name>
        </group>
    </groups>
    <templates>
        <template>
            <template>mysql_status_time2_python</template>
            <name>mysql_status_time2_python</name>
            <description/>
            <groups>
                <group>
                    <name>Templates/Databases</name>
                </group>
            </groups>
            <applications>
                <application>
                    <name>mysql_python</name>
                </application>
            </applications>
            <items>
                <item>
                    <name>Aborted_clients已经放弃的连接数量</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Aborted_clients]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>由于客户没有正确关闭连接已经死掉,已经放弃的连接数量</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Aborted_connect失败的MySQL服务器的连接的次数</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Aborted_connect]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>Aborted_connects尝试已经失败的MySQL服务器的连接的次数</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Binlog_cache_disk_use缓存磁盘文件次数</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Binlog_cache_disk_use]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>Binlog_cache_disk_use表示因为我们binlog_cache_size设计的内存不足导致缓存二进制日志用到了临时文件的次数</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Bytes_received网卡接收流量(字节)</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Bytes_received]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>Bytes_received从所有客户端接收到的字节数。结合bytes sent, 可以作为数据库网卡吞吐量的评测指标,单位字节,如果需要换算成MB则需要除以1024/1024</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Bytes_sent网卡发送量(字节)</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Bytes_sent]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>Bytes_sent发送给所有客户端的字节数。结合bytes received,可以作为数据库网卡吞吐量的评测指标,单位字节,换算成MB需要除以1024/1024</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Com_commit事务提交次数</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Com_commit]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>MySQL提交的事务数量,可以用来统计TPS(每秒事务数),计算公式:Com_commit/S+Com_rollback/S</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Com_delete删除语句数量</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Com_delete]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>MySQL删除的数量,可以用来统计qps,计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Com_insert插入语句次数</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Com_insert]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>MySQL插入的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Com_rollback回滚次数</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Com_rollback]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>MySQL回滚的事务数量,可以用来统计TPS(每秒事务数),计算公式:Com_commit/S+Com_rollback/S</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Com_select查询语句次数</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Com_select]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>MySQL查询的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Com_update更新语句次数</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Com_update]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>MySQL更新的数量,可以用来统计qps,qps计算公式:questions / uptime 或者基于com_%计算:Com_select/s + Com_insert/s + Com_update/s + Com_delete/s</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Mysql_TPS数据库的事务操作次数</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Mysql_TPS]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>TPS = round((int(Com_commit2) + int(Com_rollback2)) - (int(Com_commit1) + int(Com_rollback1))) )  # 每2秒的TPS,</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>Questions数据库qps</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[Questions]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>Questions发往服务器的查询的数量。(监控),即mysql的QPS</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
                <item>
                    <name>totle_Bytes网卡总的吞吐量(字节)</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>mysql_status[totle_Bytes]</key>
                    <delay>60s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description>totlebyte = ((int(Bytes_sent2)+int(Bytes_received2)) - (int(Bytes_sent1)+int(Bytes_received1)))</description>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <timeout>3s</timeout>
                    <url/>
                    <query_fields/>
                    <posts/>
                    <status_codes>200</status_codes>
                    <follow_redirects>1</follow_redirects>
                    <post_type>0</post_type>
                    <http_proxy/>
                    <headers/>
                    <retrieve_mode>0</retrieve_mode>
                    <request_method>0</request_method>
                    <output_format>0</output_format>
                    <allow_traps>0</allow_traps>
                    <ssl_cert_file/>
                    <ssl_key_file/>
                    <ssl_key_password/>
                    <verify_peer>0</verify_peer>
                    <verify_host>0</verify_host>
                    <master_item/>
                </item>
            </items>
            <discovery_rules/>
            <httptests/>
            <macros/>
            <templates/>
            <screens/>
            <tags/>
        </template>
    </templates>
    <triggers>
        <trigger>
            <expression>{mysql_status_time2_python:mysql_status[Mysql_TPS].last()}&gt;500</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>mysqlTPS触发器</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>3</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
        <trigger>
            <expression>{mysql_status_time2_python:mysql_status[Questions].last()}&gt;5000</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>数据库QPS</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>3</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
        <trigger>
            <expression>{mysql_status_time2_python:mysql_status[totle_Bytes].last()}&gt;104857600</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>数据库网卡流量</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>3</priority>
            <description>大于100M报警</description>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
    </triggers>
    <graphs>
        <graph>
            <name>mysql事务提交图形</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Com_commit]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>F63100</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Com_rollback]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>mysql网卡图形</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Bytes_received]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>F63100</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Bytes_sent]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>2</sortorder>
                    <drawtype>0</drawtype>
                    <color>2774A4</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[totle_Bytes]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>mysql语句类图形</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Com_delete]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>F63100</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Com_insert]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>2</sortorder>
                    <drawtype>0</drawtype>
                    <color>2774A4</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Com_select]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>3</sortorder>
                    <drawtype>0</drawtype>
                    <color>A54F10</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Com_update]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>mysql需要2秒更新的数据</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Aborted_clients]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>F63100</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Aborted_connect]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>2</sortorder>
                    <drawtype>0</drawtype>
                    <color>2774A4</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Binlog_cache_disk_use]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>3</sortorder>
                    <drawtype>0</drawtype>
                    <color>A54F10</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Bytes_received]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>4</sortorder>
                    <drawtype>0</drawtype>
                    <color>FC6EA3</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Bytes_sent]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>数据库tps、qps</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Mysql_TPS]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>F63100</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>mysql_status_time2_python</host>
                        <key>mysql_status[Questions]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
    </graphs>
</zabbix_export>

### 使用 Docker 部署前后端应用并配置 Zabbix 监控 #### 前后端项目的 Docker 部署 为了实现前后端项目的部署,可以分别创建前端和后端的服务容器。以下是基本流程: 1. **构建前端服务** 将前端代码打包成静态文件,并使用 Nginx 提供服务。 ```dockerfile # Frontend Dockerfile FROM nginx:alpine COPY dist /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] ``` 2. **构建后端服务** 后端可以根据具体技术栈选择合适的基础镜像(如 Node.js、Python Flask/Django 等),并将应用程序代码复制到容器中。 ```dockerfile # Backend Dockerfile (Node.js Example) FROM node:16-alpine WORKDIR /app COPY package*.json ./ RUN npm install COPY . . EXPOSE 3000 CMD ["node", "server.js"] ``` 3. **编写 `docker-compose.yml` 文件** 组合前后端服务并通过 Compose 工具启动。 ```yaml version: &#39;3&#39; services: frontend: build: context: ./frontend dockerfile: Dockerfile ports: - "80:80" backend: build: context: ./backend dockerfile: Dockerfile ports: - "3000:3000" depends_on: - db db: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: example MYSQL_DATABASE: appdb volumes: - db_data:/var/lib/mysql volumes: db_data: ``` --- #### Zabbix Server 的 Docker 部署与监控配置 1. **安装 Zabbix Server 和 Agent** 可以通过官方提供的 Zabbix Docker 镜像快速搭建环境[^4]。 ```bash docker run --name some-zabbix \ -e DB_SERVER_HOST="zabbix-db" \ -e POSTGRES_DB="zabbix" \ -e POSTGRES_USER="zabbix" \ -e POSTGRES_PASSWORD="your_password" \ -p 80:8080 \ -d zabbix/zabbix-server-pgsql:latest ``` 对于 PostgreSQL 数据库容器的初始化命令如下: ```bash docker run --name zabbix-db \ -e POSTGRES_DB="zabbix" \ -e POSTGRES_USER="zabbix" \ -e POSTGRES_PASSWORD="your_password" \ -d postgres:12 ``` 2. **启用 Zabbix Docker Module** 载特定模块 `zabbix_module_docker.so` 来监控 Docker 容器的状态和性能指标[^1]。此模块会自动收集容器的数量、状态以及其他运行时参数。 修改 Zabbix Agent 配置文件 `/etc/zabbix/zabbix_agentd.conf` 添以下内容: ``` LoadModulePath=/usr/lib/zabbix/modules LoadModule=zabbix_module_docker.so ``` 并重启 Zabbix Agent 使更改生效。 3. **导入模板并设置监控项** 导入适用于 Docker 的监控模板[^3],确保能够捕获 CPU 利用率、内存消耗、磁盘 I/O 等关键指标。可以通过 Web UI 进行操作或者直接上传 JSON 格式的模板文件。 4. **验证数据采集效果** 登录 Zabbix Web 控制台查看图表展示情况,确认所有预期的数据均已成功上报至服务器[^2]。 --- ### 示例代码片段 以下是一段简单的 Python 脚本用于模拟自定义监控逻辑: ```python import psutil def get_system_metrics(): cpu_usage = psutil.cpu_percent(interval=1) memory_info = psutil.virtual_memory() disk_usage = psutil.disk_usage(&#39;/&#39;) metrics = { "cpu": cpu_usage, "memory_total": memory_info.total, "memory_used": memory_info.used, "disk_total": disk_usage.total, "disk_used": disk_usage.used } return metrics if __name__ == "__main__": system_metrics = get_system_metrics() print(system_metrics) ``` 上述脚本可作为外部检查的一部分集成进 Zabbix 中。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lufei0920

你的鼓励将是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值