既有的Telegraf 关于MongoDB的输入插件很难实现对副本集节点状态的监控,副本集节点状态有 PRIMARY、SECONDARY、RECOVERYING、ARBITER 等。现在我们尝试通过 Exec Input Plugin 来实现对MongoDB状态的的监控。
第一部分 简单回顾下Zabbix的监控实现 1. Zabbix 执行的文件脚本如下:#!/bin/bash command_linebin="mongodb可执行文件路径/bin/mongo" replstatus="PRIMARY SECONDARY ARBITER" username="user" password="pwd" command_line="${command_linebin} localhost:$1/admin -u$username -p$password" mcount=$(/bin/echo "rs.status().members.length" | $command_line --quiet) if [ $mcount -ge 3 ] ;then ms1=$(/bin/echo "rs.status().members[0].stateStr" | $command_line --quiet) ms2=$(/bin/echo "rs.status().members[1].stateStr" | $command_line --quiet) ms3=$(/bin/echo "rs.status().members[2].stateStr" | $command_line --quiet) if [[ $replstatus =~ $ms1 ]] && [[ $replstatus =~ $ms2 ]] && [[ $replstatus =~ $ms3 ]] ;then echo "The Status OK " else echo "The status of mongo replica is unnormal.port is " $1 fi else ms1=$(/bin/echo "rs.status().members[0].stateStr" | $command_line --quiet) ms2=$(/bin/echo "rs.status().members[1].stateStr" | $command_line --quiet) if [[ $replstatus =~ $ms1 ]] && [[ $replstatus =~ $ms2 ]] ;then echo "The Status OK " else echo "The status of mongo replica is unnormal.port is " $1 fi fi