aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xconfigure2
-rw-r--r--configure.ac2
-rw-r--r--include/asterisk/autoconfig.h.in6
-rw-r--r--main/asterisk.c131
4 files changed, 126 insertions, 15 deletions
diff --git a/configure b/configure
index 79e1a9839..47b4cf662 100755
--- a/configure
+++ b/configure
@@ -15675,7 +15675,7 @@ done
-for ac_func in asprintf atexit dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf getpeereid
+for ac_func in asprintf atexit dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq sysctl swapctl unsetenv utime vasprintf getpeereid
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
diff --git a/configure.ac b/configure.ac
index 9432bf864..b63d82fa1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -337,7 +337,7 @@ AC_FUNC_STRNLEN
AC_FUNC_STRTOD
AC_FUNC_UTIME_NULL
AC_FUNC_VPRINTF
-AC_CHECK_FUNCS([asprintf atexit dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf getpeereid])
+AC_CHECK_FUNCS([asprintf atexit dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf getpeereid sysctl swapctl])
AC_CHECK_FUNCS([glob])
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index 8b7be9305..2ab71908a 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -934,6 +934,12 @@
/* Define to indicate the ${SUPPSERV_DESCRIP} library version */
#undef HAVE_SUPPSERV_VERSION
+/* Define to 1 if you have the `swapctl' function. */
+#undef HAVE_SWAPCTL
+
+/* Define to 1 if you have the `sysctl' function. */
+#undef HAVE_SYSCTL
+
/* Define to 1 if your system has sysinfo support */
#undef HAVE_SYSINFO
diff --git a/main/asterisk.c b/main/asterisk.c
index 8fe421dde..1c41b8a4e 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -78,6 +78,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <sys/stat.h>
#if defined(HAVE_SYSINFO)
#include <sys/sysinfo.h>
+#elif defined(HAVE_SYSCTL)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/swap.h>
#endif
#include <regex.h>
@@ -497,11 +501,114 @@ static char *handle_show_threads(struct ast_cli_entry *e, int cmd, struct ast_cl
return CLI_SUCCESS;
}
-#if defined(HAVE_SYSINFO)
+#if defined (HAVE_SYSCTL) && defined(HAVE_SWAPCTL)
+/*
+ * swapmode is rewritten by Tobias Weingartner <weingart@openbsd.org>
+ * to be based on the new swapctl(2) system call.
+ */
+static int swapmode(int *used, int *total)
+{
+ struct swapent *swdev;
+ int nswap, rnswap, i;
+
+ nswap = swapctl(SWAP_NSWAP, 0, 0);
+ if (nswap == 0)
+ return 0;
+
+ swdev = ast_calloc(nswap, sizeof(*swdev));
+ if (swdev == NULL)
+ return 0;
+
+ rnswap = swapctl(SWAP_STATS, swdev, nswap);
+ if (rnswap == -1) {
+ ast_free(swdev);
+ return 0;
+ }
+
+ /* if rnswap != nswap, then what? */
+
+ /* Total things up */
+ *total = *used = 0;
+ for (i = 0; i < nswap; i++) {
+ if (swdev[i].se_flags & SWF_ENABLE) {
+ *used += (swdev[i].se_inuse / (1024 / DEV_BSIZE));
+ *total += (swdev[i].se_nblks / (1024 / DEV_BSIZE));
+ }
+ }
+ ast_free(swdev);
+ return 1;
+}
+#elif defined(HAVE_SYSCTL)
+static int swapmode(int *used, int *total)
+{
+ used = total = 0;
+ return 1;
+}
+#endif
+
/*! \brief Give an overview of system statistics */
static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
+ int64_t physmem, freeram;
+ int totalswap, freeswap, nprocs;
+ long uptime = 0;
+#if defined(HAVE_SYSINFO)
struct sysinfo sys_info;
+ sysinfo(&sys_info)
+ uptime = sys_info.uptime/3600;
+ physmem = sys_info.totalram * sys_info.mem_unit;
+ freeram = (sys_info.freeram * sys_info.mem_unit) / 1024;
+ totalswap = (sys_info.totalswap * sys_info.mem_unit) / 1024;
+ freeswap = (sys_info.freeswap * sys_info.mem_unit) / 1024;
+ nprocs = sys_info.nprocs;
+#elif defined(HAVE_SYSCTL)
+ static int pageshift;
+ struct vmtotal vmtotal;
+ struct timeval boottime;
+ time_t now;
+ int mib[2], pagesize, usedswap;
+ size_t len;
+ /* calculate the uptime by looking at boottime */
+ time(&now);
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_BOOTTIME;
+ len = sizeof(boottime);
+ if (sysctl(mib, 2, &boottime, &len, NULL, 0) != -1) {
+ uptime = now - boottime.tv_sec;
+ }
+ uptime = uptime/3600;
+ /* grab total physical memory */
+ mib[0] = CTL_HW;
+ mib[1] = HW_PHYSMEM64;
+ len = sizeof(physmem);
+ sysctl(mib, 2, &physmem, &len, NULL, 0);
+
+ pagesize = getpagesize();
+ pageshift = 0;
+ while (pagesize > 1) {
+ pageshift++;
+ pagesize >>= 1;
+ }
+
+ /* we only need the amount of log(2)1024 for our conversion */
+ pageshift -= 10;
+
+ /* grab vm totals */
+ mib[0] = CTL_VM;
+ mib[1] = VM_METER;
+ len = sizeof(vmtotal);
+ sysctl(mib, 2, &vmtotal, &len, NULL, 0);
+ freeram = (vmtotal.t_free << pageshift);
+ /* generate swap usage and totals */
+ swapmode(&usedswap, &totalswap);
+ freeswap = (totalswap - usedswap);
+ /* grab number of processes */
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_NPROCS;
+ len = sizeof(nprocs);
+ sysctl(mib, 2, &nprocs, &len, NULL, 0);
+#endif
+
switch (cmd) {
case CLI_INIT:
e->command = "core show sysinfo";
@@ -512,22 +619,20 @@ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cl
case CLI_GENERATE:
return NULL;
}
- if (sysinfo(&sys_info)) {
- ast_cli(a->fd, "FAILED to retrieve system information\n\n");
- return CLI_FAILURE;
- }
+
ast_cli(a->fd, "\nSystem Statistics\n");
ast_cli(a->fd, "-----------------\n");
- ast_cli(a->fd, " System Uptime: %ld hours\n", sys_info.uptime/3600);
- ast_cli(a->fd, " Total RAM: %ld KiB\n", (sys_info.totalram * sys_info.mem_unit)/1024);
- ast_cli(a->fd, " Free RAM: %ld KiB\n", (sys_info.freeram * sys_info.mem_unit)/1024);
+ ast_cli(a->fd, " System Uptime: %ld hours\n", uptime);
+ ast_cli(a->fd, " Total RAM: %ld KiB\n", (long)physmem/1024);
+ ast_cli(a->fd, " Free RAM: %ld KiB\n", (long)freeram);
+#if defined(HAVE_SYSINFO)
ast_cli(a->fd, " Buffer RAM: %ld KiB\n", (sys_info.bufferram * sys_info.mem_unit)/1024);
- ast_cli(a->fd, " Total Swap Space: %ld KiB\n", (sys_info.totalswap * sys_info.mem_unit)/1024);
- ast_cli(a->fd, " Free Swap Space: %ld KiB\n\n", (sys_info.freeswap * sys_info.mem_unit)/1024);
- ast_cli(a->fd, " Number of Processes: %d \n\n", sys_info.procs);
+#endif
+ ast_cli(a->fd, " Total Swap Space: %ld KiB\n", (long)totalswap);
+ ast_cli(a->fd, " Free Swap Space: %ld KiB\n\n", (long)freeswap);
+ ast_cli(a->fd, " Number of Processes: %d \n\n", nprocs);
return CLI_SUCCESS;
}
-#endif
struct profile_entry {
const char *name;
@@ -1913,7 +2018,7 @@ static struct ast_cli_entry cli_asterisk[] = {
#if !defined(LOW_MEMORY)
AST_CLI_DEFINE(handle_show_version_files, "List versions of files used to build Asterisk"),
AST_CLI_DEFINE(handle_show_threads, "Show running threads"),
-#if defined(HAVE_SYSINFO)
+#if defined(HAVE_SYSINFO) || defined(HAVE_SYSCTL)
AST_CLI_DEFINE(handle_show_sysinfo, "Show System Information"),
#endif
AST_CLI_DEFINE(handle_show_profile, "Display profiling info"),