在VCL中是否可以在条件下使用清漆计数器?
我想写一个基于MAIN.backend_conn的当前值的条件,但我不知道是否可以在VCL中使用统计信息,即使在内联C中也可以使用。
当前解决方案
现在我使用如下配置:
backend default {
.host = "192.168.122.11";
.probe = {
.url = "/check-connections.php";
.interval = 1s;
.threshold = 4;
}
}
backend sessionWorker {
.host = "192.168.122.11";
.probe = {
.url = "/other-probe";
.interval = 5s;
.threshold = 2;
}
}
sub vcl_recv {
if (req.http.cookie ~ "(^|;\s*)(SESS=)" || std.healthy(req.backend_hint)) {
set req.backend_hint = sessionWorker;
} else {
return (synth(503, "Server overloaded"));
}
}check-connections.php读取nginx状态为活动的连接,如果有更多的活动连接,则会触发错误:
if ($active > 10) {
http_response_code(502);
} else {
http_response_code(200);
}我想找一个解决方案,如何将std.healty(req.backend_hint)替换为VCL中直接到后端的当前连接(VBE.conn)。
发布于 2016-06-12 05:02:43
已经实现了一些计数器。像bereq.retries一样
sub vcl_backend_response {
if (beresp.status == 503 && bereq.retries < 5 ) {
return(retry);
}
}
sub vcl_backend_error {
if (beresp.status == 503 && bereq.retries == 5) {
synthetic(std.fileread("/path/to/my/file/varnish503.html"));
return(deliver);
}
}也许这已经是你需要的了。否则,here是其他内置计数器的列表。
https://stackoverflow.com/questions/37653243
复制相似问题