Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions | Variables
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)
 
struct ast_moduleAST_MODULE_SELF_SYM (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, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const 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

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 153 of file func_sysinfo.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 153 of file func_sysinfo.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 153 of file func_sysinfo.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 148 of file func_sysinfo.c.

149{
151}
static struct ast_custom_function sysinfo_function
Definition: func_sysinfo.c:137
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

References ast_custom_function_register, and sysinfo_function.

◆ sysinfo_helper()

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

Definition at line 92 of file func_sysinfo.c.

94{
95#if defined(HAVE_SYSINFO)
96 struct sysinfo sys_info;
97 if (sysinfo(&sys_info)) {
98 ast_log(LOG_ERROR, "FAILED to retrieve system information\n");
99 return -1;
100 }
101#endif
102 if (ast_strlen_zero(data)) {
103 ast_log(LOG_WARNING, "Syntax: ${SYSINFO(<parameter>)} - missing argument!)\n");
104 return -1;
105 } else if (!strcasecmp("loadavg", data)) {
106 double curloadavg;
107 getloadavg(&curloadavg, 1);
108 snprintf(buf, len, "%f", curloadavg);
109 } else if (!strcasecmp("numcalls", data)) {
110 snprintf(buf, len, "%d", ast_active_calls());
111 }
112#if defined(HAVE_SYSINFO)
113 else if (!strcasecmp("uptime", data)) { /* in hours */
114 snprintf(buf, len, "%ld", sys_info.uptime/3600);
115 } else if (!strcasecmp("totalram", data)) { /* in KiB */
116 snprintf(buf, len, "%lu",(sys_info.totalram * sys_info.mem_unit)/1024);
117 } else if (!strcasecmp("freeram", data)) { /* in KiB */
118 snprintf(buf, len, "%lu",(sys_info.freeram * sys_info.mem_unit)/1024);
119 } else if (!strcasecmp("bufferram", data)) { /* in KiB */
120 snprintf(buf, len, "%lu",(sys_info.bufferram * sys_info.mem_unit)/1024);
121 } else if (!strcasecmp("totalswap", data)) { /* in KiB */
122 snprintf(buf, len, "%lu",(sys_info.totalswap * sys_info.mem_unit)/1024);
123 } else if (!strcasecmp("freeswap", data)) { /* in KiB */
124 snprintf(buf, len, "%lu",(sys_info.freeswap * sys_info.mem_unit)/1024);
125 } else if (!strcasecmp("numprocs", data)) {
126 snprintf(buf, len, "%d", sys_info.procs);
127 }
128#endif
129 else {
130 ast_log(LOG_ERROR, "Unknown sysinfo parameter type '%s'.\n", data);
131 return -1;
132 }
133
134 return 0;
135}
#define ast_log
Definition: astobj2.c:42
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int getloadavg(double *list, int nelem)
#define LOG_ERROR
#define LOG_WARNING
int ast_active_calls(void)
Retrieve the number of active calls.
Definition: pbx.c:4760
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65

References ast_active_calls(), ast_log, ast_strlen_zero(), buf, getloadavg(), len(), LOG_ERROR, and LOG_WARNING.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 143 of file func_sysinfo.c.

144{
146}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), and sysinfo_function.

Variable Documentation

◆ __mod_info

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, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 153 of file func_sysinfo.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 153 of file func_sysinfo.c.

◆ sysinfo_function

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:92

Definition at line 137 of file func_sysinfo.c.

Referenced by load_module(), and unload_module().