获取 Apache C 模块中的连接数
Get number of connections in Apache C-Module
如何获取打开的连接数(有多少不同的浏览器试图访问服务器)。
我试图查看每个函数处理程序中可用的结构 request_rec
..
request_rec->connection->conn_config
听起来像是最相关的字段(输入 ap_conf_vector_t
但我不知道如何从中获取信息。
谢谢!
没有专门的计数器。
您应该检查所有 apache 的进程并对它们进行计数,具体取决于它的状态,例如 mod_status 做:
int server_limit, thread_limit;
int j, i, res;
int ready;
int busy;
worker_score *ws_record = apr_palloc(r->pool, sizeof *ws_record);
process_score *ps_record;
ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
ready = 0;
busy = 0;
for (i = 0; i < server_limit; ++i) {
ps_record = ap_get_scoreboard_process(i);
for (j = 0; j < thread_limit; ++j) {
ap_copy_scoreboard_worker(ws_record, i, j);
res = ws_record->status;
if (!ps_record->quiescing
&& ps_record->pid) {
if (res == SERVER_READY &&
ps_record->generation == ap_my_generation)
ready++;
else if (res != SERVER_DEAD &&
res != SERVER_STARTING &&
res != SERVER_IDLE_KILL)
busy++;
}
}
}
如何获取打开的连接数(有多少不同的浏览器试图访问服务器)。
我试图查看每个函数处理程序中可用的结构 request_rec
..
request_rec->connection->conn_config
听起来像是最相关的字段(输入 ap_conf_vector_t
但我不知道如何从中获取信息。
谢谢!
没有专门的计数器。
您应该检查所有 apache 的进程并对它们进行计数,具体取决于它的状态,例如 mod_status 做:
int server_limit, thread_limit;
int j, i, res;
int ready;
int busy;
worker_score *ws_record = apr_palloc(r->pool, sizeof *ws_record);
process_score *ps_record;
ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
ready = 0;
busy = 0;
for (i = 0; i < server_limit; ++i) {
ps_record = ap_get_scoreboard_process(i);
for (j = 0; j < thread_limit; ++j) {
ap_copy_scoreboard_worker(ws_record, i, j);
res = ws_record->status;
if (!ps_record->quiescing
&& ps_record->pid) {
if (res == SERVER_READY &&
ps_record->generation == ap_my_generation)
ready++;
else if (res != SERVER_DEAD &&
res != SERVER_STARTING &&
res != SERVER_IDLE_KILL)
busy++;
}
}
}