Merge remote-tracking branch 'origin/master' into accounts
This commit is contained in:
commit
ed04aa0e74
|
@ -73,6 +73,7 @@ services:
|
|||
- ./docker/nginx/conf.d:/etc/nginx/conf.d:ro
|
||||
- ./docker/data/nginx/cache:/data/nginx/cache
|
||||
- ./docker/data/nginx/logs:/usr/local/openresty/nginx/logs
|
||||
- ./docker/data/nginx/skynet:/data/nginx/skynet:ro
|
||||
- ./docker/data/sia/apipassword:/data/sia/apipassword:ro
|
||||
- webapp:/var/www/webportal:ro
|
||||
networks:
|
||||
|
|
|
@ -54,9 +54,9 @@ server {
|
|||
client_max_body_size 128k;
|
||||
|
||||
# legacy endpoint rewrite
|
||||
rewrite /portals /skynet/portals permanent;
|
||||
rewrite /stats /skynet/stats permanent;
|
||||
rewrite /skynet/blacklist /skynet/blocklist permanent;
|
||||
rewrite ^/portals /skynet/portals permanent;
|
||||
rewrite ^/stats /skynet/stats permanent;
|
||||
rewrite ^/skynet/blacklist /skynet/blocklist permanent;
|
||||
|
||||
location / {
|
||||
# This is only safe workaround to reroute based on some conditions
|
||||
|
@ -105,6 +105,33 @@ server {
|
|||
location /skynet/stats {
|
||||
include /etc/nginx/conf.d/include/cors;
|
||||
|
||||
set $response_body ''; # we need a variable for full response body (not chuncked)
|
||||
|
||||
# modify the response to add numfiles and totalsize to account for node rotation
|
||||
# example prevstats.lua: 'return { numfiles = 12345, totalsize = 123456789 }'
|
||||
body_filter_by_lua_block {
|
||||
local file_exists = io.open("/data/nginx/skynet/prevstats.lua")
|
||||
if file_exists then
|
||||
file_exists.close()
|
||||
|
||||
-- because response data is chunked, we need to concat ngx.arg[1] until
|
||||
-- last chunk is received (when ngx.arg[2] is set to true)
|
||||
ngx.var.response_body = ngx.var.response_body .. ngx.arg[1]
|
||||
|
||||
if ngx.arg[2] then
|
||||
local json = require('cjson')
|
||||
local prevstats = require('/data/nginx/skynet/prevstats')
|
||||
local stats = json.decode(ngx.var.response_body)
|
||||
stats.uploadstats.numfiles = stats.uploadstats.numfiles + prevstats.numfiles
|
||||
stats.uploadstats.totalsize = stats.uploadstats.totalsize + prevstats.totalsize
|
||||
ngx.arg[1] = json.encode(stats)
|
||||
else
|
||||
-- do not send any data in this chunk (wait for last chunk)
|
||||
ngx.arg[1] = nil
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
proxy_cache skynet;
|
||||
proxy_cache_valid any 10m; # cache stats for 10 minutes
|
||||
proxy_set_header User-Agent: Sia-Agent;
|
||||
|
@ -115,6 +142,8 @@ server {
|
|||
location /health-check {
|
||||
include /etc/nginx/conf.d/include/cors;
|
||||
|
||||
access_log off; # do not log traffic to health-check endpoint
|
||||
|
||||
proxy_pass http://health-check:3100;
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue