zabbix 监控 dm 同步

张映 发表于 2021-01-21

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

标签:, , ,

dm从上游mysql同步数据到tidb,如果报错就会导致同步中止。上篇文章写了zabbix 监控ticdc同步,本篇与上篇会有稍许的不同

1,允许自定义参数

# vim /etc/zabbix/zabbix_agent2.conf 

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

# systemctl restart zabbix-agent2 //重启

2,创建dm同步发现脚本

$ cat /etc/zabbix/script/dm-discover.php
<?php

# Discovery dm.
# Example:
#   php ./dm-discover.php msg
# Return Json:
# [
#     {
#         "{#DMID}":"mariadb20-task",
#         "{#DMMES}":"[ddl:8200]Unsupported modify column: type varchar(4) not match origin int(4), and tidb_enable_change_column_type is false"
#     },
#     {
#         "{#DMID}":"mysql57-task",
#         "{#DMMES}":""
#     }
# ]
# Example:
#   php ./dm-discover.php id
# Return Json:
# [
#     {
#         "{#DMID}":"mariadb20-task"
#     },
#     {
#         "{#DMID}":"mysql57-task"
#     }
# ]
$result = [];

$command = "/home/tidb/.tiup/bin/tiup dmctl --master-addr 10.0.10.18:8261 query-status";

$res = shell_exec($command);
preg_match('/\{.*\s+.*\}/is',$res,$match);

if(!empty($match[0])){
    $dm_list = json_decode($match[0],true);
    if(empty($dm_list)){
        exit(json_encode($result));
    }

    foreach($dm_list['tasks'] as $k=>$v) {
        $result[$k]["{#DMID}"] = $v['taskName'];
        if(!empty($argv[1]) && $argv[1] == 'msg'){

            if($v['taskStatus'] != "Running"){

                $dm_task_detail = "/home/tidb/.tiup/bin/tiup dmctl --master-addr 10.0.10.18:8261 query-status ".$v['taskName'];
                $detail_res = shell_exec($dm_task_detail);
                preg_match('/"RawCause":\s+\"(.*)\"/i',$detail_res,$detail_match);
                $result[$k]["{#DMMES}"] = $detail_match[1];
            }else{
                $result[$k]["{#DMMES}"] = "Running";
            }
        }
    }
}

echo json_encode($result);

注意:自定义的变量最好不要重名,不然收邮件时,会没有值

3,创建dm检查脚本

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

# dm check
# Example:
# dmid mariadb20-task status:
#   php dm-check.php mariadb20-task
# Return:
#   - UP(success),
#   - Down(error msg)

$command = "/home/tidb/.tiup/bin/tiup dmctl --master-addr 10.0.10.18:8261 query-status ".$argv[1];
$res = shell_exec($command);

if(stripos($res,"errors")){

    preg_match('/"RawCause":\s+\"(.*)\"/i',$res,$detail_match);
    echo $detail_match[1];

}else if(preg_match('/"result":\s+false/i',$res)){
    echo "dm ".$argv[1]." stop by plan";
}else{
    echo "success";
}

注意:上面文章监控ticdc时,返回的数据类型,这次返回的是字符

4,配置脚本执行权限

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

5,配置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
UserParameter=dm-discover[*],sudo -u tidb php /etc/zabbix/script/dm-discover.php $1
UserParameter=dm.check[*],sudo -u tidb php /etc/zabbix/script/dm-check.php $1

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

6,zabbix_get检测配置

$ zabbix_get -s 127.0.0.1 -p 10050 -k "dm-discover[id]"
[{"{#DMID}":"mariadb20-task"},{"{#DMID}":"mysql57-task"}]

$ zabbix_get -s 127.0.0.1 -p 10050 -k "dm-discover[msg]"
[{"{#DMID}":"mariadb20-task","{#DMMES}":"Running"},{"{#DMID}":"mysql57-task","{#DMMES}":"[ddl:8200]Unsupported modify column: type varchar(4) not match origin int(4), and tidb_enable_change_column_type is false"}]

$ zabbix_get -s 127.0.0.1 -p 10050 -k "dm.check[mysql57-task]"
[ddl:8200]Unsupported modify column: type varchar(10) not match origin int(10), and tidb_enable_change_column_type is false

$ zabbix_get -s 127.0.0.1 -p 10050 -k "dm.check[mariadb20-task]"
success

7,配置自动发现,监控原型项,触发器等

创建模板参考上篇文章,监控ticdc,dm用了相同的模板

zabbix dm 监控项原型

zabbix dm 监控项原型

zabbix dm 监控项原型

zabbix dm 监控项原型

zabbix dm 触发器

zabbix dm 触发器

zabbix dm 最新数据

zabbix dm 最新数据



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

留下评论

留下评论
  • (必需)
  • (必需) (will not be published)
  • (必需)   8X6=?