Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 156 of file func_sysinfo.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 156 of file func_sysinfo.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 156 of file func_sysinfo.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 151 of file func_sysinfo.c.

152{
154}
static struct ast_custom_function sysinfo_function
Definition: func_sysinfo.c:140
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1559

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 95 of file func_sysinfo.c.

97{
98#if defined(HAVE_SYSINFO)
99 struct sysinfo sys_info;
100 if (sysinfo(&sys_info)) {
101 ast_log(LOG_ERROR, "FAILED to retrieve system information\n");
102 return -1;
103 }
104#endif
105 if (ast_strlen_zero(data)) {
106 ast_log(LOG_WARNING, "Syntax: ${SYSINFO(<parameter>)} - missing argument!)\n");
107 return -1;
108 } else if (!strcasecmp("loadavg", data)) {
109 double curloadavg;
110 getloadavg(&curloadavg, 1);
111 snprintf(buf, len, "%f", curloadavg);
112 } else if (!strcasecmp("numcalls", data)) {
113 snprintf(buf, len, "%d", ast_active_calls());
114 }
115#if defined(HAVE_SYSINFO)
116 else if (!strcasecmp("uptime", data)) { /* in hours */
117 snprintf(buf, len, "%ld", sys_info.uptime/3600);
118 } else if (!strcasecmp("totalram", data)) { /* in KiB */
119 snprintf(buf, len, "%lu",(sys_info.totalram * sys_info.mem_unit)/1024);
120 } else if (!strcasecmp("freeram", data)) { /* in KiB */
121 snprintf(buf, len, "%lu",(sys_info.freeram * sys_info.mem_unit)/1024);
122 } else if (!strcasecmp("bufferram", data)) { /* in KiB */
123 snprintf(buf, len, "%lu",(sys_info.bufferram * sys_info.mem_unit)/1024);
124 } else if (!strcasecmp("totalswap", data)) { /* in KiB */
125 snprintf(buf, len, "%lu",(sys_info.totalswap * sys_info.mem_unit)/1024);
126 } else if (!strcasecmp("freeswap", data)) { /* in KiB */
127 snprintf(buf, len, "%lu",(sys_info.freeswap * sys_info.mem_unit)/1024);
128 } else if (!strcasecmp("numprocs", data)) {
129 snprintf(buf, len, "%d", sys_info.procs);
130 }
131#endif
132 else {
133 ast_log(LOG_ERROR, "Unknown sysinfo parameter type '%s'.\n", data);
134 return -1;
135 }
136
137 return 0;
138}
int getloadavg(double *list, int nelem)
#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)
#define LOG_ERROR
#define LOG_WARNING
int ast_active_calls(void)
Retrieve the number of active calls.
Definition: pbx.c:4775
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 146 of file func_sysinfo.c.

147{
149}
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 156 of file func_sysinfo.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 156 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:95

Definition at line 140 of file func_sysinfo.c.

Referenced by load_module(), and unload_module().