]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Add uptime property to mod_sofia gateways
authorSteven Ayre <steven.ayre@voxygen.co.uk>
Wed, 3 Sep 2014 20:44:11 +0000 (21:44 +0100)
committerTravis Cross <tc@traviscross.com>
Thu, 4 Sep 2014 03:43:36 +0000 (03:43 +0000)
The 'UP' status indicates a gateway is online as determined by
registration and/or SIP OPTIONS pinging.

The time the gateway has been in the 'UP' status is recorded,
and can be monitored using 'sofia status' and 'sofia xmlstatus'.

This can be used to detect and graph when there are outages.

ref: FS-6772

Reviewed-by: Travis Cross <tc@traviscross.com>
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index 33f4e0f855a0b2934f07a4ad27e92f7de4a54726..5f656b762cb5b36446ebf69405990f88153102f0 100644 (file)
@@ -2584,6 +2584,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
                                stream->write_function(stream, "PingState\t%d/%d/%d\n", gp->ping_min, gp->ping_count, gp->ping_max);
                                stream->write_function(stream, "State   \t%s\n", sofia_state_names[gp->state]);
                                stream->write_function(stream, "Status  \t%s%s\n", status_names[gp->status], gp->pinging ? " (ping)" : "");
+                               stream->write_function(stream, "Uptime  \t%ld\n", gp->status == SOFIA_GATEWAY_UP ? switch_time_now()-gp->uptime : 0);
                                stream->write_function(stream, "CallsIN \t%u\n", gp->ib_calls);
                                stream->write_function(stream, "CallsOUT\t%u\n", gp->ob_calls);
                                stream->write_function(stream, "FailedCallsIN\t%u\n", gp->ib_failed_calls);
@@ -2827,6 +2828,7 @@ static void xml_gateway_status(sofia_gateway_t *gp, switch_stream_handle_t *stre
        stream->write_function(stream, "    <pinging>%d</pinging>\n", gp->pinging);
        stream->write_function(stream, "    <state>%s</state>\n", sofia_state_names[gp->state]);
        stream->write_function(stream, "    <status>%s</status>\n", status_names[gp->status]);
+       stream->write_function(stream, "    <uptime>%ld</uptime>\n", gp->status == SOFIA_GATEWAY_UP ? switch_time_now()-gp->uptime : 0);
        stream->write_function(stream, "    <calls-in>%u</calls-in>\n", gp->ib_calls);
        stream->write_function(stream, "    <calls-out>%u</calls-out>\n", gp->ob_calls);
        stream->write_function(stream, "    <failed-calls-in>%u</failed-calls-in>\n", gp->ib_failed_calls);
index 577ff07bbc8282f4f431412f3daef90a746b89b8..4be1d9747ac33ca4e0bd517c4dbd19283b324196 100644 (file)
@@ -488,6 +488,7 @@ struct sofia_gateway {
        time_t reg_timeout;
        int pinging;
        sofia_gateway_status_t status;
+       switch_time_t uptime;
        uint32_t ping_freq;
        int ping_count;
        int ping_max;
index edc15cf69bef0f4b4affc49478bf9122433634b5..390a289d94ecd34a631d7f97998a02f8dda65084 100644 (file)
@@ -3487,6 +3487,7 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
                        if (!switch_true(register_str)) {
                                gateway->state = REG_STATE_NOREG;
                                gateway->status = SOFIA_GATEWAY_UP;
+                               gateway->uptime = switch_time_now();
                        }
 
                        if (zstr(auth_username)) {
@@ -5563,6 +5564,7 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu
 
                                if (gateway->ping_count >= gateway->ping_min && gateway->status != SOFIA_GATEWAY_UP) {
                                        gateway->status = SOFIA_GATEWAY_UP;
+                                       gateway->uptime = switch_time_now();
                                        sofia_reg_fire_custom_gateway_state_event(gateway, status, phrase);
                                }
 
index 206b77283b36b89d78e21e938a7ee1387afc1bf3..053ddd9a9e2f3454837a2153afa70c41ac8ec7c0 100644 (file)
@@ -372,8 +372,9 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
 
                switch (ostate) {
                case REG_STATE_NOREG:
-                       if (!gateway_ptr->ping && !gateway_ptr->pinging) {
+                       if (!gateway_ptr->ping && !gateway_ptr->pinging && gateway_ptr->status != SOFIA_GATEWAY_UP) {
                                gateway_ptr->status = SOFIA_GATEWAY_UP;
+                               gateway_ptr->uptime = switch_time_now();
                        }
                        break;
                case REG_STATE_REGISTER:
@@ -396,7 +397,10 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
                        gateway_ptr->expires = now + delta;
 
                        gateway_ptr->state = REG_STATE_REGED;
-                       gateway_ptr->status = SOFIA_GATEWAY_UP;
+                       if (gateway_ptr->status != SOFIA_GATEWAY_UP) {
+                               gateway_ptr->status = SOFIA_GATEWAY_UP;
+                               gateway_ptr->uptime = switch_time_now();
+                       }
                        break;
 
                case REG_STATE_UNREGISTER: