struct freq_ctr sess_per_sec; /* sessions per second on this server */
struct freq_ctr req_per_sec; /* HTTP requests per second on the frontend */
struct freq_ctr conn_per_sec; /* received connections per second on the frontend */
+
+ unsigned long last_change; /* last time, when the state was changed */
};
/* counters used by servers and backends */
unsigned int conn_max; /* max # of active sessions */
long long cum_sess; /* cumulated number of accepted connections */
long long cum_lbconn; /* cumulated number of sessions processed by load balancing (BE only) */
- unsigned long last_sess; /* last session time */
unsigned int cps_max; /* maximum of new connections received per second */
unsigned int sps_max; /* maximum of new connections accepted per second (sessions) */
} p; /* protocol-specific stats */
struct freq_ctr sess_per_sec; /* sessions per second on this server */
+
+ unsigned long last_sess; /* last session time */
+ unsigned long last_change; /* last time, when the state was changed */
};
#endif /* _HAPROXY_COUNTERS_T_H */
unsigned int retry_type; /* Type of retry allowed */
int redispatch_after; /* number of retries before redispatch */
unsigned down_time; /* total time the proxy was down */
- time_t last_change; /* last time, when the state was changed */
int (*accept)(struct stream *s); /* application layer's accept() */
struct conn_src conn_src; /* connection source settings */
enum obj_type *default_target; /* default target to use for accepted streams or NULL */
struct xprt_ops *xprt; /* transport-layer operations */
unsigned int svc_port; /* the port to connect to (for relevant families) */
unsigned down_time; /* total time the server was down */
- time_t last_change; /* last time, when the state was changed */
int puid; /* proxy-unique server ID, used for SNMP, and "first" LB algo */
int tcp_ut; /* for TCP, user timeout */
*/
void set_backend_down(struct proxy *be)
{
- be->last_change = ns_to_sec(now_ns);
+ be->be_counters.last_change = ns_to_sec(now_ns);
_HA_ATOMIC_INC(&be->be_counters.down_trans);
if (!(global.mode & MODE_STARTING)) {
}
int be_downtime(struct proxy *px) {
- if (px->lbprm.tot_weight && px->last_change < ns_to_sec(now_ns)) // ignore negative time
+ if (px->lbprm.tot_weight && px->be_counters.last_change < ns_to_sec(now_ns)) // ignore negative time
return px->down_time;
- return ns_to_sec(now_ns) - px->last_change + px->down_time;
+ return ns_to_sec(now_ns) - px->be_counters.last_change + px->down_time;
}
/*
s->queue.length);
if ((s->cur_state == SRV_ST_STARTING) &&
- ns_to_sec(now_ns) < s->last_change + s->slowstart &&
- ns_to_sec(now_ns) >= s->last_change) {
- ratio = MAX(1, 100 * (ns_to_sec(now_ns) - s->last_change) / s->slowstart);
+ ns_to_sec(now_ns) < s->counters.last_change + s->slowstart &&
+ ns_to_sec(now_ns) >= s->counters.last_change) {
+ ratio = MAX(1, 100 * (ns_to_sec(now_ns) - s->counters.last_change) / s->slowstart);
chunk_appendf(buf, "; throttle=%d%%", ratio);
}
init_new_proxy(fe);
fe->next = proxies_list;
proxies_list = fe;
- fe->last_change = ns_to_sec(now_ns);
+ fe->fe_counters.last_change = ns_to_sec(now_ns);
fe->id = strdup("GLOBAL");
fe->cap = PR_CAP_FE|PR_CAP_INT;
fe->maxconn = 10; /* default to 10 concurrent connections */
/* conf->agent_fe was already initialized during the config
* parsing. Finish initialization. */
- conf->agent_fe.last_change = ns_to_sec(now_ns);
+ conf->agent_fe.fe_counters.last_change = ns_to_sec(now_ns);
conf->agent_fe.cap = PR_CAP_FE;
conf->agent_fe.mode = PR_MODE_TCP;
conf->agent_fe.maxconn = 0;
px->conf.file = strdup(file);
px->conf.line = linenum;
px->mode = PR_MODE_SYSLOG;
- px->last_change = ns_to_sec(now_ns);
+ px->fe_counters.last_change = ns_to_sec(now_ns);
px->cap = PR_CAP_FE;
px->maxconn = 10;
px->timeout.client = TICK_ETERNITY;
/* Pre-configures a peers frontend to accept incoming connections */
void peers_setup_frontend(struct proxy *fe)
{
- fe->last_change = ns_to_sec(now_ns);
+ fe->fe_counters.last_change = ns_to_sec(now_ns);
fe->cap = PR_CAP_FE | PR_CAP_BE;
fe->mode = PR_MODE_PEERS;
fe->maxconn = 0;
*/
struct proxy *alloc_new_proxy(const char *name, unsigned int cap, char **errmsg)
{
+ uint last_change;
struct proxy *curproxy;
if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) {
}
init_new_proxy(curproxy);
- curproxy->last_change = ns_to_sec(now_ns);
+
+ last_change = ns_to_sec(now_ns);
+ if (cap & PR_CAP_FE)
+ curproxy->fe_counters.last_change = last_change;
+ if (cap & PR_CAP_BE)
+ curproxy->be_counters.last_change = last_change;
+
curproxy->id = strdup(name);
curproxy->cap = cap;
dump_server_addr(&srv->check.addr, srv_check_addr);
dump_server_addr(&srv->agent.addr, srv_agent_addr);
- srv_time_since_last_change = ns_to_sec(now_ns) - srv->last_change;
+ srv_time_since_last_change = ns_to_sec(now_ns) - srv->counters.last_change;
bk_f_forced_id = px->options & PR_O_FORCED_ID ? 1 : 0;
srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0;
s->proxy->beconn * s->maxconn / s->proxy->fullconn);
if ((s->cur_state == SRV_ST_STARTING) &&
- ns_to_sec(now_ns) < s->last_change + s->slowstart &&
- ns_to_sec(now_ns) >= s->last_change) {
+ ns_to_sec(now_ns) < s->counters.last_change + s->slowstart &&
+ ns_to_sec(now_ns) >= s->counters.last_change) {
unsigned int ratio;
- ratio = 100 * (ns_to_sec(now_ns) - s->last_change) / s->slowstart;
+ ratio = 100 * (ns_to_sec(now_ns) - s->counters.last_change) / s->slowstart;
max = MAX(1, max * ratio / 100);
}
return max;
void resolvers_setup_proxy(struct proxy *px)
{
- px->last_change = ns_to_sec(now_ns);
+ px->fe_counters.last_change = px->be_counters.last_change = ns_to_sec(now_ns);
px->cap = PR_CAP_FE | PR_CAP_BE;
px->maxconn = 0;
px->conn_retries = 1;
int srv_downtime(const struct server *s)
{
- if ((s->cur_state != SRV_ST_STOPPED) || s->last_change >= ns_to_sec(now_ns)) // ignore negative time
+ if ((s->cur_state != SRV_ST_STOPPED) || s->counters.last_change >= ns_to_sec(now_ns)) // ignore negative time
return s->down_time;
- return ns_to_sec(now_ns) - s->last_change + s->down_time;
+ return ns_to_sec(now_ns) - s->counters.last_change + s->down_time;
}
int srv_lastsession(const struct server *s)
struct proxy *px = sv->proxy;
unsigned w;
- if (ns_to_sec(now_ns) < sv->last_change || ns_to_sec(now_ns) >= sv->last_change + sv->slowstart) {
+ if (ns_to_sec(now_ns) < sv->counters.last_change || ns_to_sec(now_ns) >= sv->counters.last_change + sv->slowstart) {
/* go to full throttle if the slowstart interval is reached unless server is currently down */
if ((sv->cur_state != SRV_ST_STOPPED) && (sv->next_state == SRV_ST_STARTING))
sv->next_state = SRV_ST_RUNNING;
if ((sv->cur_state == SRV_ST_STOPPED) && (sv->next_state == SRV_ST_STARTING) && (px->lbprm.algo & BE_LB_PROP_DYN))
w = 1;
else if ((sv->next_state == SRV_ST_STARTING) && (px->lbprm.algo & BE_LB_PROP_DYN))
- w = (px->lbprm.wdiv * (ns_to_sec(now_ns) - sv->last_change) + sv->slowstart) / sv->slowstart;
+ w = (px->lbprm.wdiv * (ns_to_sec(now_ns) - sv->counters.last_change) + sv->slowstart) / sv->slowstart;
else
w = px->lbprm.wdiv;
srv->rid = 0; /* rid defaults to 0 */
srv->next_state = SRV_ST_RUNNING; /* early server setup */
- srv->last_change = ns_to_sec(now_ns);
+ srv->counters.last_change = ns_to_sec(now_ns);
srv->check.obj_type = OBJ_TYPE_CHECK;
srv->check.status = HCHK_STATUS_INI;
/* updates the server's weight during a warmup stage. Once the final weight is
* reached, the task automatically stops. Note that any server status change
- * must have updated s->last_change accordingly.
+ * must have updated s->counters.last_change accordingly.
*/
static struct task *server_warmup(struct task *t, void *context, unsigned int state)
{
if (srv->next_state == SRV_ST_STARTING) {
task_schedule(srv->warmup,
tick_add(now_ms,
- MS_TO_TICKS(MAX(1000, (ns_to_sec(now_ns) - srv->last_change)) / 20)));
+ MS_TO_TICKS(MAX(1000, (ns_to_sec(now_ns) - srv->counters.last_change)) / 20)));
}
}
if (srv_prev_state != s->cur_state) {
if (srv_prev_state == SRV_ST_STOPPED) {
/* server was down and no longer is */
- if (s->last_change < ns_to_sec(now_ns)) // ignore negative times
- s->down_time += ns_to_sec(now_ns) - s->last_change;
+ if (s->counters.last_change < ns_to_sec(now_ns)) // ignore negative times
+ s->down_time += ns_to_sec(now_ns) - s->counters.last_change;
_srv_event_hdl_publish(EVENT_HDL_SUB_SERVER_UP, cb_data.common, s);
}
else if (s->cur_state == SRV_ST_STOPPED) {
s->counters.down_trans++;
_srv_event_hdl_publish(EVENT_HDL_SUB_SERVER_DOWN, cb_data.common, s);
}
- s->last_change = ns_to_sec(now_ns);
+ s->counters.last_change = ns_to_sec(now_ns);
/* publish the state change */
_srv_event_hdl_prepare_state(&cb_data.state,
/* backend was down and is back up again:
* no helper function, updating last_change and backend downtime stats
*/
- if (s->proxy->last_change < ns_to_sec(now_ns)) // ignore negative times
- s->proxy->down_time += ns_to_sec(now_ns) - s->proxy->last_change;
- s->proxy->last_change = ns_to_sec(now_ns);
+ if (s->proxy->be_counters.last_change < ns_to_sec(now_ns)) // ignore negative times
+ s->proxy->down_time += ns_to_sec(now_ns) - s->proxy->be_counters.last_change;
+ s->proxy->be_counters.last_change = ns_to_sec(now_ns);
}
}
srv_adm_set_drain(srv);
}
- srv->last_change = ns_to_sec(now_ns) - srv_last_time_change;
+ srv->counters.last_change = ns_to_sec(now_ns) - srv_last_time_change;
srv->check.status = srv_check_status;
srv->check.result = srv_check_result;
/* Pre-configures a ring proxy to emit connections */
void sink_setup_proxy(struct proxy *px)
{
- px->last_change = ns_to_sec(now_ns);
+ px->be_counters.last_change = ns_to_sec(now_ns);
px->cap = PR_CAP_BE;
px->maxconn = 0;
px->conn_retries = 1;
field = mkf_str(FO_STATUS, fld_status);
break;
case ST_I_PX_LASTCHG:
- field = mkf_u32(FN_AGE, ns_to_sec(now_ns) - sv->last_change);
+ field = mkf_u32(FN_AGE, ns_to_sec(now_ns) - sv->counters.last_change);
break;
case ST_I_PX_WEIGHT:
field = mkf_u32(FN_AVG, (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv);
field = mkf_u32(0, px->srv_bck);
break;
case ST_I_PX_LASTCHG:
- field = mkf_u32(FN_AGE, ns_to_sec(now_ns) - px->last_change);
+ field = mkf_u32(FN_AGE, ns_to_sec(now_ns) - px->be_counters.last_change);
break;
case ST_I_PX_DOWNTIME:
if (px->srv)