Ver código fonte

modules/dialog_ng: added support for active and early dialog stats

Jason Penton 10 anos atrás
pai
commit
aa4c310911

+ 19 - 4
modules/dialog_ng/dialog.c

@@ -65,9 +65,6 @@ struct tm_binds d_tmb;
 struct rr_binds d_rrb;
 pv_spec_t timeout_avp;
 
-int active_dlgs_cnt = 0;
-int early_dlgs_cnt	= 0;
-
 /* db stuff */
 int dlg_db_mode_param = DB_MODE_NONE;
 static int db_fetch_rows = 200;
@@ -92,6 +89,10 @@ static int w_dlg_terminate(struct sip_msg*, char*, char*);
 static int w_dlg_get(struct sip_msg*, char*, char*, char*);
 static int w_is_known_dlg(struct sip_msg *);
 
+stat_var *active_dlgs = 0;
+stat_var *early_dlgs = 0;
+stat_var *expired_dlgs = 0;
+
 static cmd_export_t cmds[] = {
     {"set_dlg_profile", (cmd_function) w_set_dlg_profile, 1, fixup_profile,
         0, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE},
@@ -157,6 +158,12 @@ static mi_export_t mi_cmds[] = {
     /* TODO: restore old dialog functionality later - also expose dialoig_out cmds, possibly*/
 };
 
+stat_export_t mod_stats[] = {
+    {"active_dialogs", STAT_NO_RESET, &active_dlgs},
+    {"early_dialogs", STAT_NO_RESET, &early_dlgs},
+    {0, 0, 0}
+};
+
 static rpc_export_t rpc_methods[];
 
 struct module_exports exports = {
@@ -164,7 +171,7 @@ struct module_exports exports = {
     DEFAULT_DLFLAGS, /* dlopen flags */
     cmds, /* exported functions */
     mod_params, /* param exports */
-    0, /* exported statistics */
+    mod_stats, /* exported statistics */
     mi_cmds, /* exported MI functions */
     0, /* exported pseudo-variables */
     0, /* extra processes */
@@ -362,6 +369,14 @@ static int mod_init(void) {
         return -1;
     }
 
+#ifdef STATISTICS
+    /* register statistics */
+    if (register_module_stats(exports.name, mod_stats) != 0) {
+	LM_ERR("failed to register %s statistics\n", exports.name);
+	return -1;
+    }
+#endif
+
 
     if (faked_msg_init() < 0)
         return -1;

+ 6 - 4
modules/dialog_ng/dlg_db_handler.c

@@ -38,6 +38,7 @@
 #include "../../str.h"
 #include "../../socket_info.h"
 #include "../../lib/srutils/srjson.h"
+#include "../../lib/kcore/statistics.h"
 
 #include "dlg_hash.h"
 #include "dlg_var.h"
@@ -123,8 +124,9 @@ static db1_con_t* dialog_db_handle    = 0; /* database connection handle */
 static db_func_t dialog_dbf;
 
 extern int dlg_enable_stats;
-extern int active_dlgs_cnt;
-extern int early_dlgs_cnt;
+extern stat_var *active_dlgs; /*!< number of active dialogs */
+extern stat_var *early_dlgs; /*!< number of active dialogs */
+
 
 #define GET_FIELD_IDX(_val, _idx)\
 		(_val + _idx)
@@ -546,10 +548,10 @@ static int load_dialog_info_from_db(int dlg_hash_size, int fetch_num_rows)
 			dlg->state 		= VAL_INT(GET_FIELD_IDX(values, DLGI_STATE_COL_IDX));
 
 			if (dlg->state==DLG_STATE_CONFIRMED) {
-				active_dlgs_cnt++;
+				update_stat(active_dlgs, 1);
 			}
 			else if (dlg->state==DLG_STATE_EARLY) {
-				early_dlgs_cnt++;
+				update_stat(early_dlgs, 1);
 			}
 
 			dlg->tl.timeout = (unsigned int)(VAL_INT(GET_FIELD_IDX(values, DLGI_TIMEOUT_COL_IDX)));

+ 21 - 13
modules/dialog_ng/dlg_handlers.c

@@ -47,9 +47,8 @@ extern struct tm_binds d_tmb;
 
 /* statistic variables */
 extern stat_var *early_dlgs; /*!< number of early dialogs */
-extern stat_var *processed_dlgs; /*!< number of processed dialogs */
+extern stat_var *active_dlgs; /*!< number of active dialogs */
 extern stat_var *expired_dlgs; /*!< number of expired dialogs */
-extern stat_var *failed_dlgs; /*!< number of failed dialogs */
 
 extern pv_elem_t *ruri_param_model; /*!< pv-string to get r-uri */
 
@@ -504,6 +503,10 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param) {
 	if (dlg_db_mode == DB_MODE_REALTIME)
 	    update_dialog_dbinfo(dlg);
 
+	if (old_state != DLG_STATE_EARLY) {
+	    update_stat(early_dlgs, 1);
+	}
+
 	run_dlg_callbacks(DLGCB_EARLY, dlg, req, rpl, DLG_DIR_UPSTREAM, 0);
 	return;
     }
@@ -604,7 +607,10 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param) {
         if (unref)
             unref_dlg(dlg, unref);
 
-        return;
+		if (old_state == DLG_STATE_EARLY)
+	    update_stat(early_dlgs, -1);
+
+		return;
     }
 
     if (unref) unref_dlg(dlg, unref);
@@ -1195,12 +1201,13 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param) {
                     dlg->callid.len, dlg->callid.s,
                     dlg->from_tag.len, dlg->from_tag.s);
 
-        } else {
-            unref++;
-        }
-        /* dialog terminated (BYE) */
-        dlg_terminated(req, dlg, dir);
-        unref_dlg(dlg, unref);
+		} else {
+			unref++;
+		}
+		/* dialog terminated (BYE) */
+		dlg_terminated(req, dlg, dir);
+		unref_dlg(dlg, unref);
+		update_stat(active_dlgs, -1);
 
         return;
     }
@@ -1303,10 +1310,11 @@ void dlg_ontimeout(struct dlg_tl *tl) {
                 dlg->from_tag.len, dlg->from_tag.s);
 
 
-        /* dialog timeout */
-        run_dlg_callbacks(DLGCB_EXPIRED, dlg, NULL, NULL, DLG_DIR_NONE, 0);
-
-        unref_dlg(dlg, unref + 1);
+		/* dialog timeout */
+		run_dlg_callbacks(DLGCB_EXPIRED, dlg, NULL, NULL, DLG_DIR_NONE, 0);
+		unref_dlg(dlg, unref + 1);
+		update_stat(&active_dlgs, -1);
+		update_stat(&expired_dlgs, 1);
     } else {
         unref_dlg(dlg, 1);
     }