[svn-commits] dhubbard: trunk r61539 - in /trunk: include/asterisk/ main/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Apr 11 12:11:33 MST 2007


Author: dhubbard
Date: Wed Apr 11 14:11:32 2007
New Revision: 61539

URL: http://svn.digium.com/view/asterisk?view=rev&rev=61539
Log:
added option_minmemfree for use in asterisk.conf to specify the amount of minimum free memory prior to accepting calls.  added CLI 'core show sysinfo' to display system information

Modified:
    trunk/include/asterisk/options.h
    trunk/main/asterisk.c
    trunk/main/pbx.c

Modified: trunk/include/asterisk/options.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/options.h?view=diff&rev=61539&r1=61538&r2=61539
==============================================================================
--- trunk/include/asterisk/options.h (original)
+++ trunk/include/asterisk/options.h Wed Apr 11 14:11:32 2007
@@ -113,6 +113,7 @@
 extern int option_debug;		/*!< Debugging */
 extern int option_maxcalls;		/*!< Maximum number of simultaneous channels */
 extern double option_maxload;
+extern long option_minmemfree;		/*!< Minimum amount of free system memory - stop accepting calls if free memory falls below this watermark */
 extern char defaultlanguage[];
 
 extern time_t ast_startuptime;

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=61539&r1=61538&r2=61539
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Wed Apr 11 14:11:32 2007
@@ -80,6 +80,7 @@
 #include <grp.h>
 #include <pwd.h>
 #include <sys/stat.h>
+#include <sys/sysinfo.h>
 #ifdef linux
 #include <sys/prctl.h>
 #ifdef HAVE_CAP
@@ -163,6 +164,7 @@
 double option_maxload;				/*!< Max load avg on system */
 int option_maxcalls;				/*!< Max number of active calls */
 int option_maxfiles;				/*!< Max number of open file handles (files, sockets) */
+long option_minmemfree;				/*!< Minimum amount of free system memory - stop accepting calls if free memory falls below this watermark */
 
 /*! @} */
 
@@ -354,6 +356,7 @@
 	ast_cli(fd, "  Verbosity:                   %d\n", option_verbose);
 	ast_cli(fd, "  Debug level:                 %d\n", option_debug);
 	ast_cli(fd, "  Max load avg:                %lf\n", option_maxload);
+	ast_cli(fd, "  Min Free Memory:             %ld MB\n", option_minmemfree);
 	if (localtime_r(&ast_startuptime, &tm)) {
 		strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
 		ast_cli(fd, "  Startup time:                %s\n", buf);
@@ -404,6 +407,31 @@
 	}
         AST_LIST_UNLOCK(&thread_list);
 	ast_cli(fd, "%d threads listed.\n", count);
+	return 0;
+}
+
+static const char show_sysinfo_help[] =
+"Usage: core show sysinfo\n"
+"       List current system information.\n";
+
+/*! \brief Give an overview of system statistics */
+static int handle_show_sysinfo(int fd, int argc, char *argv[])
+{
+	struct sysinfo sys_info;
+
+	if (sysinfo(&sys_info)) {
+		ast_cli(fd, "FAILED to retrieve system information\n\n");
+		return 0;
+	}
+	ast_cli(fd, "\nSystem Statistics\n");
+	ast_cli(fd, "-----------------\n");
+	ast_cli(fd, "  System Uptime:             %ld hours\n", sys_info.uptime/3600);
+	ast_cli(fd, "  Total RAM:                 %ld KiB\n", (sys_info.totalram / sys_info.mem_unit)/1024);
+	ast_cli(fd, "  Free RAM:                  %ld KiB\n", (sys_info.freeram / sys_info.mem_unit)/1024);
+	ast_cli(fd, "  Buffer RAM:                %ld KiB\n", (sys_info.bufferram / sys_info.mem_unit)/1024);
+	ast_cli(fd, "  Total Swap Space:          %ld KiB\n", (sys_info.totalswap / sys_info.mem_unit)/1024);
+	ast_cli(fd, "  Free Swap Space:           %ld KiB\n\n", (sys_info.freeswap / sys_info.mem_unit)/1024);
+	ast_cli(fd, "  Number of Processes:       %d \n\n", sys_info.procs);
 	return 0;
 }
 
@@ -1690,6 +1718,10 @@
 	{ { "core", "show", "threads", NULL },
 	handle_show_threads, "Show running threads",
 	show_threads_help },
+
+	{ { "core", "show", "sysinfo", NULL },
+	handle_show_sysinfo, "Show System Information",
+	show_sysinfo_help },
 
 	{ { "core", "show", "profile", NULL },
 	handle_show_profile, "Display profiling info",
@@ -2483,6 +2515,12 @@
 			ast_copy_string(ast_config_AST_SYSTEM_NAME, v->value, sizeof(ast_config_AST_SYSTEM_NAME));
 		} else if (!strcasecmp(v->name, "languageprefix")) {
 			ast_language_is_prefix = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "minmemfree")) {
+			/* specify the minimum amount of free memory to retain.  Asterisk should stop accepting new calls
+			 * if the amount of free memory falls below this watermark */
+			if ((sscanf(v->value, "%ld", &option_minmemfree) != 1) || (option_minmemfree < 0)) {
+				option_minmemfree = 0;
+			}
 		}
 	}
 	ast_config_destroy(cfg);
@@ -2555,6 +2593,11 @@
 	/* Check for options */
 	while ((c = getopt(argc, argv, "mtThfFdvVqprRgciInx:U:G:C:L:M:")) != -1) {
 		switch (c) {
+		case 'e':
+			if ((sscanf(optarg, "%ld", &option_minmemfree) != 1) || (option_minmemfree < 0)) {
+				option_minmemfree = 0;
+			}
+			break;
 #if HAVE_WORKING_FORK
 		case 'F':
 			ast_set_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK);

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=61539&r1=61538&r2=61539
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Wed Apr 11 14:11:32 2007
@@ -37,6 +37,7 @@
 #include <time.h>
 #include <sys/time.h>
 #include <limits.h>
+#include <sys/sysinfo.h>
 
 #include "asterisk/lock.h"
 #include "asterisk/cli.h"
@@ -2447,11 +2448,14 @@
 	return 0;
 }
 
-/* Returns 0 on success, non-zero if call limit was reached */
+/* Returns 0 on success, non-zero if a configured limit (maxcalls, maxload, minmemfree) was reached */
 static int increase_call_count(const struct ast_channel *c)
 {
 	int failed = 0;
 	double curloadavg;
+	long curfreemem;
+	struct sysinfo sys_info;
+
 	ast_mutex_lock(&maxcalllock);
 	if (option_maxcalls) {
 		if (countcalls >= option_maxcalls) {
@@ -2466,6 +2470,19 @@
 			failed = -1;
 		}
 	}
+	if (option_minmemfree) {
+		if (!sysinfo(&sys_info)) {
+			/* make sure that the free system memory is above the configured low watermark
+			 * convert the amount of freeram from mem_units to MB */
+			curfreemem = sys_info.freeram / sys_info.mem_unit; 
+			curfreemem /= 1024*1024; 
+			if (curfreemem < option_minmemfree) {
+				ast_log(LOG_WARNING, "Available system memory (~%ldMB) is below the configured low watermark (%ldMB)\n", curfreemem, option_minmemfree);
+				failed = -1;
+			}
+		}
+	}
+		
 	if (!failed)
 		countcalls++;
 	ast_mutex_unlock(&maxcalllock);



More information about the svn-commits mailing list