You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2012/09/24 22:50:59 UTC
svn commit: r1389564 - in /httpd/httpd/trunk: include/httpd.h
modules/generators/mod_status.c server/util.c
Author: jim
Date: Mon Sep 24 20:50:58 2012
New Revision: 1389564
URL: http://svn.apache.org/viewvc?rev=1389564&view=rev
Log:
Break out loadavg from Apache load.... one is quick, the other
isn't so much, and so why load things up when wanting just
the server loadavg?
Modified:
httpd/httpd/trunk/include/httpd.h
httpd/httpd/trunk/modules/generators/mod_status.c
httpd/httpd/trunk/server/util.c
Modified: httpd/httpd/trunk/include/httpd.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/httpd.h?rev=1389564&r1=1389563&r2=1389564&view=diff
==============================================================================
--- httpd/httpd/trunk/include/httpd.h (original)
+++ httpd/httpd/trunk/include/httpd.h Mon Sep 24 20:50:58 2012
@@ -1299,21 +1299,29 @@ struct server_rec {
};
/**
- * @struct server_load_rec
- * @brief A structure to hold various server load params
+ * @struct ap_sload_t
+ * @brief A structure to hold server load params
*/
typedef struct ap_sload_t ap_sload_t;
struct ap_sload_t {
+ /* percentage of process/threads ready/idle (0->100)*/
+ int idle;
+ /* percentage of process/threads busy (0->100) */
+ int busy;
+};
+
+/**
+ * @struct ap_loadavg_t
+ * @brief A structure to hold various server loadavg
+ */
+typedef struct ap_loadavg_t ap_loadavg_t;
+struct ap_loadavg_t {
/* current loadavg, ala getloadavg() */
float loadavg;
/* 5 min loadavg */
float loadavg5;
/* 15 min loadavg */
float loadavg15;
- /* percentage of process/threads ready/idle (0->100)*/
- int idle;
- /* percentage of process/threads busy (0->100) */
- int busy;
};
/**
@@ -2211,6 +2219,13 @@ AP_DECLARE(void *) ap_realloc(void *ptr,
*/
AP_DECLARE(void) ap_get_sload(ap_sload_t *ld);
+/**
+ * Get server load averages (ala getloadavg)
+ * @param ld struct to populate: -1 in fields means error
+ */
+AP_DECLARE(void) ap_get_loadavg(ap_loadavg_t *ld);
+
+
#define AP_NORESTART APR_OS_START_USEERR + 1
#ifdef __cplusplus
Modified: httpd/httpd/trunk/modules/generators/mod_status.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/generators/mod_status.c?rev=1389564&r1=1389563&r2=1389564&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/generators/mod_status.c (original)
+++ httpd/httpd/trunk/modules/generators/mod_status.c Mon Sep 24 20:50:58 2012
@@ -393,7 +393,7 @@ static int status_handler(request_rec *r
ap_scoreboard_image->global->restart_time);
if (!short_report) {
- ap_sload_t t;
+ ap_loadavg_t t;
ap_rputs(DOCTYPE_HTML_3_2
"<html><head>\n"
@@ -421,9 +421,9 @@ static int status_handler(request_rec *r
ap_rputs("<dt>Server uptime: ", r);
show_time(r, up_time);
ap_rputs("</dt>\n", r);
- ap_get_sload(&t);
- ap_rprintf(r, "<dt>Server load: %.2f %.2f %.2f [%d:%d]</dt>\n",
- t.loadavg, t.loadavg5, t.loadavg15, t.idle, t.busy);
+ ap_get_loadavg(&t);
+ ap_rprintf(r, "<dt>Server load: %.2f %.2f %.2f</dt>\n",
+ t.loadavg, t.loadavg5, t.loadavg15);
}
if (ap_extended_status) {
Modified: httpd/httpd/trunk/server/util.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util.c?rev=1389564&r1=1389563&r2=1389564&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util.c (original)
+++ httpd/httpd/trunk/server/util.c Mon Sep 24 20:50:58 2012
@@ -2793,32 +2793,16 @@ AP_DECLARE(void *) ap_realloc(void *ptr,
AP_DECLARE(void) ap_get_sload(ap_sload_t *ld)
{
- double la[3];
- int i, j, num, server_limit, thread_limit;
+ int i, j, server_limit, thread_limit;
int ready = 0;
int busy = 0;
int total;
ap_generation_t mpm_generation;
/* preload errored fields, we overwrite */
- ld->loadavg = -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->loadavg = (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);
@@ -2848,5 +2832,28 @@ AP_DECLARE(void) ap_get_sload(ap_sload_t
ld->idle = ready * 100 / total;
ld->busy = busy * 100 / total;
}
+}
+AP_DECLARE(void) ap_get_loadavg(ap_loadavg_t *ld)
+{
+ double la[3];
+ int num;
+
+ /* preload errored fields, we overwrite */
+ ld->loadavg = -1.0;
+ ld->loadavg5 = -1.0;
+ ld->loadavg15 = -1.0;
+
+#if HAVE_GETLOADAVG
+ num = getloadavg(la, 3);
+ if (num > 0) {
+ ld->loadavg = (float)la[0];
+ }
+ if (num > 1) {
+ ld->loadavg5 = (float)la[1];
+ }
+ if (num > 2) {
+ ld->loadavg15 = (float)la[2];
+ }
+#endif
}