node tail 日志服务
2014-01-27 15:00
190 查看
var http = require('http'), ,spawn = require('child_process').spawn function onRequest(req, res) { var reqUrl = req.url if ('/' == reqUrl || 'favicon.ico' == reqUrl) { return res.end('Im debugger') } res.writeHead(200 ,{'Content-Type': 'text/plain','Cache-Control': 'no-cache,no-store'}) } var logFile = 'xxxxx' tailLog(logFile) req.on('close' ,function(){ console.log('aborted') req.tail.kill('SIGHUP') }) function tailLog(logFile) { //console.log(logFile) logFile = logFile.trim() if (!logFile) return res.end('Log File lost') var tail = req.tail = spawn('tail' , ['-f' , logFile]) tail.stdout.on('data' , function(data){ var line = data.toString('utf-8') console.log(line) res.write(line) }) } } var arguments = process.argv.splice(2) http.createServer(onRequest).listen(arguments[0] || 2014)
服务通过 nginx 反向代理后 要注意 conf 里需要配置 proxy_buffering off; 不然 nginx 要一直等 node,没有任何响应
相关文章推荐
- 打通钉钉+WebHook:日志服务告警升级
- ElasticSearch+LogStash+Kibana+Redis搭建日志管理服务
- 如何将日志服务的数据秒级同步到表格存储
- Windows服务安装异常:System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
- rsync通过服务同步、日志文件、screen工具
- linux学习入门 基础部分(9)[1.系统日志默认分类2.日志管理服务rsyslog3.日志分析工具journa4.时间同步5.timedatectl命令]
- HiJackThis(HJT)日志在线自动分析服务
- 阿里云日志服务基础
- 基于服务发现的操作日志服务 foruo-sc-log
- 在线清理Apache、Tomcat、Nginx等Web服务产生的日志文件
- 在RHEL6.X上安装(rsyslog+mysql+loganalyzer+evtsys)日志服务
- 配置Linux的Syslog服务来记录Cisco路由器的日志(基本配置)
- 阿里云日志服务日志写入华东2配置
- mysql二进制日志文件出错导致mysql服务无法启动
- linux xinetd服务通信 日志
- 系统日志服务rsyslog
- 计划任务与日志服务
- 10.32/10.33 rsync通过服务同步 10.34 linux系统日志 screen工具
- rsync通过服务的方式同步、linux系统日志、screen工具
- devstack查看服务日志