adding statistics

This commit is contained in:
Kapil Gupta 2012-08-24 16:55:11 -04:00
parent cd6f4fbff9
commit 44a542719b
4 changed files with 111 additions and 23 deletions

View File

@ -450,6 +450,8 @@ switch_status_t megaco_context_add_termination(mg_context_t *ctx, mg_termination
ctx->terminations[1]->name, ctx->terminations[1]->uuid);
switch_ivr_uuid_bridge(ctx->terminations[0]->uuid, ctx->terminations[1]->uuid);
ctx->terminations[0]->profile->mg_stats->total_num_of_call_recvd++;
}
return SWITCH_STATUS_SUCCESS;
@ -638,6 +640,7 @@ switch_status_t megaco_profile_start(const char *profilename)
profile->next_context_id++;
profile->inact_tmr = 0x00;
profile->peer_active = 0x00;
profile->mg_stats = switch_core_alloc(pool, sizeof(mg_stats_t));
profile->inact_tmr_task_id = 0x00;
switch_thread_rwlock_create(&profile->rwlock, pool);

View File

@ -20,6 +20,7 @@ switch_status_t handle_all_term_status_cli_cmd(switch_stream_handle_t *stream, m
void get_peer_xml_buffer(char* prntBuf, MgPeerSta* cfm);
void megaco_cli_print_usage(switch_stream_handle_t *stream);
switch_status_t handle_show_activecalls_cli_cmd(switch_stream_handle_t *stream, megaco_profile_t* mg_profile);
switch_status_t handle_show_stats(switch_stream_handle_t *stream, megaco_profile_t* mg_profile);
/******************************************************************************/
@ -202,6 +203,12 @@ switch_status_t mg_process_cli_cmd(const char *cmd, switch_stream_handle_t *stre
/* mg <mg-profile> show activecalls */
megaco_profile_release(profile);
handle_show_activecalls_cli_cmd(stream, profile);
/*******************************************************************/
} else if(!strcasecmp(argv[3], "stats")){
/*******************************************************************/
/* mg <mg-profile> show stats */
megaco_profile_release(profile);
handle_show_stats(stream, profile);
/*******************************************************************/
}else if(!strcasecmp(argv[3], "alltermstatus")){
/*******************************************************************/
@ -287,13 +294,13 @@ void megaco_cli_print_usage(switch_stream_handle_t *stream)
stream->write_function(stream, "Usage: Profile Specific\n");
stream->write_function(stream, "mg profile <profile-name> start \n");
stream->write_function(stream, "mg profile <profile-name> stop \n");
stream->write_function(stream, "mg profile <profile-name> status \n");
stream->write_function(stream, "mg profile <profile-name> xmlstatus \n");
//stream->write_function(stream, "mg profile <profile-name> status \n");
//stream->write_function(stream, "mg profile <profile-name> xmlstatus \n");
stream->write_function(stream, "mg profile <profile-name> peerxmlstatus \n");
stream->write_function(stream, "mg profile <profile-name> send sc <term-id> <method> <reason> \n");
stream->write_function(stream, "mg profile <profile-name> send notify <term-id> <digits> \n");
stream->write_function(stream, "mg profile <profile-name> send ito notify \n");
stream->write_function(stream, "mg profile <profile-name> send cng <term-id> \n");
//stream->write_function(stream, "mg profile <profile-name> send sc <term-id> <method> <reason> \n");
//stream->write_function(stream, "mg profile <profile-name> send notify <term-id> <digits> \n");
//stream->write_function(stream, "mg profile <profile-name> send ito notify \n");
//stream->write_function(stream, "mg profile <profile-name> send cng <term-id> \n");
stream->write_function(stream, "mg profile <profile-name> show activecalls \n");
stream->write_function(stream, "mg profile <profile-name> show termstatus <term-id> \n");
stream->write_function(stream, "mg profile <profile-name> show alltermstatus \n");
@ -868,3 +875,41 @@ switch_status_t handle_show_activecalls_cli_cmd(switch_stream_handle_t *stream,
return SWITCH_STATUS_SUCCESS;
}
/******************************************************************************/
switch_status_t handle_show_stats(switch_stream_handle_t *stream, megaco_profile_t* mg_profile)
{
if(!mg_profile || !mg_profile->mg_stats){
stream->write_function(stream, "-ERR NULL profile/term pointer \n");
return SWITCH_STATUS_FALSE;
}
stream->write_function(stream, "Total Number of Physical ADD received = %d \n", mg_profile->mg_stats->total_num_of_phy_add_recvd);
stream->write_function(stream, "Total Number of RTP ADD received = %d \n", mg_profile->mg_stats->total_num_of_rtp_add_recvd);
stream->write_function(stream, "Total Number of SUB received = %d \n", mg_profile->mg_stats->total_num_of_sub_recvd);
stream->write_function(stream, "Total Number of CALL received = %d \n", mg_profile->mg_stats->total_num_of_call_recvd);
stream->write_function(stream, "Total Number of ADD failed = %d \n", mg_profile->mg_stats->total_num_of_add_failed);
stream->write_function(stream, "Total Number of Term Already in context Error = %d \n",
mg_profile->mg_stats->total_num_of_term_already_in_ctxt_error);
stream->write_function(stream, "Total Number of choose context failed Error = %d \n",
mg_profile->mg_stats->total_num_of_choose_ctxt_failed_error);
stream->write_function(stream, "Total Number of choose term failed Error = %d \n",
mg_profile->mg_stats->total_num_of_choose_term_failed_error);
stream->write_function(stream, "Total Number of find term failed Error = %d \n",
mg_profile->mg_stats->total_num_of_find_term_failed_error);
stream->write_function(stream, "Total Number of get context failed Error = %d \n",
mg_profile->mg_stats->total_num_of_get_ctxt_failed_error);
stream->write_function(stream, "Total Number of un-supported codec error = %d \n",
mg_profile->mg_stats->total_num_of_un_supported_codec_error);
stream->write_function(stream, "Total Number of Term addition to context failed error = %d \n",
mg_profile->mg_stats->total_num_of_add_term_failed_error);
stream->write_function(stream, "Total Number of Term activation failed error = %d \n",
mg_profile->mg_stats->total_num_of_term_activation_failed_error);
stream->write_function(stream, "Total Number of Term not found in context error = %d \n",
mg_profile->mg_stats->total_num_of_no_term_ctxt_error);
return SWITCH_STATUS_SUCCESS;
}
/******************************************************************************/

View File

@ -629,10 +629,11 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
mg_ctxt = megaco_choose_context(mg_profile);
if(NULL == mg_ctxt){
mg_profile->mg_stats->total_num_of_choose_ctxt_failed_error++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR," megaco_choose_context failed \n");
mg_util_set_err_string(&errTxt, " Resource Failure ");
err_code = MGT_MGCO_RSP_CODE_RSRC_ERROR;
goto error;
mg_util_set_err_string(&errTxt, " Resource Failure ");
err_code = MGT_MGCO_RSP_CODE_RSRC_ERROR;
goto error;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO," Allocated Context[%p] with context_id[%d]\n", (void*)mg_ctxt, mg_ctxt->context_id);
@ -653,6 +654,7 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
" megaco_get_context failed for context-id[%ld]\n", inc_cmd->contextId.val.val);
#endif
mg_profile->mg_stats->total_num_of_get_ctxt_failed_error++;
mg_util_set_err_string(&errTxt, " Resource Failure ");
err_code = MGT_MGCO_RSP_CODE_RSRC_ERROR;
goto error;
@ -665,8 +667,10 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
(MGT_TERMID_CHOOSE == termId->type.val)){
term = megaco_choose_termination(mg_profile, mg_profile->rtp_termination_id_prefix);
mg_profile->mg_stats->total_num_of_rtp_add_recvd++;
if(NULL == term){
mg_profile->mg_stats->total_num_of_choose_term_failed_error++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR," megaco_choose_termination failed \n");
mg_util_set_err_string(&errTxt, " Resource Failure ");
err_code = MGT_MGCO_RSP_CODE_RSRC_ERROR;
@ -680,8 +684,10 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
/********************************************************************/
}else{ /* Physical termination */
term = megaco_find_termination(mg_profile, (char*)termId->name.lcl.val);
mg_profile->mg_stats->total_num_of_phy_add_recvd++;
if(NULL == term){
mg_profile->mg_stats->total_num_of_find_term_failed_error++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
" megaco_find_termination failed for term-id[%s] \n",(char*)termId->name.lcl.val);
mg_util_set_err_string(&errTxt, " Resource Failure ");
@ -697,6 +703,7 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
/* check if termination already is in call */
if(term->context){
mg_profile->mg_stats->total_num_of_term_already_in_ctxt_error++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR," Termination[%p : %s] "
"already in context[%p -%d]..rejecting ADD \n",
(void*)term, term->name, (void*)term->context,term->context->context_id);
@ -711,6 +718,7 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
/* IF there is any error , return */
if(term->mg_error_code && (*term->mg_error_code == MGT_MGCP_RSP_CODE_INCONSISTENT_LCL_OPT)){
mg_profile->mg_stats->total_num_of_un_supported_codec_error++;
mg_util_set_err_string(&errTxt, " Unsupported Codec ");
err_code = MGT_MGCP_RSP_CODE_INCONSISTENT_LCL_OPT;
goto error;
@ -719,6 +727,7 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
/* associate physical termination to context */
if(SWITCH_STATUS_FALSE == megaco_context_add_termination(mg_ctxt, term)){
mg_profile->mg_stats->total_num_of_add_term_failed_error++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"megaco_context_add_termination failed \n");
mg_util_set_err_string(&errTxt, " Resource Failure ");
err_code = MGT_MGCO_RSP_CODE_RSRC_ERROR;
@ -818,6 +827,7 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
/* only for RTP */
if(SWITCH_STATUS_FALSE == mg_build_sdp(&desc->u.media, inc_med_desc, mg_profile, term, &rsp.u.mgCmdRsp[0]->memCp)) {
if(term->mg_error_code && (*term->mg_error_code == MGT_MGCP_RSP_CODE_INCONSISTENT_LCL_OPT)){
mg_profile->mg_stats->total_num_of_un_supported_codec_error++;
mg_util_set_err_string(&errTxt, " Unsupported Codec ");
err_code = MGT_MGCP_RSP_CODE_INCONSISTENT_LCL_OPT;
goto error;
@ -846,6 +856,7 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
return ret;
error:
mg_profile->mg_stats->total_num_of_add_failed++;
if (SWITCH_STATUS_SUCCESS ==
mg_build_mgco_err_request(&mgErr, txn_id, ctxtId, err_code, &errTxt)) {
sng_mgco_send_err(mg_profile->idx, mgErr);
@ -956,6 +967,7 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand
term = megaco_find_termination(mg_profile, (char*)termId->name.lcl.val);
if(NULL == term){
mg_profile->mg_stats->total_num_of_find_term_failed_error++;
mg_util_set_term_string(&errTxt,termId);
err_code = MGT_MGCO_RSP_CODE_UNKNOWN_TERM_ID;
goto error;
@ -970,6 +982,7 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand
/*find context based on received context-id */
mg_ctxt = megaco_get_context(mg_profile, ctxtId->val.val);
if(NULL == mg_ctxt){
mg_profile->mg_stats->total_num_of_get_ctxt_failed_error++;
#ifdef BIT_64
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Modify request Failed, context[%d] not found \n",ctxtId->val.val);
@ -983,6 +996,7 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand
}
if(SWITCH_STATUS_FALSE == megaco_context_is_term_present(mg_ctxt, term)){
mg_profile->mg_stats->total_num_of_no_term_ctxt_error++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Modify request Failed, requested term not associated with any context \n");
/* ERROR - termination didnt bind with requested context */
@ -1012,6 +1026,7 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand
/* IF there is any error , return */
if(term->mg_error_code && (*term->mg_error_code == MGT_MGCP_RSP_CODE_INCONSISTENT_LCL_OPT)){
mg_profile->mg_stats->total_num_of_un_supported_codec_error++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Modify request Failed, Unsupported Codec \n");
mg_util_set_err_string(&errTxt, " Unsupported Codec ");
@ -1041,6 +1056,7 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand
/* SDP updated to termination */
if(SWITCH_STATUS_SUCCESS != megaco_activate_termination(term)) {
mg_profile->mg_stats->total_num_of_term_activation_failed_error++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Modify request Failed, Activation of termination failed \n");
mg_util_set_err_string(&errTxt, " Resource Failure ");
@ -1193,6 +1209,8 @@ switch_status_t handle_mg_subtract_cmd(megaco_profile_t* mg_profile, MgMgcoComma
termLst = mg_get_term_id_list(inc_cmd);
termId = termLst->terms[0];
mg_profile->mg_stats->total_num_of_sub_recvd++;
/************************************************************************************************************************************************************/
/* Validating Subtract request *******************************************/
@ -1243,6 +1261,7 @@ switch_status_t handle_mg_subtract_cmd(megaco_profile_t* mg_profile, MgMgcoComma
/*find context based on received context-id */
mg_ctxt = megaco_get_context(mg_profile, ctxtId->val.val);
if(NULL == mg_ctxt){
mg_profile->mg_stats->total_num_of_get_ctxt_failed_error++;
mg_util_set_ctxt_string(&errTxt, ctxtId);
err_code = MGT_MGCO_RSP_CODE_UNKNOWN_CTXT;
goto error;
@ -1262,22 +1281,24 @@ switch_status_t handle_mg_subtract_cmd(megaco_profile_t* mg_profile, MgMgcoComma
term = megaco_find_termination(mg_profile, (char*)termId->name.lcl.val);
if(SWITCH_STATUS_FALSE == megaco_context_is_term_present(mg_ctxt, term)){
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Subtract request Failed, termination no associated with any context \n");
/* ERROR - termination didnt bind with requested context */
mg_util_set_term_string(&errTxt,termId);
err_code = MGT_MGCO_RSP_CODE_NO_TERM_CTXT;
goto error;
}
if(NULL == term){
if(NULL == term){
mg_profile->mg_stats->total_num_of_find_term_failed_error++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Subtract request Failed, no termination found for input term string[%s] \n", (char*)termId->name.lcl.val);
mg_util_set_term_string(&errTxt,termId);
err_code = MGT_MGCO_RSP_CODE_UNKNOWN_TERM_ID;
goto error;
}
mg_util_set_term_string(&errTxt,termId);
err_code = MGT_MGCO_RSP_CODE_UNKNOWN_TERM_ID;
goto error;
}
if(SWITCH_STATUS_FALSE == megaco_context_is_term_present(mg_ctxt, term)){
mg_profile->mg_stats->total_num_of_no_term_ctxt_error++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Subtract request Failed, termination no associated with any context \n");
/* ERROR - termination didnt bind with requested context */
mg_util_set_term_string(&errTxt,termId);
err_code = MGT_MGCO_RSP_CODE_NO_TERM_CTXT;
goto error;
}
/* remove termination from context */
megaco_context_sub_termination(mg_ctxt, term);

View File

@ -61,6 +61,24 @@ typedef struct mg_peer_profile_s{
} mg_peer_profile_t;
typedef struct mg_stats_s{
uint32_t total_num_of_phy_add_recvd;
uint32_t total_num_of_rtp_add_recvd;
uint32_t total_num_of_sub_recvd;
uint32_t total_num_of_call_recvd;
uint32_t total_num_of_add_failed;
uint32_t total_num_of_term_already_in_ctxt_error;
uint32_t total_num_of_choose_ctxt_failed_error;
uint32_t total_num_of_choose_term_failed_error;
uint32_t total_num_of_find_term_failed_error;
uint32_t total_num_of_get_ctxt_failed_error;
uint32_t total_num_of_un_supported_codec_error;
uint32_t total_num_of_add_term_failed_error;
uint32_t total_num_of_term_activation_failed_error;
uint32_t total_num_of_no_term_ctxt_error;
}mg_stats_t;
typedef enum {
MG_TERM_FREE = 0,
MG_TERM_TDM,
@ -217,6 +235,7 @@ struct megaco_profile_s {
uint32_t rtpid_next;
mg_termination_t *physical_terminations;
mg_stats_t* mg_stats;
switch_hash_t *terminations;
switch_thread_rwlock_t *terminations_rwlock;