-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c63033a
commit 0465806
Showing
15 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
local BasePlugin = require "kong.plugins.base_plugin" | ||
local init_worker = require "kong.reports.init_worker" | ||
local log = require "kong.reports.log" | ||
|
||
local ReportsHandler = BasePlugin:extend() | ||
|
||
function ReportsHandler:new() | ||
ReportsHandler.super.new(self, "reports") | ||
end | ||
|
||
function ReportsHandler:init_worker() | ||
ReportsHandler.super.init_worker(self) | ||
init_worker.execute() | ||
end | ||
|
||
function ReportsHandler:log() | ||
ReportsHandler.super.log(self) | ||
log.execute() | ||
end | ||
|
||
return ReportsHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
local syslog = require "kong.tools.syslog" | ||
local lock = require "resty.lock" | ||
local cache = require "kong.tools.database_cache" | ||
|
||
local INTERVAL = 3600 | ||
|
||
local _M = {} | ||
|
||
local function create_timer(at, cb) | ||
local ok, err = ngx.timer.at(at, cb) | ||
if not ok then | ||
ngx.log(ngx.ERR, "[reports] failed to create timer: ", err) | ||
end | ||
end | ||
|
||
local function send_ping(premature) | ||
local lock = lock:new("locks", { | ||
exptime = INTERVAL - 0.001 | ||
}) | ||
local elapsed = lock:lock("ping") | ||
if elapsed and elapsed == 0 then | ||
local reqs = cache.get(cache.requests_key()) | ||
if not reqs then reqs = 0 end | ||
syslog.log({signal = "ping", requests=reqs}) | ||
end | ||
create_timer(INTERVAL, send_ping) | ||
end | ||
|
||
function _M.execute() | ||
cache.rawset(cache.requests_key(), 0, 0) -- Initializing the counter | ||
create_timer(0, send_ping) | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
local cache = require "kong.tools.database_cache" | ||
|
||
local _M = {} | ||
|
||
function _M.execute(conf) | ||
cache.incr(cache.requests_key(), 1) | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters