Mon Mar 12 2012 21:40:04

Asterisk developer's documentation


func_sysinfo.c File Reference
#include "asterisk.h"
#include <sys/sysinfo.h>
#include "asterisk/module.h"
#include "asterisk/pbx.h"
Include dependency graph for func_sysinfo.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
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_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "System information related functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static struct ast_module_infoast_module_info = &__mod_info
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

static void __reg_module ( void  ) [static]

Definition at line 155 of file func_sysinfo.c.

static void __unreg_module ( void  ) [static]

Definition at line 155 of file func_sysinfo.c.

static int load_module ( void  ) [static]

Definition at line 150 of file func_sysinfo.c.

References ast_custom_function_register.

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(), getloadavg(), LOG_ERROR, and LOG_WARNING.

{
#if defined(HAVE_SYSINFO)
   struct sysinfo sys_info;
   if (sysinfo(&sys_info)) {
      ast_log(LOG_ERROR, "FAILED to retrieve system information\n");
      return -1;
   }
#endif
   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "Syntax: ${SYSINFO(<parameter>)} - missing argument!)\n");
      return -1;
   } else if (!strcasecmp("loadavg", data)) {
      double curloadavg;
      getloadavg(&curloadavg, 1);
      snprintf(buf, len, "%f", curloadavg);
   } else if (!strcasecmp("numcalls", data)) {
      snprintf(buf, len, "%d", ast_active_calls());
   }
#if defined(HAVE_SYSINFO)
   else if (!strcasecmp("uptime", data)) {             /* in hours */
      snprintf(buf, len, "%ld", sys_info.uptime/3600);
   } else if (!strcasecmp("totalram", data)) {         /* in KiB */
      snprintf(buf, len, "%ld",(sys_info.totalram * sys_info.mem_unit)/1024);
   } else if (!strcasecmp("freeram", data)) {          /* in KiB */
      snprintf(buf, len, "%ld",(sys_info.freeram * sys_info.mem_unit)/1024);
   } else if (!strcasecmp("bufferram", data)) {        /* in KiB */
      snprintf(buf, len, "%ld",(sys_info.bufferram * sys_info.mem_unit)/1024);
   } else if (!strcasecmp("totalswap", data)) {        /* in KiB */
      snprintf(buf, len, "%ld",(sys_info.totalswap * sys_info.mem_unit)/1024);
   } else if (!strcasecmp("freeswap", data)) {         /* in KiB */
      snprintf(buf, len, "%ld",(sys_info.freeswap * sys_info.mem_unit)/1024);
   } else if (!strcasecmp("numprocs", data)) {
      snprintf(buf, len, "%d", sys_info.procs);
   }
#endif
   else {
      ast_log(LOG_ERROR, "Unknown sysinfo parameter type '%s'.\n", data);
      return -1;
   }
      
   return 0;
}
static int unload_module ( void  ) [static]

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "System information related functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 155 of file func_sysinfo.c.

Definition at line 155 of file func_sysinfo.c.

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

Definition at line 139 of file func_sysinfo.c.