Authored by wuxiao

添加承接golang前端的客户端

... ... @@ -25,18 +25,26 @@ influxdb_port = 8086
--[[
前端监听配置
--]]
http_mq_port = 9503
http_mq_port = 9500
worker_num = 8
daemonize = false
--[[
日志文件
路径配置
--]]
--working directory工作目录
pwd = '/www/yoho-phplog'
--pwd = '/Data/code/yoho-phplog'
--python路径
python = "/usr/bin/python"
--php路径
php = "/usr/bin/php56"
--php = "/Data/local/php/bin/php"
--日志文件
--log_file = nil
log_file = '/Data/code/yoho-phplog/access.log'
--[[
通道配置
--]]
... ... @@ -52,31 +60,3 @@ rabbitmq_ack_interval = 10
info_channel = 'YHInfo'
debug_channel = 'YHDebug'
shutdown_channel = 'YHShutdown'
--[[
执行检测代码
--]]
if log_file then
fp = io.open(log_file,'rb')
if fp ~= nil then
fp:close()
else
dir = string.match(log_file,"(.+)[/\\][^/\\]+")
dp = io.open(dir,'rb')
if dp ~= nil then
dp:close()
else
os.execute('mkdir -p '..dir..' 2>&1 > /dev/null')
end
dp = io.open(dir,'rb')
if dp ~= nil then
dp:close()
fp = io.open(log_file,'w')
if fp ~= nil then
fp:close()
end
end
end
end
\ No newline at end of file
... ...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: wuxiao
# @Date: 2016-05-24 13:37:45
# @Last Modified by: anchen
# @Last Modified time: 2016-05-24 18:40:09
import os
import sys
__FILE__ = os.path.abspath(sys.argv[0])
__DIR__ = os.path.dirname(os.path.abspath(sys.argv[0]))
import json
import time
import pika
from influxdb import InfluxDBClient
from lupa import LuaRuntime
'''
读取配置信息
'''
lua = LuaRuntime(unpack_returned_tuples=True)
lua.execute(open(__DIR__+'/Config.lua').read(-1))
Config = lua.globals()
q_name = 'log' #队列名
ack_interval = Config.rabbitmq_ack_interval #批量ack响应阀值
#连接rabbitmq
credentials = pika.PlainCredentials(Config.rabbitmq_user, Config.rabbitmq_pass)
connection = pika.BlockingConnection(pika.ConnectionParameters(
Config.rabbitmq_host,Config.rabbitmq_port,Config.rabbitmq_vhost,credentials))
if not connection:
exit("Cannot connect to the broker!\n")
channel = connection.channel()
#连接influxdb
influxdb = InfluxDBClient(Config.influxdb_host, Config.influxdb_port, timeout=1)
print "MqClient:Start.\n";
#开始消费消息数据
for method_frame, properties, body in channel.consume(q_name):
try:
#print method_frame.delivery_tag, method_frame, properties
print " [x] Received %r" % (body,)
data = json.loads(body)
#print data
#决定库表
if data['group'] == 'error':
db = 'error'
measurement = Config.debug_channel+time.strftime('_%Y%m%d')
elif data['group'] == 'shutdown':
db = 'error'
measurement = Config.shutdown_channel+time.strftime('_%Y%m%d')
else:
db = 'log'
measurement = Config.info_channel+time.strftime('_%Y%m%d')
#拼装入库数据
json_body = [
{
"measurement": measurement,
"tags": data['tags'],
#"time": "2009-11-10T23:00:00Z",
"fields": data['data']
}
]
#选择库,写入
influxdb.switch_database(db)
influxdb.write_points(json_body)
#ack回应
#channel.basic_ack(method_frame.delivery_tag)
if method_frame.delivery_tag % ack_interval == 0:
channel.basic_ack(multiple=True)
except Exception as err:
channel.basic_ack(method_frame.delivery_tag)
print err
continue
channel.cancel()
connection.close()
\ No newline at end of file
... ...
... ... @@ -7,15 +7,6 @@
class Rabbitmq
{
//配置信息
static $conn_args = array(
'host' => '54.222.219.223',
'port' => '5672',
'login' => 'guest',
'password' => 'guest',
'vhost' => '/'
);
static $conn;
static $channel;
... ... @@ -30,7 +21,15 @@ class Rabbitmq
//创建连接
$conn = self::$conn;
if (!is_object($conn) || !$conn->isConnected()){
$conn = new AMQPConnection(self::$conn_args);
//配置信息
$conn_args = array(
'host' => $Config->rabbitmq_host,
'port' => $Config->rabbitmq_port,
'login' => $Config->rabbitmq_user,
'password' => $Config->rabbitmq_pass,
'vhost' => $Config->rabbitmq_vhost,
);
$conn = new AMQPConnection($conn_args);
if (!$conn->connect()) {
echo ("Cannot connect to the broker!\n");
return;
... ...
--[[
配置文件
--]]
--[[
rabbitmq服务器
--]]
--rabbitmq_host = '127.0.0.1'
rabbitmq_host = '54.222.219.223'
rabbitmq_port = 5672
rabbitmq_user = 'guest'
rabbitmq_pass = 'guest'
rabbitmq_vhost = '/'
--[[
influxdb服务器
--]]
--influxdb_host = '127.0.0.1'
influxdb_host = '54.222.219.223'
influxdb_port = 8086
--[[
前端监听配置
--]]
http_mq_port = 9503
worker_num = 8
daemonize = false
--[[
日志文件
--]]
--log_file = nil
log_file = '/Data/code/yoho-phplog/access.log'
--[[
通道配置
--]]
--交换机名前缀
rabbitmq_exchange_name = 'yohoExchange_'
--路由键名
rabbitmq_route_key = 'phplog'
--队列名
rabbitmq_queue_name = 'phplog'
--批量ack响应阀值
rabbitmq_ack_interval = 10
info_channel = 'YHInfo'
debug_channel = 'YHDebug'
shutdown_channel = 'YHShutdown'
--[[
执行检测代码
--]]
if log_file then
fp = io.open(log_file,'rb')
if fp ~= nil then
fp:close()
else
dir = string.match(log_file,"(.+)[/\\][^/\\]+")
dp = io.open(dir,'rb')
if dp ~= nil then
dp:close()
else
os.execute('mkdir -p '..dir..' 2>&1 > /dev/null')
end
dp = io.open(dir,'rb')
if dp ~= nil then
dp:close()
fp = io.open(log_file,'w')
if fp ~= nil then
fp:close()
end
end
end
end
\ 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
#配置读取
vars=`sed -n '/^pwd\|^python\|^php\|^log_file/s/ \{1,\}= \{1,\}/=/p' Config.lua`
eval $vars
if [ ! -f "$log_file" ];then
dir=`dirname $log_file`
if [ ! -d $dir ];then
mkdir -p $dir
fi
touch $log_file
chmod 777 $log_file
fi
monitor(){
#pid=`ps aux|grep $1.php|$wc -l`
pid=`ps aux|grep "$1"|$wc -l`
pid=`ps aux|grep "$1"|wc -l`
if [ $pid -le 1 ];then
msg="At time: `date` :$1 is stop ."
... ... @@ -40,6 +38,7 @@ while true;do
#mqclient
monitor "$python $pwd/MqClient.py"
monitor "$python $pwd/GoMqClient.py.py"
sleep 5
... ...