mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-12-09 19:51:36 +01:00
[MEDIUM] session: add a counter on the cumulated number of sessions
Sessions are like connections but they have been accepted by L4 rules and really became sessions.
This commit is contained in:
parent
1aa006fe7a
commit
f4d17d9071
@ -44,6 +44,7 @@ enum {
|
|||||||
STKTABLE_DT_SERVER_ID, /* the server ID to use with this session if > 0 */
|
STKTABLE_DT_SERVER_ID, /* the server ID to use with this session if > 0 */
|
||||||
STKTABLE_DT_CONN_CNT, /* cumulated number of connections */
|
STKTABLE_DT_CONN_CNT, /* cumulated number of connections */
|
||||||
STKTABLE_DT_CONN_CUR, /* concurrent number of connections */
|
STKTABLE_DT_CONN_CUR, /* concurrent number of connections */
|
||||||
|
STKTABLE_DT_SESS_CNT, /* cumulated number of sessions (accepted connections) */
|
||||||
STKTABLE_DT_BYTES_IN_CNT, /* cumulated bytes count from client to servers */
|
STKTABLE_DT_BYTES_IN_CNT, /* cumulated bytes count from client to servers */
|
||||||
STKTABLE_DT_BYTES_OUT_CNT,/* cumulated bytes count from servers to client */
|
STKTABLE_DT_BYTES_OUT_CNT,/* cumulated bytes count from servers to client */
|
||||||
STKTABLE_DATA_TYPES /* Number of data types, must always be last */
|
STKTABLE_DATA_TYPES /* Number of data types, must always be last */
|
||||||
@ -54,6 +55,7 @@ union stktable_data {
|
|||||||
int server_id;
|
int server_id;
|
||||||
unsigned int conn_cnt;
|
unsigned int conn_cnt;
|
||||||
unsigned int conn_cur;
|
unsigned int conn_cur;
|
||||||
|
unsigned int sess_cnt;
|
||||||
unsigned long long bytes_in_cnt;
|
unsigned long long bytes_in_cnt;
|
||||||
unsigned long long bytes_out_cnt;
|
unsigned long long bytes_out_cnt;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -134,6 +134,11 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
|
|||||||
if (p->feconn > p->counters.feconn_max)
|
if (p->feconn > p->counters.feconn_max)
|
||||||
p->counters.feconn_max = p->feconn;
|
p->counters.feconn_max = p->feconn;
|
||||||
proxy_inc_fe_sess_ctr(l, p);
|
proxy_inc_fe_sess_ctr(l, p);
|
||||||
|
if (s->tracked_counters) {
|
||||||
|
void *ptr = stktable_data_ptr(s->tracked_table, s->tracked_counters, STKTABLE_DT_SESS_CNT);
|
||||||
|
if (ptr)
|
||||||
|
stktable_data_cast(ptr, sess_cnt)++;
|
||||||
|
}
|
||||||
|
|
||||||
/* this part should be common with other protocols */
|
/* this part should be common with other protocols */
|
||||||
s->si[0].fd = cfd;
|
s->si[0].fd = cfd;
|
||||||
@ -2208,6 +2213,54 @@ acl_fetch_src_conn_cur(struct proxy *px, struct session *l4, void *l7, int dir,
|
|||||||
return acl_fetch_conn_cnt(&px->table, test, stktable_lookup_key(&px->table, key));
|
return acl_fetch_conn_cnt(&px->table, test, stktable_lookup_key(&px->table, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set test->i to the cumulated number of sessions in the stksess entry <ts> */
|
||||||
|
static int
|
||||||
|
acl_fetch_sess_cnt(struct stktable *table, struct acl_test *test, struct stksess *ts)
|
||||||
|
{
|
||||||
|
test->flags = ACL_TEST_F_VOL_TEST;
|
||||||
|
test->i = 0;
|
||||||
|
if (ts != NULL) {
|
||||||
|
void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_SESS_CNT);
|
||||||
|
if (!ptr)
|
||||||
|
return 0; /* parameter not stored */
|
||||||
|
test->i = stktable_data_cast(ptr, sess_cnt);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set test->i to the cumulated number of sessions from the session's tracked counters */
|
||||||
|
static int
|
||||||
|
acl_fetch_trk_sess_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||||
|
struct acl_expr *expr, struct acl_test *test)
|
||||||
|
{
|
||||||
|
if (!l4->tracked_counters)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return acl_fetch_sess_cnt(l4->tracked_table, test, l4->tracked_counters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set test->i to the cumulated number of session from the session's source
|
||||||
|
* address in the table pointed to by expr.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
acl_fetch_src_sess_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||||
|
struct acl_expr *expr, struct acl_test *test)
|
||||||
|
{
|
||||||
|
struct stktable_key *key;
|
||||||
|
|
||||||
|
key = tcpv4_src_to_stktable_key(l4);
|
||||||
|
if (!key)
|
||||||
|
return 0; /* only TCPv4 is supported right now */
|
||||||
|
|
||||||
|
if (expr->arg_len)
|
||||||
|
px = find_stktable(expr->arg.str);
|
||||||
|
|
||||||
|
if (!px)
|
||||||
|
return 0; /* table not found */
|
||||||
|
|
||||||
|
return acl_fetch_sess_cnt(&px->table, test, stktable_lookup_key(&px->table, key));
|
||||||
|
}
|
||||||
|
|
||||||
/* set test->i to the number of kbytes received from clients matching the stksess entry <ts> */
|
/* set test->i to the number of kbytes received from clients matching the stksess entry <ts> */
|
||||||
static int
|
static int
|
||||||
acl_fetch_kbytes_in(struct stktable *table, struct acl_test *test, struct stksess *ts)
|
acl_fetch_kbytes_in(struct stktable *table, struct acl_test *test, struct stksess *ts)
|
||||||
@ -2318,6 +2371,8 @@ static struct acl_kw_list acl_kws = {{ },{
|
|||||||
{ "src_updt_conn_cnt", acl_parse_int, acl_fetch_src_updt_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
{ "src_updt_conn_cnt", acl_parse_int, acl_fetch_src_updt_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
||||||
{ "trk_conn_cur", acl_parse_int, acl_fetch_trk_conn_cur, acl_match_int, ACL_USE_NOTHING },
|
{ "trk_conn_cur", acl_parse_int, acl_fetch_trk_conn_cur, acl_match_int, ACL_USE_NOTHING },
|
||||||
{ "src_conn_cur", acl_parse_int, acl_fetch_src_conn_cur, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
{ "src_conn_cur", acl_parse_int, acl_fetch_src_conn_cur, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
||||||
|
{ "trk_sess_cnt", acl_parse_int, acl_fetch_trk_sess_cnt, acl_match_int, ACL_USE_NOTHING },
|
||||||
|
{ "src_sess_cnt", acl_parse_int, acl_fetch_src_sess_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
||||||
{ "trk_kbytes_in", acl_parse_int, acl_fetch_trk_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
{ "trk_kbytes_in", acl_parse_int, acl_fetch_trk_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
||||||
{ "src_kbytes_in", acl_parse_int, acl_fetch_src_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
{ "src_kbytes_in", acl_parse_int, acl_fetch_src_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
||||||
{ "trk_kbytes_out", acl_parse_int, acl_fetch_trk_kbytes_out, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
{ "trk_kbytes_out", acl_parse_int, acl_fetch_trk_kbytes_out, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
||||||
|
|||||||
@ -528,6 +528,7 @@ struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES] = {
|
|||||||
[STKTABLE_DT_SERVER_ID] = { .name = "server_id", .data_length = stktable_data_size(server_id) },
|
[STKTABLE_DT_SERVER_ID] = { .name = "server_id", .data_length = stktable_data_size(server_id) },
|
||||||
[STKTABLE_DT_CONN_CNT] = { .name = "conn_cnt", .data_length = stktable_data_size(conn_cnt) },
|
[STKTABLE_DT_CONN_CNT] = { .name = "conn_cnt", .data_length = stktable_data_size(conn_cnt) },
|
||||||
[STKTABLE_DT_CONN_CUR] = { .name = "conn_cur", .data_length = stktable_data_size(conn_cur) },
|
[STKTABLE_DT_CONN_CUR] = { .name = "conn_cur", .data_length = stktable_data_size(conn_cur) },
|
||||||
|
[STKTABLE_DT_SESS_CNT] = { .name = "sess_cnt", .data_length = stktable_data_size(sess_cnt) },
|
||||||
[STKTABLE_DT_BYTES_IN_CNT] = { .name = "bytes_in_cnt", .data_length = stktable_data_size(bytes_in_cnt) },
|
[STKTABLE_DT_BYTES_IN_CNT] = { .name = "bytes_in_cnt", .data_length = stktable_data_size(bytes_in_cnt) },
|
||||||
[STKTABLE_DT_BYTES_OUT_CNT] = { .name = "bytes_out_cnt", .data_length = stktable_data_size(bytes_out_cnt) },
|
[STKTABLE_DT_BYTES_OUT_CNT] = { .name = "bytes_out_cnt", .data_length = stktable_data_size(bytes_out_cnt) },
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user