sms-rate-refresh feature

"Rafael Alfaro" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hello Everybody,

I did this patch with the following purpose:
Provide the bearerbox status web page with an online incoming and
outgoing sms rate display (msg/sec).

For example, if you take a look to the current bearerbox status web
page, you will see that the sms rate is the average since the
bearerbox is online, because the current code is:

        (float) counter_value(incoming_sms_counter)/t,
        (float) counter_value(outgoing_sms_counter)/t,

So, I added a new feature to the core group cfg: "sms-rate-refresh".
This will launch a thread that will be sampling the
"counter_value(incoming_sms_counter)" and
"counter_value(outgoing_sms_counter)" every "sms_rate_refresh"
seconds, and with this information we can calculate the current sms
rate (msg/sec).

If the "sms-rate-refresh" feature is not used at the configuration
file, by default, the average since bearerbox is online will be
displayed (like right now is coded).

Best Regards,
-- 
Rafael Alfaro.
 VAP O&M Engineer
 Telemovil El Salvador
 Centro Financiero Gigante, Torre "D", Piso 9
 San Salvador, El Salvador
 Mobile: +503 78889841
 NOC: +503 22809447
 Fax: +503 22809450
gateway-rate-refresh.patch (text/x-patch, 3.3 KB)
diff -urN gateway/gw/bearerbox.c gateway-patched/gw/bearerbox.c
--- gateway/gw/bearerbox.c	2008-01-09 14:06:57.000000000 -0600
+++ gateway-patched/gw/bearerbox.c	2008-03-23 20:30:26.000000000 -0600
@@ -95,6 +95,13 @@
 long max_incoming_sms_qlength;
 long max_outgoing_sms_qlength;
 
+/*sms rate refresh control*/
+long sms_rate_refresh;
+
+/*sms rate variables*/
+float outgoing_sms_rate;
+float incoming_sms_rate;
+
 
 /* this is not a list of items; instead it is used as
  * indicator to note how many threads we have.
@@ -372,6 +379,8 @@
         log_open(octstr_get_cstr(log), loglevel, GW_NON_EXCL);
         octstr_destroy(log);
     }
+    if (cfg_get_integer(&sms_rate_refresh, grp, octstr_imm("sms-rate-refresh")) == -1)
+        sms_rate_refresh = -1;
 
     if (check_config(cfg) == -1)
         panic(0, "Cannot start with corrupted configuration");
@@ -567,6 +576,19 @@
     }
 }
 
+static void sms_rate_refresh_thread(void *arg)
+{
+
+    gwthread_sleep(1);
+    while (1) {
+        int prev_outgoing_sms_counter = (int)counter_value(outgoing_sms_counter);
+        int prev_incoming_sms_counter = (int)counter_value(incoming_sms_counter);
+        gwthread_sleep(sms_rate_refresh);
+        outgoing_sms_rate = (float)(((float)counter_value(outgoing_sms_counter) - (float)prev_outgoing_sms_counter) / (float)sms_rate_refresh);
+        incoming_sms_rate = (float)(((float)counter_value(incoming_sms_counter) - (float)prev_incoming_sms_counter) / (float)sms_rate_refresh);
+    }
+
+}
 
 int main(int argc, char **argv)
 {
@@ -574,6 +596,8 @@
     Cfg *cfg;
     Octstr *filename;
 
+    long t_sms_rate_refresh;
+
     bb_status = BB_RUNNING;
     
     gwlib_init();
@@ -624,7 +648,10 @@
         gwlist_remove_producer(suspended);	
         gwlist_remove_producer(isolated);
     }
-
+    if (sms_rate_refresh != -1) {
+        t_sms_rate_refresh = gwthread_create(sms_rate_refresh_thread, NULL);
+        gwthread_wakeup(t_sms_rate_refresh);
+    }
     while (bb_status != BB_SHUTDOWN && bb_status != BB_DEAD && 
            gwlist_producer_count(flow_threads) > 0) {
         /* debug("bb", 0, "Main Thread: going to sleep."); */
@@ -824,7 +851,10 @@
         return octstr_create("Un-supported format");
 
     t = time(NULL) - start_time;
-    
+    if (sms_rate_refresh == -1) {
+        incoming_sms_rate = (float)counter_value(incoming_sms_counter) / t;
+        outgoing_sms_rate = (float)counter_value(outgoing_sms_counter) / t;
+    }    
     if (bb_status == BB_RUNNING)
         s = "running";
     else if (bb_status == BB_ISOLATED)
@@ -891,8 +921,8 @@
         counter_value(incoming_sms_counter), gwlist_len(incoming_sms),
         counter_value(outgoing_sms_counter), gwlist_len(outgoing_sms),
         store_messages(),
-        (float) counter_value(incoming_sms_counter)/t,
-        (float) counter_value(outgoing_sms_counter)/t,
+        incoming_sms_rate,
+        outgoing_sms_rate,
         dlr_messages(), dlr_type());
 
     octstr_destroy(version);
diff -urN gateway/gwlib/cfg.def gateway-patched/gwlib/cfg.def
--- gateway/gwlib/cfg.def	2008-03-16 05:38:16.000000000 -0600
+++ gateway-patched/gwlib/cfg.def	2008-03-23 19:43:54.000000000 -0600
@@ -126,6 +126,8 @@
     OCTSTR(sms-resend-retry)
     OCTSTR(sms-combine-concatenated-mo)
     OCTSTR(sms-combine-concatenated-mo-timeout)
+    OCTSTR(sms-rate-refresh)
+
 )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.