]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add peak sps to stats and a command to reset it
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 19 Jul 2013 20:16:42 +0000 (15:16 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 19 Jul 2013 20:16:42 +0000 (15:16 -0500)
src/include/private/switch_core_pvt.h
src/include/switch_types.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/event_handlers/mod_snmp/subagent.c
src/mod/event_handlers/mod_snmp/subagent.h
src/switch_core.c
src/switch_time.c

index 5cf7196382f64b1ff5db607c44f9e34ca67720ff..8ba0ebbca802d0ee69b4b02e0cafc58c8677da21 100644 (file)
@@ -240,6 +240,7 @@ struct switch_runtime {
        uint32_t sps_total;
        int32_t sps;
        int32_t sps_last;
+       int32_t sps_peak;
        switch_log_level_t hard_log_level;
        char *mailer_app;
        char *mailer_app_args;
index 315c0b2fdf940f5b1d3bc378158048fc12f1634a..034c4c1cd3fe709265a82800a6e1bcca4ba9e8a7 100644 (file)
@@ -1887,7 +1887,8 @@ typedef enum {
        SCSC_DEBUG_SQL,
        SCSC_SQL,
        SCSC_API_EXPANSION,
-       SCSC_RECOVER
+       SCSC_RECOVER,
+       SCSC_SPS_PEAK
 } switch_session_ctl_t;
 
 typedef enum {
index 183732835664db05bddbdf0ab90562677553d22b..2c6195c43144b575e77fb7092d554f45698c52c1 100644 (file)
@@ -2012,7 +2012,7 @@ SWITCH_STANDARD_API(lan_addr_function)
 SWITCH_STANDARD_API(status_function)
 {
        switch_core_time_duration_t duration = { 0 };
-       int sps = 0, last_sps = 0;
+       int sps = 0, last_sps = 0, max_sps = 0;
        switch_bool_t html = SWITCH_FALSE;      /* shortcut to format.html      */
        char * nl = "\n";                                       /* shortcut to format.nl        */
        stream_format format = { 0 };
@@ -2058,7 +2058,8 @@ SWITCH_STANDARD_API(status_function)
        stream->write_function(stream, "%" SWITCH_SIZE_T_FMT " session(s) since startup%s", switch_core_session_id() - 1, nl);
        switch_core_session_ctl(SCSC_LAST_SPS, &last_sps);
        switch_core_session_ctl(SCSC_SPS, &sps);
-       stream->write_function(stream, "%d session(s) - %d out of max %d per sec %s", switch_core_session_count(), last_sps, sps, nl);
+       switch_core_session_ctl(SCSC_SPS_PEAK, &max_sps);
+       stream->write_function(stream, "%d session(s) - %d out of max %d per sec peak %d %s", switch_core_session_count(), last_sps, sps, max_sps, nl);
        stream->write_function(stream, "%d session(s) max%s", switch_core_session_limit(0), nl);
        stream->write_function(stream, "min idle cpu %0.2f/%0.2f%s", switch_core_min_idle_cpu(-1.0), switch_core_idle_cpu(), nl);
 
@@ -2067,7 +2068,7 @@ SWITCH_STANDARD_API(status_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
-#define CTL_SYNTAX "[recover|send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]"
+#define CTL_SYNTAX "[recover|send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sps_peak_reset|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]"
 SWITCH_STANDARD_API(ctl_function)
 {
        int argc;
@@ -2289,6 +2290,10 @@ SWITCH_STANDARD_API(ctl_function)
                        switch_core_session_ctl(SCSC_DEBUG_LEVEL, &arg);
                        stream->write_function(stream, "+OK DEBUG level: %d\n", arg);
 
+               } else if (!strcasecmp(argv[0], "sps_peak_reset")) {
+                       arg = -1;
+                       switch_core_session_ctl(SCSC_SPS_PEAK, &arg);
+                       stream->write_function(stream, "+OK max sessions per second counter reset\n");
                } else if (!strcasecmp(argv[0], "last_sps")) {
                        switch_core_session_ctl(SCSC_LAST_SPS, &arg);
                        stream->write_function(stream, "+OK last sessions per second: %d\n", arg);
index 3232f026c65886c6c3b76fdf4b3819384694c058..0a6771c137b8123b3a2b6419e125a3ab328b54af 100644 (file)
@@ -257,6 +257,10 @@ int handle_systemStats(netsnmp_mib_handler *handler, netsnmp_handler_registratio
                        switch_core_session_ctl(SCSC_SPS, &int_val);
                        snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
                        break;
+               case SS_PEAK_SESSIONS_PER_SECOND:
+                       switch_core_session_ctl(SCSC_SPS_PEAK, &int_val);
+                       snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
+                       break;
                default:
                        snmp_log(LOG_WARNING, "Unregistered OID-suffix requested (%d)\n", (int) subid);
                        netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
index 47a982ce4f2e8a364a9b1d9f7de7b96146f88b39..60bd7e5735d67a95f4d626bc144f3843608215d7 100644 (file)
@@ -46,6 +46,7 @@
 #define SS_CURRENT_CALLS               5
 #define SS_SESSIONS_PER_SECOND         6
 #define SS_MAX_SESSIONS_PER_SECOND     7
+#define SS_PEAK_SESSIONS_PER_SECOND    8
 
 /* .1.3.6.1.4.1.27880.1.9 */
 #define CH_INDEX                       1
index 1164c42c8d160a6c558631ccc9a418b55e9d1075..151915c2b0fe4322c1d8f855d4f3457db91349e2 100644 (file)
@@ -88,6 +88,7 @@ static void send_heartbeat(void)
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Count", "%u", switch_core_session_count());
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Max-Sessions", "%u", switch_core_session_limit(0));
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Per-Sec", "%u", runtime.sps);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Per-Sec-Max", "%u", runtime.sps_peak);
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Since-Startup", "%" SWITCH_SIZE_T_FMT, switch_core_session_id() - 1);
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Idle-CPU", "%f", switch_core_idle_cpu());
                switch_event_fire(&event);
@@ -2477,6 +2478,12 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
        case SCSC_LAST_SPS:
                newintval = runtime.sps_last;
                break;
+       case SCSC_SPS_PEAK:
+               if (oldintval == -1) {
+                       runtime.sps_peak = 0;
+               }
+               newintval = runtime.sps_peak;
+               break;
        case SCSC_MAX_DTMF_DURATION:
                newintval = switch_core_max_dtmf_duration(oldintval);
                break;
index c5f07af68791f0c3875898325b624b5fde60386f..1c25b11e6936d32b46b0127fb9f707254229a18c 100644 (file)
@@ -1008,6 +1008,10 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
                        }
                        switch_mutex_lock(runtime.throttle_mutex);
                        runtime.sps_last = runtime.sps_total - runtime.sps;
+
+                       if (runtime.sps_last > runtime.sps_peak) {
+                               runtime.sps_peak = runtime.sps_last;
+                       }
                        runtime.sps = runtime.sps_total;
                        switch_mutex_unlock(runtime.throttle_mutex);
                        tick = 0;