Ejemplo n.º 1
0
static int sysinfo_helper(struct ast_channel *chan, const char *cmd, char *data,
		                         char *buf, size_t len)
{
#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, "%lu",(sys_info.totalram * sys_info.mem_unit)/1024);
	} else if (!strcasecmp("freeram", data)) {          /* in KiB */
		snprintf(buf, len, "%lu",(sys_info.freeram * sys_info.mem_unit)/1024);
	} else if (!strcasecmp("bufferram", data)) {        /* in KiB */
		snprintf(buf, len, "%lu",(sys_info.bufferram * sys_info.mem_unit)/1024);
	} else if (!strcasecmp("totalswap", data)) {        /* in KiB */
		snprintf(buf, len, "%lu",(sys_info.totalswap * sys_info.mem_unit)/1024);
	} else if (!strcasecmp("freeswap", data)) {         /* in KiB */
		snprintf(buf, len, "%lu",(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;
}
Ejemplo n.º 2
0
static u_char *ast_var_Config(struct variable *vp, oid *name, size_t *length,
							 int exact, size_t *var_len, WriteMethod **write_method)
{
	static unsigned long long_ret;
	struct timeval tval;

	if (header_generic(vp, name, length, exact, var_len, write_method))
		return NULL;

	switch (vp->magic) {
	case ASTCONFUPTIME:
		gettimeofday(&tval, NULL);
		long_ret = difftime(tval.tv_sec, ast_startuptime.tv_sec) * 100 + tval.tv_usec / 10000 - ast_startuptime.tv_usec / 10000;
		return (u_char *)&long_ret;
	case ASTCONFRELOADTIME:
		gettimeofday(&tval, NULL);
		if (ast_lastreloadtime.tv_sec)
			long_ret = difftime(tval.tv_sec, ast_lastreloadtime.tv_sec) * 100 + tval.tv_usec / 10000 - ast_lastreloadtime.tv_usec / 10000;
		else
			long_ret = difftime(tval.tv_sec, ast_startuptime.tv_sec) * 100 + tval.tv_usec / 10000 - ast_startuptime.tv_usec / 10000;
		return (u_char *)&long_ret;
	case ASTCONFPID:
		long_ret = getpid();
		return (u_char *)&long_ret;
	case ASTCONFSOCKET:
		*var_len = strlen(ast_config_AST_SOCKET);
		return (u_char *)ast_config_AST_SOCKET;
	case ASTCONFACTIVECALLS:
		long_ret = ast_active_calls();
		return (u_char *)&long_ret;
	case ASTCONFPROCESSEDCALLS:
		long_ret = ast_processed_calls();
		return (u_char *)&long_ret;
	default:
		break;
	}
	return NULL;
}