00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 87233 $")
00031
00032 #if defined(HAVE_SYSINFO)
00033 #include <sys/sysinfo.h>
00034 #endif
00035
00036 #include "asterisk/module.h"
00037 #include "asterisk/pbx.h"
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 static int sysinfo_helper(struct ast_channel *chan, const char *cmd, char *data,
00091 char *buf, size_t len)
00092 {
00093 #if defined(HAVE_SYSINFO)
00094 struct sysinfo sys_info;
00095 if (sysinfo(&sys_info)) {
00096 ast_log(LOG_ERROR, "FAILED to retrieve system information\n");
00097 return -1;
00098 }
00099 #endif
00100 if (ast_strlen_zero(data)) {
00101 ast_log(LOG_WARNING, "Syntax: ${SYSINFO(<parameter>)} - missing argument!)\n");
00102 return -1;
00103 } else if (!strcasecmp("loadavg", data)) {
00104 double curloadavg;
00105 getloadavg(&curloadavg, 1);
00106 snprintf(buf, len, "%f", curloadavg);
00107 } else if (!strcasecmp("numcalls", data)) {
00108 snprintf(buf, len, "%d", ast_active_calls());
00109 }
00110 #if defined(HAVE_SYSINFO)
00111 else if (!strcasecmp("uptime", data)) {
00112 snprintf(buf, len, "%ld", sys_info.uptime/3600);
00113 } else if (!strcasecmp("totalram", data)) {
00114 snprintf(buf, len, "%ld",(sys_info.totalram * sys_info.mem_unit)/1024);
00115 } else if (!strcasecmp("freeram", data)) {
00116 snprintf(buf, len, "%ld",(sys_info.freeram * sys_info.mem_unit)/1024);
00117 } else if (!strcasecmp("bufferram", data)) {
00118 snprintf(buf, len, "%ld",(sys_info.bufferram * sys_info.mem_unit)/1024);
00119 } else if (!strcasecmp("totalswap", data)) {
00120 snprintf(buf, len, "%ld",(sys_info.totalswap * sys_info.mem_unit)/1024);
00121 } else if (!strcasecmp("freeswap", data)) {
00122 snprintf(buf, len, "%ld",(sys_info.freeswap * sys_info.mem_unit)/1024);
00123 } else if (!strcasecmp("numprocs", data)) {
00124 snprintf(buf, len, "%d", sys_info.procs);
00125 }
00126 #endif
00127 else {
00128 ast_log(LOG_ERROR, "Unknown sysinfo parameter type '%s'.\n", data);
00129 return -1;
00130 }
00131
00132 return 0;
00133 }
00134
00135 static struct ast_custom_function sysinfo_function = {
00136 .name = "SYSINFO",
00137 .read = sysinfo_helper,
00138 .read_max = 22,
00139 };
00140
00141 static int unload_module(void)
00142 {
00143 return ast_custom_function_unregister(&sysinfo_function);
00144 }
00145
00146 static int load_module(void)
00147 {
00148 return ast_custom_function_register(&sysinfo_function);
00149 }
00150
00151 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "System information related functions");
00152