Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


func_sysinfo.c File Reference
#include "asterisk.h"
#include <sys/sysinfo.h>
#include "asterisk/module.h"
#include "asterisk/pbx.h"

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 = "ac1f6a56484a8820659555499174e588" , .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.

151 {
153 }
static struct ast_custom_function sysinfo_function
Definition: func_sysinfo.c:139
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
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.

96 {
97 #if defined(HAVE_SYSINFO)
98  struct sysinfo sys_info;
99  if (sysinfo(&sys_info)) {
100  ast_log(LOG_ERROR, "FAILED to retrieve system information\n");
101  return -1;
102  }
103 #endif
104  if (ast_strlen_zero(data)) {
105  ast_log(LOG_WARNING, "Syntax: ${SYSINFO(<parameter>)} - missing argument!)\n");
106  return -1;
107  } else if (!strcasecmp("loadavg", data)) {
108  double curloadavg;
109  getloadavg(&curloadavg, 1);
110  snprintf(buf, len, "%f", curloadavg);
111  } else if (!strcasecmp("numcalls", data)) {
112  snprintf(buf, len, "%d", ast_active_calls());
113  }
114 #if defined(HAVE_SYSINFO)
115  else if (!strcasecmp("uptime", data)) { /* in hours */
116  snprintf(buf, len, "%ld", sys_info.uptime/3600);
117  } else if (!strcasecmp("totalram", data)) { /* in KiB */
118  snprintf(buf, len, "%lu",(sys_info.totalram * sys_info.mem_unit)/1024);
119  } else if (!strcasecmp("freeram", data)) { /* in KiB */
120  snprintf(buf, len, "%lu",(sys_info.freeram * sys_info.mem_unit)/1024);
121  } else if (!strcasecmp("bufferram", data)) { /* in KiB */
122  snprintf(buf, len, "%lu",(sys_info.bufferram * sys_info.mem_unit)/1024);
123  } else if (!strcasecmp("totalswap", data)) { /* in KiB */
124  snprintf(buf, len, "%lu",(sys_info.totalswap * sys_info.mem_unit)/1024);
125  } else if (!strcasecmp("freeswap", data)) { /* in KiB */
126  snprintf(buf, len, "%lu",(sys_info.freeswap * sys_info.mem_unit)/1024);
127  } else if (!strcasecmp("numprocs", data)) {
128  snprintf(buf, len, "%d", sys_info.procs);
129  }
130 #endif
131  else {
132  ast_log(LOG_ERROR, "Unknown sysinfo parameter type '%s'.\n", data);
133  return -1;
134  }
135 
136  return 0;
137 }
int ast_active_calls(void)
Retrieve the number of active calls.
Definition: pbx.c:5931
#define LOG_WARNING
Definition: logger.h:144
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define LOG_ERROR
Definition: logger.h:155
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int getloadavg(double *list, int nelem)
static int unload_module ( void  )
static

Definition at line 145 of file func_sysinfo.c.

References ast_custom_function_unregister().

146 {
148 }
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
static struct ast_custom_function sysinfo_function
Definition: func_sysinfo.c:139

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 = "ac1f6a56484a8820659555499174e588" , .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.

struct ast_custom_function sysinfo_function
static
Initial value:
= {
.name = "SYSINFO",
.read = sysinfo_helper,
.read_max = 22,
}
static int sysinfo_helper(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_sysinfo.c:94

Definition at line 139 of file func_sysinfo.c.