這邊假設管理人員需要針對伺服器的連線時間過長(在此為5秒)的這個Event增加操作,操作中會去觸發一個HTTP的連線,連線中就可以由開發人員撰寫相關程式來達到通知、記錄、甚至Cloud Scale Out的目的...
此邏輯的設計包含:
- Request Rule(RULE_SET_RESP_TIME_FLAG)做進入時間記錄
- Response Rule(RULE_SET_RESP_TIME)做回應時間記錄,並操作HTTP連線動作
Rule的原始碼如下:
RULE_SET_RESP_TIME_FLAG.rule
$tm = sys.time(); connection.data.set("start", $tm);
RULE_SET_RESP_TIME.rule
# Response time in (integer) seconds above
$THRESHOLD =5;
# which requests are logged.
$start = connection.data.get("start");
$now = sys.time();
$diff =($now - $start);
if( $diff >= $THRESHOLD ){
$uri = http.getRawURL();
$node = connection.getNode();
log.info ("SLOW REQUEST (". $diff ."s) ". $node .":". $uri );
# Doing scale out...
http.request.get("http://your.server.ip.address:300/scaleout" );
}