0

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!

ItayB
  • 10,377
  • 9
  • 50
  • 77

1 Answers1

1

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++;
        }
    }
}
umka
  • 1,655
  • 1
  • 12
  • 18
  • Thanks for your answer, but I see that the solution only increase counters so it won't reflect real state.. – ItayB May 07 '15 at 07:35
  • 1
    Yes, this code counts processes only when it's called. If you need to maintain a dynamically updated table with counters, there should be more complex code. – umka May 07 '15 at 11:32