Modify the main page of the doxygen documentation to link to a new page dedicated
[asterisk-bristuff.git] / funcs / func_sysinfo.c
blob16e9632d5b00f4011d13b71a91ded490af35e6da
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2007, Digium, Inc.
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
17 /*! \file
19 * SYSINFO function to return various system data.
21 * \note Inspiration and Guidance from Russell
23 * \author Jeff Peeler
25 * \ingroup functions
28 #include "asterisk.h"
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 87233 $")
32 #if defined(HAVE_SYSINFO)
33 #include <sys/sysinfo.h>
34 #endif
36 #include "asterisk/module.h"
37 #include "asterisk/pbx.h"
39 static int sysinfo_helper(struct ast_channel *chan, const char *cmd, char *data,
40 char *buf, size_t len)
42 #if defined(HAVE_SYSINFO)
43 struct sysinfo sys_info;
44 if (sysinfo(&sys_info)) {
45 ast_log(LOG_ERROR, "FAILED to retrieve system information\n");
46 return -1;
48 #endif
49 if (ast_strlen_zero(data)) {
50 ast_log(LOG_WARNING, "Syntax: ${SYSINFO(<parameter>)} - missing argument!)\n");
51 return -1;
52 } else if (!strcasecmp("loadavg", data)) {
53 double curloadavg;
54 getloadavg(&curloadavg, 1);
55 snprintf(buf, len, "%f", curloadavg);
56 } else if (!strcasecmp("numcalls", data)) {
57 snprintf(buf, len, "%d", ast_active_calls());
59 #if defined(HAVE_SYSINFO)
60 else if (!strcasecmp("uptime", data)) { /* in hours */
61 snprintf(buf, len, "%ld", sys_info.uptime/3600);
62 } else if (!strcasecmp("totalram", data)) { /* in KiB */
63 snprintf(buf, len, "%ld",(sys_info.totalram * sys_info.mem_unit)/1024);
64 } else if (!strcasecmp("freeram", data)) { /* in KiB */
65 snprintf(buf, len, "%ld",(sys_info.freeram * sys_info.mem_unit)/1024);
66 } else if (!strcasecmp("bufferram", data)) { /* in KiB */
67 snprintf(buf, len, "%ld",(sys_info.bufferram * sys_info.mem_unit)/1024);
68 } else if (!strcasecmp("totalswap", data)) { /* in KiB */
69 snprintf(buf, len, "%ld",(sys_info.totalswap * sys_info.mem_unit)/1024);
70 } else if (!strcasecmp("freeswap", data)) { /* in KiB */
71 snprintf(buf, len, "%ld",(sys_info.freeswap * sys_info.mem_unit)/1024);
72 } else if (!strcasecmp("numprocs", data)) {
73 snprintf(buf, len, "%d", sys_info.procs);
75 #endif
76 else {
77 ast_log(LOG_ERROR, "Unknown sysinfo parameter type '%s'.\n", data);
78 return -1;
81 return 0;
84 static struct ast_custom_function sysinfo_function = {
85 .name = "SYSINFO",
86 .synopsis = "Returns system information specified by parameter.",
87 .syntax = "SYSINFO(<parameter>)",
88 .read = sysinfo_helper,
89 .desc =
90 "Returns information from a given parameter\n"
91 " Options:\n"
92 " loadavg - system load average from past minute\n"
93 " numcalls - number of active calls currently in progress\n"
94 #if defined(HAVE_SYSINFO)
95 " uptime - system uptime in hours\n"
96 " totalram - total usable main memory size in KiB\n"
97 " freeram - available memory size in KiB\n"
98 " bufferram - memory used by buffers in KiB\n"
99 " totalswap - total swap space size in KiB\n"
100 " freeswap - free swap space still available in KiB\n"
101 " numprocs - number of current processes\n",
102 #endif /* HAVE_SYSINFO */
105 static int unload_module(void)
107 return ast_custom_function_unregister(&sysinfo_function);
110 static int load_module(void)
112 return ast_custom_function_register(&sysinfo_function);
115 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "System information related functions");