-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics: add metrics for the upstream
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
local tonumber = tonumber | ||
|
||
local prometheus = require('apicast.prometheus') | ||
|
||
local _M = {} | ||
|
||
local upstream_status_codes = prometheus( | ||
'counter', | ||
'upstream_status', | ||
'HTTP status from upstream servers', | ||
{ 'status' } | ||
) | ||
|
||
local upstream_resp_times = prometheus( | ||
'histogram', | ||
'upstream_resp_times', | ||
'Response times from upstream servers' | ||
) | ||
|
||
local function inc_status_codes_counter(status) | ||
if status and upstream_status_codes then | ||
upstream_status_codes:inc(1, { status }) | ||
end | ||
end | ||
|
||
local function add_resp_time(response_time) | ||
if response_time and upstream_resp_times then | ||
upstream_resp_times:observe(tonumber(response_time)) | ||
end | ||
end | ||
|
||
function _M.report(status, response_time) | ||
inc_status_codes_counter(status) | ||
add_resp_time(response_time) | ||
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