healthcheck

This commit is contained in:
xingchaowang 2015-03-11 14:05:19 +08:00
parent f6f7f3a020
commit f29d7388ce
3 changed files with 16 additions and 6 deletions

View file

@ -12,11 +12,16 @@ import com.ctrip.zeus.model.entity.VirtualServer;
public class HealthCheckConf {
public static String generate(Slb slb, VirtualServer vs, App app) {
HealthCheck h = app.getHealthCheck();
return "health_check " +
" match=server_ok " +
" uri=" + h.getUri() +
" interval=" + h.getIntervals() +
" fails=" + h.getFails() +
" passes=" + h.getPasses();
StringBuilder b = new StringBuilder(128);
b.append(" ").append("check interval=").append(h.getIntervals())
.append(" rise").append(h.getPasses())
.append(" fall").append(h.getFails())
.append(" timeout=").append(1000)
.append(" type=http").append(";\n");
b.append(" ").append("check_keepalive_requests 100").append(";\n");
b.append(" ").append("check_http_send \"GET ").append(h.getUri()).append(" HTTP/1.1\\r\\nConnection: keep-alive\\r\\n\\r\\n\"").append(";\n");
b.append(" ").append("check_http_expect_alive http_2xx http_3xx").append(";\n");
return b.toString();
}
}

View file

@ -15,7 +15,9 @@ public class LocationConf {
b.append(" ").append("location ").append(getPath(slb, vs, app)).append("{").append("\n");
b.append(" ").append(" check_status").append(";\n");
b.append(" ").append(" proxy_pass http://").append(upstreamName).append(";\n");
//ToDo:health_check
//b.append(" ").append(" ").append(HealthCheckConf.generate(slb,vs,app)).append(";\n");

View file

@ -44,6 +44,9 @@ public class UpstreamsConf {
.append(";\n");
}
//HealthCheck
b.append(HealthCheckConf.generate(slb,vs,app));
b.append("}").append("\n");
return b.toString();