-
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
a9ff1bd
commit 417c137
Showing
14 changed files
with
177 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
local stringy = require "stringy" | ||
|
||
local _M = {} | ||
|
||
function _M.get_hostname() | ||
local f = io.popen ("/bin/hostname") | ||
local hostname = f:read("*a") or "" | ||
f:close() | ||
hostname = string.gsub(hostname, "\n$", "") | ||
return hostname | ||
end | ||
|
||
function _M.parse_status(value) | ||
local result = {} | ||
local parts = stringy.split(value, "\n") | ||
for i, v in ipairs(parts) do | ||
local part = stringy.strip(v) | ||
if i == 1 then | ||
result["connections_active"] = tonumber(string.sub(part, string.find(part, "%d+"))) | ||
elseif i == 3 then | ||
local counter = 1 | ||
local stat_names = { "connections_accepted", "connections_handled", "total_requests"} | ||
for stat in string.gmatch(part, "%S+") do | ||
result[stat_names[counter]] = tonumber(stat) | ||
counter = counter + 1 | ||
end | ||
elseif i == 4 then | ||
local reading, writing, waiting = string.match(part, "%a+:%s*(%d+)%s*%a+:%s*(%d+)%s*%a+:%s*(%d+)") | ||
result["connections_reading"] = tonumber(reading) | ||
result["connections_writing"] = tonumber(writing) | ||
result["connections_waiting"] = tonumber(waiting) | ||
end | ||
end | ||
return result | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
return { | ||
fields = { | ||
origin = { type = "string" }, | ||
headers = { type = "string" }, | ||
exposed_headers = { type = "string" }, | ||
methods = { type = "string" }, | ||
headers = { type = "array" }, | ||
exposed_headers = { type = "array" }, | ||
methods = { type = "array", enum = { "HEAD", "GET", "POST", "PUT", "PATCH", "DELETE" } }, | ||
max_age = { type = "number" }, | ||
credentials = { type = "boolean", default = false }, | ||
preflight_continue = { type = "boolean", default = false } | ||
} | ||
} | ||
} |
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 route_helpers = require "kong.api.route_helpers" | ||
|
||
describe("Route Helpers", function() | ||
|
||
it("should return the hostname", function() | ||
assert.truthy(route_helpers.get_hostname()) | ||
end) | ||
|
||
it("should return parse the nginx status", function() | ||
local status = "Active connections: 33 \nserver accepts handled requests\n 3 5 7 \nReading: 314 Writing: 1 Waiting: 2 \n" | ||
local res = route_helpers.parse_status(status) | ||
|
||
assert.are.equal(33, res.connections_active) | ||
assert.are.equal(3, res.connections_accepted) | ||
assert.are.equal(5, res.connections_handled) | ||
assert.are.equal(7, res.total_requests) | ||
assert.are.equal(314, res.connections_reading) | ||
assert.are.equal(1, res.connections_writing) | ||
assert.are.equal(2, res.connections_waiting) | ||
end) | ||
end) |
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
417c137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit also exposes a
/status
endpoint on the admin API for basic monitoring purposes.