summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Parker <jparker@digium.com>2007-12-07 16:11:05 +0000
committerJason Parker <jparker@digium.com>2007-12-07 16:11:05 +0000
commit02ea9face7d5bef3fa1c4bb14a3a2147c5f3b737 (patch)
treea4fa144f2008bf16fa24587b437b590a946b4b54
parent00297c91e52d468e7c778886982290a310a4ebe3 (diff)
Add count of total number of calls processed by asterisk during it's lifetime.
Add number of total calls and current calls to SNMP. Closes issue #10057, patch by jcmoore. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@91779 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--doc/asterisk-mib.txt24
-rw-r--r--include/asterisk/pbx.h5
-rw-r--r--main/cli.c59
-rw-r--r--main/pbx.c10
-rw-r--r--res/snmp/agent.c10
5 files changed, 105 insertions, 3 deletions
diff --git a/doc/asterisk-mib.txt b/doc/asterisk-mib.txt
index fbbc63356..9f62cf673 100644
--- a/doc/asterisk-mib.txt
+++ b/doc/asterisk-mib.txt
@@ -11,7 +11,7 @@ IMPORTS
FROM DIGIUM-MIB;
asterisk MODULE-IDENTITY
- LAST-UPDATED "200606081626Z"
+ LAST-UPDATED "200708211450Z"
ORGANIZATION "Digium, Inc."
CONTACT-INFO
"Mark A. Spencer
@@ -30,6 +30,9 @@ asterisk MODULE-IDENTITY
Tel: +47 5598 7200
Email: tholo@voop.no"
DESCRIPTION
+ "Add total and current call counter statistics."
+ REVISION "200708211450Z"
+ DESCRIPTION
"Asterisk is an Open Source PBX. This MIB defined
objects for managing Asterisk instances."
REVISION "200603061840Z"
@@ -104,6 +107,23 @@ astConfigSocket OBJECT-TYPE
"The control socket for giving Asterisk commands."
::= { asteriskConfiguration 4 }
+astConfigCallsActive OBJECT-TYPE
+ SYNTAX Gauge32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The number of calls currently active on the Asterisk PBX."
+ ::= { asteriskConfiguration 5 }
+
+astConfigCallsProcessed OBJECT-TYPE
+ SYNTAX Counter32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The total number of calls processed through the Asterisk PBX since last
+ restart."
+ ::= { asteriskConfiguration 6 }
+
-- asteriskModules
astNumModules OBJECT-TYPE
@@ -194,7 +214,7 @@ astIndDescription OBJECT-TYPE
-- asteriskChannels
astNumChannels OBJECT-TYPE
- SYNTAX Integer32
+ SYNTAX Gauge32
MAX-ACCESS read-only
STATUS current
DESCRIPTION
diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h
index 3568e7ec4..1082c74b2 100644
--- a/include/asterisk/pbx.h
+++ b/include/asterisk/pbx.h
@@ -892,6 +892,11 @@ int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_m
* \brief Retrieve the number of active calls
*/
int ast_active_calls(void);
+
+/*!
+ * \brief Retrieve the total number of calls processed through the PBX since last restart
+ */
+int ast_processed_calls(void);
/*!
* \brief executes a read operation on a function
diff --git a/main/cli.c b/main/cli.c
index 52b8d51b4..94ed6b565 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -570,6 +570,61 @@ static char *handle_modlist(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
#undef MODLIST_FORMAT
#undef MODLIST_FORMAT2
+static char *handle_showcalls(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct timeval curtime = ast_tvnow();
+ int showuptime, printsec;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show calls [uptime]";
+ e->usage =
+ "Usage: core show calls [uptime] [seconds]\n"
+ " Lists number of currently active calls and total number of calls\n"
+ " processed through PBX since last restart. If 'uptime' is specified\n"
+ " the system uptime is also displayed. If 'seconds' is specified in\n"
+ " addition to 'uptime', the system uptime is displayed in seconds.\n";
+ return NULL;
+
+ case CLI_GENERATE:
+ if (a->pos != e->args)
+ return NULL;
+ return a->n == 0 ? ast_strdup("seconds") : NULL;
+ }
+
+ /* regular handler */
+ if (a->argc >= e->args && !strcasecmp(a->argv[e->args-1],"uptime")) {
+ showuptime = 1;
+
+ if (a->argc == e->args+1 && !strcasecmp(a->argv[e->args],"seconds"))
+ printsec = 1;
+ else if (a->argc == e->args)
+ printsec = 0;
+ else
+ return CLI_SHOWUSAGE;
+ } else if (a->argc == e->args-1) {
+ showuptime = 0;
+ printsec = 0;
+ } else
+ return CLI_SHOWUSAGE;
+
+ if (option_maxcalls) {
+ ast_cli(a->fd, "%d of %d max active call%s (%5.2f%% of capacity)\n",
+ ast_active_calls(), option_maxcalls, ESS(ast_active_calls()),
+ ((double)ast_active_calls() / (double)option_maxcalls) * 100.0);
+ } else {
+ ast_cli(a->fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls()));
+ }
+
+ ast_cli(a->fd, "%d call%s processed\n", ast_processed_calls(), ESS(ast_processed_calls()));
+
+ if (ast_startuptime.tv_sec && showuptime) {
+ print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime", printsec);
+ }
+
+ return RESULT_SUCCESS;
+}
+
static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
#define FORMAT_STRING "%-20.20s %-20.20s %-7.7s %-30.30s\n"
@@ -680,6 +735,8 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
((double)ast_active_calls() / (double)option_maxcalls) * 100.0);
else
ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls()));
+
+ ast_cli(fd, "%d call%s processed\n", ast_processed_calls(), ESS(ast_processed_calls()));
}
return CLI_SUCCESS;
@@ -1124,6 +1181,8 @@ static struct ast_cli_entry cli_cli[] = {
AST_CLI_DEFINE(handle_chanlist, "Display information on channels"),
+ AST_CLI_DEFINE(handle_showcalls, "Display information on calls"),
+
AST_CLI_DEFINE(handle_showchan, "Display information on a specific channel"),
AST_CLI_DEFINE(handle_core_set_debug_channel, "Enable/disable debugging on a channel",
diff --git a/main/pbx.c b/main/pbx.c
index d27011834..2d8205575 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -416,6 +416,7 @@ static struct ast_event_sub *device_state_sub;
AST_MUTEX_DEFINE_STATIC(maxcalllock);
static int countcalls;
+static int totalcalls;
static AST_RWLIST_HEAD_STATIC(acf_root, ast_custom_function);
@@ -3472,8 +3473,10 @@ static int increase_call_count(const struct ast_channel *c)
}
#endif
- if (!failed)
+ if (!failed) {
countcalls++;
+ totalcalls++;
+ }
ast_mutex_unlock(&maxcalllock);
return failed;
@@ -3560,6 +3563,11 @@ int ast_active_calls(void)
return countcalls;
}
+int ast_processed_calls(void)
+{
+ return totalcalls;
+}
+
int pbx_set_autofallthrough(int newval)
{
int oldval = autofallthrough;
diff --git a/res/snmp/agent.c b/res/snmp/agent.c
index b728c55a9..88d703dff 100644
--- a/res/snmp/agent.c
+++ b/res/snmp/agent.c
@@ -67,6 +67,8 @@ static oid asterisk_oid[] = { 1, 3, 6, 1, 4, 1, 22736, 1 };
#define ASTCONFRELOADTIME 2
#define ASTCONFPID 3
#define ASTCONFSOCKET 4
+#define ASTCONFACTIVECALLS 5
+#define ASTCONFPROCESSEDCALLS 6
#define ASTMODULES 3
#define ASTMODCOUNT 1
@@ -592,6 +594,12 @@ static u_char *ast_var_Config(struct variable *vp, oid *name, size_t *length,
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;
}
@@ -723,6 +731,8 @@ static void init_asterisk_mib(void)
{ASTCONFRELOADTIME, ASN_TIMETICKS, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFRELOADTIME}},
{ASTCONFPID, ASN_INTEGER, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFPID}},
{ASTCONFSOCKET, ASN_OCTET_STR, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFSOCKET}},
+ {ASTCONFACTIVECALLS, ASN_GAUGE, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFACTIVECALLS}},
+ {ASTCONFPROCESSEDCALLS, ASN_INTEGER, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFPROCESSEDCALLS}},
{ASTMODCOUNT, ASN_INTEGER, RONLY, ast_var_Modules , 2, {ASTMODULES, ASTMODCOUNT}},
{ASTINDCOUNT, ASN_INTEGER, RONLY, ast_var_indications, 2, {ASTINDICATIONS, ASTINDCOUNT}},
{ASTINDCURRENT, ASN_OCTET_STR, RONLY, ast_var_indications, 2, {ASTINDICATIONS, ASTINDCURRENT}},