ItayB
ItayB

Reputation: 11367

Get number of connections in Apache C-Module

How can I get the number of open connections (how many different browsers are trying to reach server). I tried to look in the struct request_rec which is available in each function handler..
request_rec->connection->conn_config sounds like the most relevant field (type ap_conf_vector_t but I don't know how to get info from it.

Thanks!

Upvotes: 0

Views: 182

Answers (1)

umka
umka

Reputation: 1655

There is no special counter for it.

You should go through all apache's processes and count them, depending on it's status, like mod_status do:

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++;
        }
    }
}

Upvotes: 1

Related Questions