Linux Shell:尾随日志文件并使用curl将每一行发送到http服务

时间:2015-02-19 19:43:33

标签: linux shell curl logging tail

我正在收集日志,需要将日志发送到实时日志监控系统。 日志监视器系统通过http服务接收消息。

此命令有效:

tail -F app.2015-02-17.log | sed -e "s/\"//g" |  awk '{print "{\"topic\":\"EC_IPService_Log\",\"message\":\""$0"\"}"}'|while read LINE ; do (curl -X POST -H "Authorization:Basic cm9ja2V0bXE6cm9ja2V0bXE=" -H "mq-version:1" -H "Content-Type:application/json"  http://localhost:9999/MQ/sendMessage -d "$LINE") ; done

问题是这个命令运行速度不够快,无法处理来自tail命令的日志,所以它越来越慢。当我运行此命令10小时时,它可能会在一小时前处理日志...

如果我将curl命令改为如下所示回显:

tail -F app.2015-02-17.log | sed -e "s/\"//g" |  awk '{print "{\"topic\":\"EC_IPService_Log\",\"message\":\""$0"\"}"}'|while read LINE ; do (echo "$LINE") ; done

此命令运行得足够快。

有没有更好的解决方案来使用curl来解决这个问题? 提前谢谢。

0 个答案:

没有答案