Browse Source

暂时去除流量监控功能

zjcqoo 6 years ago
parent
commit
b8e6d6c38a
4 changed files with 0 additions and 124 deletions
  1. 0 37
      lua/g.lua
  2. 0 6
      lua/init.lua
  3. 0 72
      lua/worker.lua
  4. 0 9
      nginx.conf

+ 0 - 37
lua/g.lua

@@ -1,37 +0,0 @@
-local _M = {}
-local traff = ngx.shared.traff
-
-local nReq = 0
-
-
-function _M.inc()
-  nReq = nReq + 1
-end
-
-function _M.syn()
-  traff:incr('nReq', nReq)
-  nReq = 0
-end
-
-function _M.update()
-  local nReq = traff:get('nReq')
-  traff:set('nReq', 0)
-  return nReq
-end
-
-function _M.getStat()
-  return traff:get('stat')
-end
-
-function _M.setStat(stat)
-  return traff:set('stat', stat)
-end
-
-function _M.reset()
-  if traff:get('nReq') == nil then
-    traff:add('nReq', 0)
-    traff:add('stat', '')
-  end
-end
-
-return _M

+ 0 - 6
lua/init.lua

@@ -1,6 +0,0 @@
-local traff = ngx.shared.traff
-
-if traff:get('nReq') == nil then
-  traff:add('nReq', 0)
-  traff:add('stat', '')
-end

+ 0 - 72
lua/worker.lua

@@ -1,72 +0,0 @@
-local g = require('g')
-
--- run in master worker
-if ngx.worker.id() ~= 0 then
-  return
-end
-
-local function buildDevTrafficFn(dev)
-  local regex = dev ..
-    [[:\s+(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)]]
-  --        0      1     2     3     4     5     6     7    | 8
-  -- eth0: bytes packets errs drop fifo frame compress multi| bytes 
-
-  local lastRxBytes = 0
-  local lastTxBytes = 0
-
-  return function(str)
-    local m = ngx.re.match(str, regex, 'oi')
-    if m == nil then
-      return '0,0'
-    end
-    local sRxBytes = m[1]
-    local sTxBytes = m[2]
-
-    if sTxBytes == nil then
-      return '0,0'
-    end
-
-    local nRxBytes = tonumber(sRxBytes)
-    local nTxBytes = tonumber(sTxBytes)
-
-    local rxBPS = nRxBytes - lastRxBytes
-    local txBPS = nTxBytes - lastTxBytes
-
-    lastRxBytes = nRxBytes
-    lastTxBytes = nTxBytes
-
-    return rxBPS .. ',' .. txBPS
-  end
-end
-
-
-local fileStat = io.open('/proc/net/dev')
-if fileStat == nil then
-  ngx.log(ngx.ERR, 'open `/proc/net/dev` fail')
-  return
-end
-
-local firstRun = true
-local getDevTraffic = buildDevTrafficFn('eth0')
-
-
-local function updateTraffic()
-  local r, err = fileStat:seek('set')
-  local out = fileStat:read('*all')
-
-  local traffDev = getDevTraffic(out)
-
-  if firstRun then
-    firstRun = false
-    return
-  end
-
-  g.syn()
-
-  local traffHttp = g.update()
-  local stat = traffDev .. ',' .. traffHttp
-
-  g.setStat(stat)
-end
-
-ngx.timer.every(1, updateTraffic)

+ 0 - 9
nginx.conf

@@ -58,16 +58,7 @@ http {
   proxy_busy_buffers_size 64k;
   proxy_send_timeout      10s;
 
-  # https://github.com/openresty/lua-nginx-module
-
-  # traffic statistics
-  lua_shared_dict         traff   16k;
-
   lua_load_resty_core     off;
-  lua_package_path        ./lua/?.lua;
-  init_by_lua_file        ../lua/init.lua;
-  init_worker_by_lua_file ../lua/worker.lua;
-  # log_by_lua              require('g').inc();
 
   map $http_origin $_origin_id {
     include               allowed-sites.conf;