diff options
author | Jim Jagielski <jim@apache.org> | 2012-09-24 18:56:58 +0200 |
---|---|---|
committer | Jim Jagielski <jim@apache.org> | 2012-09-24 18:56:58 +0200 |
commit | 1134cfb81d14d5c8d7b486a9f0b3400f35f8444d (patch) | |
tree | b6d42392101918794b0084e3d1142c93f12ab9ac /server/util.c | |
parent | add pre_htaccess hook; in conjunction with earlier dirwalk_stat (diff) | |
download | apache2-1134cfb81d14d5c8d7b486a9f0b3400f35f8444d.tar.xz apache2-1134cfb81d14d5c8d7b486a9f0b3400f35f8444d.zip |
Would be nice to have some sort of canonical definition
of server loading for Apache. So create a struct that
holds some useful data. The hope is that for those
platforms that lack getloadavg(), people will write
replacements.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1389481 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server/util.c')
-rw-r--r-- | server/util.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/server/util.c b/server/util.c index 24d3a22ed3..d518eadef1 100644 --- a/server/util.c +++ b/server/util.c @@ -63,6 +63,8 @@ #include <grp.h> #endif +#include "ap_mpm.h" + /* A bunch of functions in util.c scan strings looking for certain characters. * To make that more efficient we encode a lookup table. The test_char_table * is generated automatically by gen_test_char.c. @@ -2788,3 +2790,63 @@ AP_DECLARE(void *) ap_realloc(void *ptr, size_t size) ap_abort_on_oom(); return p; } + +AP_DECLARE(void) ap_get_sload(ap_sload_t *ld) +{ + double la[3]; + int i, j, num, server_limit, thread_limit; + int ready = 0; + int busy = 0; + int total; + ap_generation_t mpm_generation; + + /* preload errored fields, we overwrite */ + ld->loadavg1 = -1.0; + ld->loadavg5 = -1.0; + ld->loadavg15 = -1.0; + ld->idle = -1; + ld->busy = -1; + +#if HAVE_GETLOADAVG + num = getloadavg(la, 3); + if (num > 0) { + ld->loadavg1 = (float)la[0]; + } + if (num > 1) { + ld->loadavg5 = (float)la[1]; + } + if (num > 2) { + ld->loadavg15 = (float)la[2]; + } +#endif + ap_mpm_query(AP_MPMQ_GENERATION, &mpm_generation); + ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit); + ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit); + + for (i = 0; i < server_limit; i++) { + process_score *ps; + ps = ap_get_scoreboard_process(i); + + for (j = 0; j < thread_limit; j++) { + int res; + worker_score *ws = NULL; + ws = &ap_scoreboard_image->servers[i][j]; + res = ws->status; + + if (res == SERVER_READY && ps->generation == mpm_generation) { + ready++; + } + else if (res != SERVER_DEAD && + res != SERVER_STARTING && res != SERVER_IDLE_KILL && + ps->generation == mpm_generation) { + busy++; + } + } + } + total = busy + ready; + if (total) { + ld->idle = ready * 100 / total; + ld->busy = busy * 100 / total; + } + +} |