Browse code

modules/ims_qos: Added stats framework and basic stats

Richard Good authored on 26/02/2015 08:57:29
Showing 6 changed files
... ...
@@ -51,6 +51,7 @@
51 51
 #include "mod.h"
52 52
 #include "cdpeventprocessor.h"
53 53
 #include "rx_str.h"
54
+#include "ims_qos_stats.h"
54 55
 
55 56
 cdp_cb_event_list_t *cdp_event_list = 0;
56 57
 extern usrloc_api_t ul;
... ...
@@ -60,6 +61,8 @@ extern int cdp_event_threshold;
60 60
 extern int cdp_event_latency_loglevel;
61 61
 extern int cdp_event_list_size_threshold;
62 62
 
63
+extern struct ims_qos_counters_h ims_qos_cnts_h;
64
+
63 65
 int init_cdp_cb_event_list() {
64 66
     cdp_event_list = shm_malloc(sizeof (cdp_cb_event_list_t));
65 67
     if (!cdp_event_list) {
... ...
@@ -255,10 +258,12 @@ void cdp_cb_event_process() {
255 255
 			    ul.update_pcontact(domain, &ci, pcontact);
256 256
 			}
257 257
 			ul.unlock_udomain(domain, &p_session_data->registration_aor, &p_session_data->ip, p_session_data->recv_port);
258
+			counter_add(ims_qos_cnts_h.active_registration_rx_sessions, -1);
258 259
 		    }
259 260
                 } else {
260 261
                     LM_DBG("This is a media bearer session session");
261
-                    
262
+		    
263
+		    counter_add(ims_qos_cnts_h.active_media_rx_sessions, -1);
262 264
                     //we only terminate the dialog if this was triggered from the transport plane or timeout - i.e. if must_terminate_dialog is set
263 265
                     //if this was triggered from the signalling plane (i.e. someone hanging up) then we don'y need to terminate the dialog
264 266
                     if (p_session_data->must_terminate_dialog) {
265 267
new file mode 100644
... ...
@@ -0,0 +1,116 @@
0
+/*
1
+ * $Id$
2
+ *
3
+ * Copyright (C) 2012 Smile Communications, jason.penton@smilecoms.com
4
+ * Copyright (C) 2012 Smile Communications, richard.good@smilecoms.com
5
+ * 
6
+ * The initial version of this code was written by Dragos Vingarzan
7
+ * (dragos(dot)vingarzan(at)fokus(dot)fraunhofer(dot)de and the
8
+ * Fruanhofer Institute. It was and still is maintained in a separate
9
+ * branch of the original SER. We are therefore migrating it to
10
+ * Kamailio/SR and look forward to maintaining it from here on out.
11
+ * 2011/2012 Smile Communications, Pty. Ltd.
12
+ * ported/maintained/improved by 
13
+ * Jason Penton (jason(dot)penton(at)smilecoms.com and
14
+ * Richard Good (richard(dot)good(at)smilecoms.com) as part of an 
15
+ * effort to add full IMS support to Kamailio/SR using a new and
16
+ * improved architecture
17
+ * 
18
+ * NB: Alot of this code was originally part of OpenIMSCore,
19
+ * FhG Fokus. 
20
+ * Copyright (C) 2004-2006 FhG Fokus
21
+ * Thanks for great work! This is an effort to 
22
+ * break apart the various CSCF functions into logically separate
23
+ * components. We hope this will drive wider use. We also feel
24
+ * that in this way the architecture is more complete and thereby easier
25
+ * to manage in the Kamailio/SR environment
26
+ *
27
+ * This file is part of Kamailio, a free SIP server.
28
+ *
29
+ * Kamailio is free software; you can redistribute it and/or modify
30
+ * it under the terms of the GNU General Public License as published by
31
+ * the Free Software Foundation; either version 2 of the License, or
32
+ * (at your option) any later version
33
+ *
34
+ * Kamailio is distributed in the hope that it will be useful,
35
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
36
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
+ * GNU General Public License for more details.
38
+ *
39
+ * You should have received a copy of the GNU General Public License 
40
+ * along with this program; if not, write to the Free Software 
41
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
42
+ * 
43
+ *
44
+ *
45
+ *
46
+ * History:
47
+ * --------
48
+ *  2011-02-02  initial version (jason.penton)
49
+ */
50
+
51
+
52
+#include "ims_qos_stats.h"
53
+
54
+struct ims_qos_counters_h ims_qos_cnts_h;
55
+enum sctp_info_req { IMS_QOS_REGISTRATION_AAR_AVG_RSP, IMS_QOS_MEDIA_AAR_AVG_RSP };
56
+
57
+static counter_val_t ims_qos_internal_stats(counter_handle_t h, void* what);
58
+
59
+counter_def_t ims_qos_cnt_defs[] = {
60
+    {&ims_qos_cnts_h.active_registration_rx_sessions,	    "active_registration_rx_sessions",		0, 0, 0,	    "number of currently active registration Rx sessions"},
61
+    {&ims_qos_cnts_h.registration_aar_avg_response_time,    "registration_aar_avg_response_time",	0, ims_qos_internal_stats, (void*) (long) IMS_QOS_REGISTRATION_AAR_AVG_RSP,	"avg response time for registration AARs"},
62
+    {&ims_qos_cnts_h.registration_aar_timeouts,		    "registration_aar_timeouts",		0, 0, 0,	    "total number of registration AAR timeouts"},
63
+    {&ims_qos_cnts_h.failed_registration_aars,		    "failed_registration_aars",			0, 0, 0,	    "total number of failed registration AARs"},
64
+    {&ims_qos_cnts_h.registration_aars,			    "registration_aars",			0, 0, 0,	    "total number of registration AARs"},
65
+    {&ims_qos_cnts_h.asrs,				    "asrs",					0, 0, 0,	    "total number of registration ASRs"},
66
+    {&ims_qos_cnts_h.successful_registration_aars,	    "successful_registration_aars",		0, 0, 0,	    "total number of successful registration AARs"},
67
+    {&ims_qos_cnts_h.registration_aar_response_time,	    "registration_aar_response_time",		0, 0, 0,	    "total number of seconds waiting for registration AAR responses"},
68
+
69
+    {&ims_qos_cnts_h.active_media_rx_sessions,		    "active_media_rx_sessions",		0, 0, 0,		    "number of currently active media Rx sessions"},
70
+    {&ims_qos_cnts_h.media_aar_avg_response_time,	    "media_aar_avg_response_time",	0, ims_qos_internal_stats, (void*) (long) IMS_QOS_MEDIA_AAR_AVG_RSP,	"avg response time for media AARs"},
71
+    {&ims_qos_cnts_h.media_aar_timeouts,		    "media_aar_timeouts",		0, 0, 0,		    "total number of media AAR timeouts"},
72
+    {&ims_qos_cnts_h.failed_media_aars,			    "failed_media_aars",		0, 0, 0,		    "total number of failed media AARs"},
73
+    {&ims_qos_cnts_h.media_aars,			    "media_aars",			0, 0, 0,		    "total number of media AARs"},
74
+    {&ims_qos_cnts_h.successful_media_aars,		    "successful_media_aars",		0, 0, 0,		    "total number of successful media AARs"},
75
+    {&ims_qos_cnts_h.media_aar_response_time,		    "media_aar_response_time",		0, 0, 0,		    "total number of seconds waiting for media AAR responses"},
76
+    {0, 0, 0, 0, 0, 0}
77
+};
78
+
79
+
80
+int ims_qos_init_counters() {
81
+    if (counter_register_array("ims_qos", ims_qos_cnt_defs) < 0)
82
+	goto error;
83
+    return 0;
84
+error:
85
+    return -1;
86
+}
87
+
88
+void ims_qos_destroy_counters() {
89
+    
90
+}
91
+
92
+/** helper function for some stats (which are kept internally).
93
+ */
94
+static counter_val_t ims_qos_internal_stats(counter_handle_t h, void* what) {
95
+    enum sctp_info_req w;
96
+
97
+    w = (int) (long) what;
98
+    switch (w) {
99
+	case IMS_QOS_REGISTRATION_AAR_AVG_RSP:
100
+	    if (counter_get_val(ims_qos_cnts_h.registration_aars) == 0) 
101
+		return 0;
102
+	    else
103
+		return counter_get_val(ims_qos_cnts_h.registration_aar_response_time)/counter_get_val(ims_qos_cnts_h.registration_aars);
104
+	    break;
105
+	case IMS_QOS_MEDIA_AAR_AVG_RSP:
106
+	    if (counter_get_val(ims_qos_cnts_h.media_aars) == 0) 
107
+		return 0;
108
+	    else
109
+		return counter_get_val(ims_qos_cnts_h.media_aar_response_time)/counter_get_val(ims_qos_cnts_h.media_aars);
110
+	    break;
111
+	default:
112
+	    return 0;
113
+    };
114
+    return 0;
115
+}
0 116
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+/* 
1
+ * File:   ims_qos_stats.h
2
+ * Author: jaybeepee
3
+ *
4
+ * Created on 24 February 2015, 11:15 AM
5
+ */
6
+
7
+#ifndef IMS_QOS_STATS_H
8
+#define	IMS_QOS_STATS_H
9
+
10
+#include "../../counters.h"
11
+
12
+struct ims_qos_counters_h {
13
+    counter_handle_t registration_aar_avg_response_time;
14
+    counter_handle_t registration_aar_response_time;
15
+    counter_handle_t registration_aar_timeouts;
16
+    counter_handle_t failed_registration_aars;
17
+    counter_handle_t registration_aars;
18
+    counter_handle_t asrs;
19
+    counter_handle_t successful_registration_aars;
20
+    counter_handle_t active_registration_rx_sessions;
21
+    counter_handle_t media_aar_avg_response_time;
22
+    counter_handle_t media_aar_response_time;
23
+    counter_handle_t media_aar_timeouts;
24
+    counter_handle_t failed_media_aars;
25
+    counter_handle_t media_aars;
26
+    counter_handle_t successful_media_aars;
27
+    counter_handle_t active_media_rx_sessions;
28
+};
29
+
30
+int ims_qos_init_counters();
31
+void ims_qos_destroy_counters();
32
+
33
+#endif	/* IMS_QOS_STATS_H */
34
+
35
+
36
+
... ...
@@ -43,7 +43,6 @@
43 43
  * 
44 44
  */
45 45
 
46
-#include "stats.h"
47 46
 #include <stdio.h>
48 47
 #include <string.h>
49 48
 #include <stdlib.h>
... ...
@@ -72,7 +71,7 @@
72 72
 #include "../../parser/sdp/sdp.h"
73 73
 
74 74
 #include "../../lib/ims/useful_defs.h"
75
-
75
+#include "ims_qos_stats.h"
76 76
 
77 77
 MODULE_VERSION
78 78
 
... ...
@@ -103,6 +102,13 @@ int video_default_bandwidth = 128;
103 103
 
104 104
 int cdp_event_list_size_threshold = 0;  /**Threshold for size of cdp event list after which a warning is logged */
105 105
 
106
+stat_var *aars;
107
+stat_var *strs;
108
+stat_var *asrs;
109
+stat_var *successful_aars;
110
+stat_var *successful_strs;
111
+
112
+
106 113
 /** module functions */
107 114
 static int mod_init(void);
108 115
 static int mod_child_init(int);
... ...
@@ -142,11 +148,6 @@ static param_export_t params[] = {
142 142
     { 0, 0, 0}
143 143
 };
144 144
 
145
-stat_export_t mod_stats[] = {
146
-    {"aar_avg_response_time", STAT_IS_FUNC, (stat_var**) get_avg_aar_response_time},
147
-    {"aar_timeouts", 0, (stat_var**) & stat_aar_timeouts},
148
-    {0, 0, 0}
149
-};
150 145
 
151 146
 /** module exports */
152 147
 struct module_exports exports = {"ims_qos", DEFAULT_DLFLAGS, /* dlopen flags */
... ...
@@ -162,18 +163,6 @@ struct module_exports exports = {"ims_qos", DEFAULT_DLFLAGS, /* dlopen flags */
162 162
  * init module function
163 163
  */
164 164
 static int mod_init(void) {
165
-#ifdef STATISTICS
166
-    /* register statistics */
167
-    if (register_module_stats(exports.name, mod_stats) != 0) {
168
-        LM_ERR("failed to register core statistics\n");
169
-        goto error;
170
-    }
171
-
172
-    if (!register_stats()) {
173
-        LM_ERR("Unable to register statistics\n");
174
-        goto error;
175
-    }
176
-#endif
177 165
 
178 166
     callback_singleton = shm_malloc(sizeof (int));
179 167
     *callback_singleton = 0;
... ...
@@ -226,6 +215,11 @@ static int mod_init(void) {
226 226
         LM_ERR("unable to initialise cdp callback event list\n");
227 227
         return -1;
228 228
     }
229
+    
230
+    if (ims_qos_init_counters() != 0) {
231
+	    LM_ERR("Failed to register counters for ims_qos module\n");
232
+	    return -1;
233
+	}
229 234
 
230 235
     return 0;
231 236
 error:
... ...
@@ -48,7 +48,6 @@
48 48
  *  2011-02-02  initial version (jason.penton)
49 49
  */
50 50
 
51
-#include "stats.h"
52 51
 #include "../../mem/shm_mem.h"
53 52
 #include "../../parser/sdp/sdp.h"
54 53
 #include "../cdp_avp/mod_export.h"
... ...
@@ -66,11 +65,16 @@
66 66
 #include "mod.h"
67 67
 
68 68
 #include "../../lib/ims/useful_defs.h"
69
+#include "ims_qos_stats.h"
70
+
71
+
69 72
 #define macro_name(_rc)	#_rc
70 73
 
71 74
 //extern struct tm_binds tmb;
72 75
 usrloc_api_t ul;
73 76
 
77
+extern struct ims_qos_counters_h ims_qos_cnts_h;
78
+
74 79
 extern int authorize_video_flow;
75 80
 
76 81
 str IMS_Serv_AVP_val = {"IMS Services", 12};
... ...
@@ -116,7 +120,7 @@ void async_aar_callback(int is_timeout, void *param, AAAMessage *aaa, long elaps
116 116
 
117 117
     if (is_timeout != 0) {
118 118
         LM_ERR("Error timeout when sending AAR message via CDP\n");
119
-        update_stat(stat_aar_timeouts, 1);
119
+        counter_inc(ims_qos_cnts_h.media_aar_timeouts);
120 120
         goto error;
121 121
     }
122 122
     if (!aaa) {
... ...
@@ -124,8 +128,8 @@ void async_aar_callback(int is_timeout, void *param, AAAMessage *aaa, long elaps
124 124
         goto error;
125 125
     }
126 126
 
127
-    update_stat(aar_replies_received, 1);
128
-    update_stat(aar_replies_response_time, elapsed_msecs);
127
+    counter_inc(ims_qos_cnts_h.media_aars);
128
+    counter_add(ims_qos_cnts_h.media_aar_response_time, elapsed_msecs);
129 129
 
130 130
     /* Process the response to AAR, retrieving result code and associated Rx session ID */
131 131
     if (rx_process_aaa(aaa, &cdp_result) < 0) {
... ...
@@ -135,11 +139,14 @@ void async_aar_callback(int is_timeout, void *param, AAAMessage *aaa, long elaps
135 135
 
136 136
     if (cdp_result >= 2000 && cdp_result < 3000) {
137 137
         LM_DBG("Success, received code: [%i] from PCRF for AAR request\n", cdp_result);
138
+	counter_inc(ims_qos_cnts_h.successful_media_aars);
138 139
 	
139 140
 	LM_DBG("Auth session ID [%.*s]", aaa->sessionId->data.len, aaa->sessionId->data.s);
140 141
 
141 142
 	if(!data->aar_update) {
142 143
 	    LM_DBG("This is an AAA response to an initial AAR");
144
+	    counter_inc(ims_qos_cnts_h.active_media_rx_sessions);
145
+	    
143 146
 	    str * passed_rx_session_id = shm_malloc(sizeof (struct _str));
144 147
 	    passed_rx_session_id->s = 0;
145 148
 	    passed_rx_session_id->len = 0;
... ...
@@ -151,6 +158,7 @@ void async_aar_callback(int is_timeout, void *param, AAAMessage *aaa, long elaps
151 151
         result = CSCF_RETURN_TRUE;
152 152
     } else {
153 153
         LM_DBG("Received negative reply from PCRF for AAR Request\n");
154
+	counter_inc(ims_qos_cnts_h.failed_media_aars);
154 155
         //we don't free rx_authdata_p here - it is free-ed when the CDP session expires
155 156
         goto error; // if its not a success then that means i want to reject this call!
156 157
     }
... ...
@@ -223,7 +231,7 @@ void async_aar_reg_callback(int is_timeout, void *param, AAAMessage *aaa, long e
223 223
 
224 224
     if (is_timeout != 0) {
225 225
         LM_ERR("Error timeout when sending AAR message via CDP\n");
226
-        update_stat(stat_aar_timeouts, 1);
226
+        counter_inc(ims_qos_cnts_h.registration_aar_timeouts);
227 227
         goto error;
228 228
     }
229 229
     if (!aaa) {
... ...
@@ -231,8 +239,8 @@ void async_aar_reg_callback(int is_timeout, void *param, AAAMessage *aaa, long e
231 231
         goto error;
232 232
     }
233 233
 
234
-    update_stat(aar_replies_received, 1);
235
-    update_stat(aar_replies_response_time, elapsed_msecs);
234
+    counter_inc(ims_qos_cnts_h.registration_aars);
235
+    counter_add(ims_qos_cnts_h.registration_aar_response_time, elapsed_msecs);
236 236
 
237 237
     /* Process the response to AAR, retrieving result code and associated Rx session ID */
238 238
     if (rx_process_aaa(aaa, &cdp_result) < 0) {
... ...
@@ -241,7 +249,8 @@ void async_aar_reg_callback(int is_timeout, void *param, AAAMessage *aaa, long e
241 241
     }
242 242
 
243 243
     if (cdp_result >= 2000 && cdp_result < 3000) {
244
-        if (is_rereg) {
244
+        counter_inc(ims_qos_cnts_h.successful_registration_aars);
245
+	if (is_rereg) {
245 246
             LM_DBG("this is a re-registration, therefore we don't need to do anything except know that the the subscription was successful\n");
246 247
             result = CSCF_RETURN_TRUE;
247 248
             create_return_code(result);
... ...
@@ -263,6 +272,8 @@ void async_aar_reg_callback(int is_timeout, void *param, AAAMessage *aaa, long e
263 263
 	    goto error;
264 264
 	}
265 265
 	p_session_data->session_has_been_opened = 1;
266
+	counter_inc(ims_qos_cnts_h.active_registration_rx_sessions);
267
+	
266 268
 	if (auth) cdpb.AAASessionsUnlock(auth->hash);
267 269
 	
268 270
 	
... ...
@@ -300,6 +311,7 @@ void async_aar_reg_callback(int is_timeout, void *param, AAAMessage *aaa, long e
300 300
         result = CSCF_RETURN_TRUE;
301 301
     } else {
302 302
         LM_DBG("Received negative reply from PCRF for AAR Request\n");
303
+	counter_inc(ims_qos_cnts_h.failed_registration_aars);
303 304
         result = CSCF_RETURN_FALSE;
304 305
         goto error;
305 306
     }
... ...
@@ -60,6 +60,9 @@
60 60
 #include "rx_asr.h"
61 61
 #include "rx_avp.h"
62 62
 #include "../../lib/ims/ims_getters.h"
63
+#include "ims_qos_stats.h"
64
+
65
+extern struct ims_qos_counters_h ims_qos_cnts_h;
63 66
 
64 67
 /*
65 68
  * Called upon receipt of an ASR. Terminates the user session and returns the ASA.
... ...
@@ -76,13 +79,15 @@ AAAMessage* rx_process_asr(AAAMessage *request) {
76 76
 
77 77
     if (!request || !request->sessionId) return 0;
78 78
 
79
+    counter_inc(ims_qos_cnts_h.asrs);
80
+    
79 81
     session = cdpb.AAAGetAuthSession(request->sessionId->data);
80 82
 
81 83
     if (!session) {
82 84
         LM_DBG("received an ASR but the session is already deleted\n");
83 85
         return 0;
84 86
     }
85
-
87
+    
86 88
     code = rx_get_abort_cause(request);
87 89
     LM_DBG("abort-cause code is %u\n", code);
88 90