Wed Jan 27 20:02:40 2016

Asterisk developer's documentation


func_sysinfo.c File Reference

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"System information related functions")
static int load_module (void)
static int sysinfo_helper (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int unload_module (void)

Variables

static struct ast_custom_function sysinfo_function

Detailed Description

SYSINFO function to return various system data.

Note:
Inspiration and Guidance from Russell
Author:
Jeff Peeler

Definition in file func_sysinfo.c.


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"System information related functions"   
)
static int load_module ( void   )  [static]

Definition at line 150 of file func_sysinfo.c.

References ast_custom_function_register.

00151 {
00152    return ast_custom_function_register(&sysinfo_function);
00153 }

static int sysinfo_helper ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 94 of file func_sysinfo.c.

References ast_active_calls(), ast_log(), ast_strlen_zero(), LOG_ERROR, and LOG_WARNING.

00096 {
00097 #if defined(HAVE_SYSINFO)
00098    struct sysinfo sys_info;
00099    if (sysinfo(&sys_info)) {
00100       ast_log(LOG_ERROR, "FAILED to retrieve system information\n");
00101       return -1;
00102    }
00103 #endif
00104    if (ast_strlen_zero(data)) {
00105       ast_log(LOG_WARNING, "Syntax: ${SYSINFO(<parameter>)} - missing argument!)\n");
00106       return -1;
00107    } else if (!strcasecmp("loadavg", data)) {
00108       double curloadavg;
00109       getloadavg(&curloadavg, 1);
00110       snprintf(buf, len, "%f", curloadavg);
00111    } else if (!strcasecmp("numcalls", data)) {
00112       snprintf(buf, len, "%d", ast_active_calls());
00113    }
00114 #if defined(HAVE_SYSINFO)
00115    else if (!strcasecmp("uptime", data)) {             /* in hours */
00116       snprintf(buf, len, "%ld", sys_info.uptime/3600);
00117    } else if (!strcasecmp("totalram", data)) {         /* in KiB */
00118       snprintf(buf, len, "%lu",(sys_info.totalram * sys_info.mem_unit)/1024);
00119    } else if (!strcasecmp("freeram", data)) {          /* in KiB */
00120       snprintf(buf, len, "%lu",(sys_info.freeram * sys_info.mem_unit)/1024);
00121    } else if (!strcasecmp("bufferram", data)) {        /* in KiB */
00122       snprintf(buf, len, "%lu",(sys_info.bufferram * sys_info.mem_unit)/1024);
00123    } else if (!strcasecmp("totalswap", data)) {        /* in KiB */
00124       snprintf(buf, len, "%lu",(sys_info.totalswap * sys_info.mem_unit)/1024);
00125    } else if (!strcasecmp("freeswap", data)) {         /* in KiB */
00126       snprintf(buf, len, "%lu",(sys_info.freeswap * sys_info.mem_unit)/1024);
00127    } else if (!strcasecmp("numprocs", data)) {
00128       snprintf(buf, len, "%d", sys_info.procs);
00129    }
00130 #endif
00131    else {
00132       ast_log(LOG_ERROR, "Unknown sysinfo parameter type '%s'.\n", data);
00133       return -1;
00134    }
00135       
00136    return 0;
00137 }

static int unload_module ( void   )  [static]

Definition at line 145 of file func_sysinfo.c.

References ast_custom_function_unregister().

00146 {
00147    return ast_custom_function_unregister(&sysinfo_function);
00148 }


Variable Documentation

Initial value:
 {
   .name = "SYSINFO",
   .read = sysinfo_helper,
   .read_max = 22,
}

Definition at line 139 of file func_sysinfo.c.


Generated on 27 Jan 2016 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1