目录规划
[root@redis02 ]# tree -d -L 1 falcon falcon ## 主目录 ├── agent ## agent ├── mongomon ## mongodb 监控脚本 └── redismon ## redis监控脚本 ......
agent 目录及文件
[root@redis02 goluk]# tree -L 1 falcon/agent falcon/agent ├── bin ## agent命令目录 ├── cfg.json ## 配置文件(从config目录拷贝出来 ├── config ## 配置目录 ├── control ## agent服务启动停止脚本 ├── logs ├── plugins └── public
cfg.json说明
修改heartbeat 和 transfer 小节内的ip addr指向 falcon server
"heartbeat": {
"enabled": true,
"addr": "192.168.1.248:6030",
"interval": 60,
"timeout": 1000
},
"transfer": {
"enabled": true,
"addrs": [
"192.168.1.248:8433"
],
"interval": 60,
"timeout": 1000
},
control脚本
来自mail-provider模块,略微修改后作为agent启停脚本
#!/bin/bash
WORKSPACE=$(cd $(dirname $0)/; pwd)
cd $WORKSPACE
#mkdir -p var
module=agent
app=falcon-$module
conf=cfg.json
localconf=cfg.local.json
pidfile=logs/$module.pid
logfile=logs/$module.log
function check_pid() {
if [ -f $pidfile ];then
pid=`cat $pidfile`
if [ -n $pid ]; then
running=`ps -p $pid|grep -v "PID TTY" |wc -l`
return $running
fi
fi
return 0
}
function start() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo -n "$app now is running already, pid="
cat $pidfile
return 1
fi
c=$conf
if [ -f $localconf ];then
c=$localconf
fi
nohup ./bin/$app -c $c &> $logfile &
echo $! > $pidfile
echo "$app started..., pid=$!"
}
function stop() {
pid=`cat $pidfile`
kill $pid
echo "$app stoped..."
}
function restart() {
stop
sleep 1
start
}
function status() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo "started"
else
echo "stoped"
fi
}
function tailf() {
tail -f $logfile
}
function build() {
go build
if [ $? -ne 0 ]; then
exit $?
fi
mv $module $app
./$app -v
}
function pack() {
build
version=`./$app -v`
tar zcvf $app-$version.tar.gz control cfg.json $app
}
function packbin() {
build
version=`./$app -v`
tar zcvf $app-bin-$version.tar.gz $app
}
function help() {
echo "$0 pid|reload|build|pack|packbin|start|stop|restart|status|tail"
}
function pid() {
cat $pidfile
}
function reload() {
build
restart
tailf
}
if [ "$1" == "" ]; then
help
elif [ "$1" == "stop" ];then
stop
elif [ "$1" == "start" ];then
start
elif [ "$1" == "restart" ];then
restart
elif [ "$1" == "status" ];then
status
elif [ "$1" == "tail" ];then
tailf
elif [ "$1" == "build" ];then
build
elif [ "$1" == "pack" ];then
pack
elif [ "$1" == "packbin" ];then
packbin
elif [ "$1" == "pid" ];then
pid
elif [ "$1" == "reload" ];then
reload
else
help
fi
启停命令
cd agent ./control start/stop