zabbix 监控 ticdc 同步

张映 发表于 2021-01-19

分类目录: tidb, 服务器相关

标签:,

ticdc往下游mysql同步,如果报错就会导致同步中止,这时提醒就显得很重要了。

1,创建ticdc同步发现脚本


# vim /etc/zabbix/zabbix_agent2.conf  

UnsafeUserParameters=1 //0改成1,允许自定义参数  

# systemctl restart zabbix-agent2   //重启

# mkdir /etc/zabbix/script/ //创建个脚本目录

# vim /etc/zabbix/script/ticdc-discover.php
<?php
# Discovery ticdc.
# Example:
#   php ./ticdc-discover.php msg
# Return Json:
# [
#     {
#         "{#RID}":"test-to-201-mysql",
#         "{#MES}":"[CDC:ErrMySQLTxnError]Error 1146: Table 'test.test' doesn't exist"
#     },
#     {
#         "{#RID}":"test-to-194-mariadb",
#         "{#MES}":""
#     }
# ]
# Example:
#   php ./ticdc-discover.php id
# Return Json:
# [
#     {
#         "{#RID}":"test-to-201-mysql"
#     },
#     {
#         "{#RID}":"test-to-194-mariadb"
#     }
# ]
$result = [];

$command = "/home/tidb/.tiup/bin/tiup ctl cdc changefeed list --pd=http://10.0.10.19:2379";
$res = shell_exec($command);
preg_match('/\[.*\s+.*\]/is',$res,$match);
if(!empty($match[0])){
    $cid = json_decode($match[0],true);

    foreach($cid as $k=>$v) {
        $result[$k]["{#RID}"] = $v['id'];
        if(!empty($argv[1]) && $argv[1] == 'msg'){
            if(!empty($v['summary']['error'])){
                $result[$k]["{#MES}"] = $v['summary']['error']['message'];
            }else{
                $result[$k]["{#MES}"] = "";
            }
        }
    }
}

echo json_encode($result);

2,创建检查脚本

# cat /etc/zabbix/script/ticdc-check.php
<?php

# Ticdc check
# Example:
# cid test-to-201-mysql status:
#   php ticdc-check.php test-to-201-mysql
# Return:
#   - UP(1),
#   - Down(0)

$command = "/home/tidb/.tiup/bin/tiup ctl cdc changefeed query --pd=http://10.0.10.19:2379 -c ".$argv[1];
$res = shell_exec($command);
if(stripos($res,"message") || preg_match('/"task-status":\s+\[\]/i',$res)){
    echo 0;
}else{
    echo 1;
}

3,配置脚本执行权限

# chown tidb.tidb -R /etc/zabbix/script/

4,配置zabbix-agent2

$ vim /etc/zabbix/zabbix_agent2.d/ticdc-status.conf
UserParameter=ticdc-discover[*],sudo -u tidb php /etc/zabbix/script/ticdc-discover.php $1
UserParameter=ticdc.check[*],sudo -u tidb php /etc/zabbix/script/ticdc-check.php $1

# systemctl restart zabbix-agent2 //重启客户端

5,zabbix_get检测配置

[tidb@jiankong bin]$ zabbix_get -s 127.0.0.1 -p 10050 -k "ticdc-discover[id]"
[{"{#RID}":"test-to-194-mariadb"},{"{#RID}":"test-to-201-mysql"}]

[tidb@jiankong bin]$ zabbix_get -s 127.0.0.1 -p 10050 -k "ticdc-discover[msg]"
[{"{#RID}":"test-to-201-mysql","{#MES}":"[CDC:ErrMySQLTxnError]Error 1146: Table 'test.test' doesn't exist"},{"{#RID}":"test-to-194-mariadb","{#MES}":""}]

[tidb@jiankong bin]$ zabbix_get -s 127.0.0.1 -p 10050 -k "ticdc.check[test-to-194-mariadb]"
1

[tidb@jiankong bin]$ zabbix_get -s 127.0.0.1 -p 10050 -k "ticdc.check[test-to-201-mysql]"
0

6,创建模板,自动发现,监控原型项,触发器等

zabbix ticdc 模板

zabbix ticdc 模板

zabbix ticdc 自动发现

zabbix ticdc 自动发现

zabbix ticdc 监控项原型

zabbix ticdc 监控项原型

zabbix ticdc 触发器

zabbix ticdc 触发器

zabbix ticdc 报错邮件提醒

zabbix ticdc 报错邮件提醒

zabbix ticdc 报错解决 邮件提醒

zabbix ticdc 报错解决 邮件提醒



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/server/2482.html