Authored by wuxiao

整理代码

... ... @@ -4,7 +4,6 @@ error_reporting(E_ALL);
ini_set('display_errors',true);
require_once __DIR__.'/Config.php';
require_once __DIR__.'/InfluxdbLog.php';
require_once __DIR__.'/Rabbitmq.php';
/**
... ... @@ -13,20 +12,6 @@ require_once __DIR__.'/Rabbitmq.php';
class Sender{
/**
* 添加记录
* @param array $data
* @param array $tags
* @return type
*/
static function add($type,array $data,array $tags = []){
$tags = $tags + array(
'ip'=>'',
'hostname'=>'',
);
return InfluxdbLog::handle($type,$data,$tags);
}
/**
* 添加到队列中
* @param array $data
* @param array $tags
... ...
<?php
error_reporting(E_ALL);
ini_set('display_errors',true);
require_once __DIR__.'/Config.php';
require_once __DIR__.'/InfluxdbLog.php';
require_once __DIR__.'/Rabbitmq.php';
/**
* 发送者类
*/
class Sender{
/**
* 添加记录
* @param array $data
* @param array $tags
* @return type
*/
static function add($type,array $data,array $tags = []){
$tags = $tags + array(
'ip'=>'',
'hostname'=>'',
);
return InfluxdbLog::handle($type,$data,$tags);
}
/**
* 添加到队列中
* @param array $data
* @param array $tags
* @return type
*/
static function pushmq($type,array $data,array $tags = []){
$tags = $tags + array(
'ip'=>'',
'hostname'=>'',
);
return Rabbitmq::handle($type, $data, $tags);
}
/**
* 写日志
* @param type $message
* @return type
*/
static function log($message){
echo $message."\n";
if (!Config::log_file){
return;
}
$fp = @fopen(Config::log_file,'a');
if (!$fp){
return;
}
$r = fwrite($fp, $message."\n");
fclose($fp);
return $r;
}
}
\ No newline at end of file
... ...
#!/bin/sh
#working directory
pwd="/Data/code/yoho-phplog"
pgrep="/usr/bin/pgrep"
wc="/usr/bin/wc"
lsof="/usr/sbin/lsof"
python="/usr/bin/python"
php="/Data/local/php/bin/php"
log_file=$pwd'/access.log'
if [ ! -f $log_file ];then
touch $log_file
chmod 777 $log_file
fi
monitor(){
#pid=`ps aux|grep $1.php|$wc -l`
pid=`ps aux|grep "$1"|$wc -l`
if [ $pid -le 1 ];then
msg="At time: `date` :$1 is stop ."
echo $msg
echo $msg >> $log_file
#cmd="$php -f $pwd/$1.php"
cmd="$1"
echo $cmd
echo $cmd >> $log_file
$cmd 2>&1 &
else
echo "$1 is running ."
fi
}
while true;do
#http
monitor "$php -f $pwd/HttpServer.php"
monitor "$php -f $pwd/HttpMqServer.php"
#tcp
monitor "$php -f $pwd/TcpServer.php"
#udp
monitor "$php -f $pwd/UdpServer.php"
#mqclient
monitor "$python $pwd/MqClient.py"
sleep 5
done
... ...
... ... @@ -35,16 +35,9 @@ monitor(){
while true;do
#http
monitor "$php -f $pwd/HttpServer.php"
#http mq
monitor "$php -f $pwd/HttpMqServer.php"
#tcp
monitor "$php -f $pwd/TcpServer.php"
#udp
monitor "$php -f $pwd/UdpServer.php"
#mqclient
monitor "$python $pwd/MqClient.py"
... ...