diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index 5dba69cb7d..328443048c 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -238,6 +238,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; diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 9e17785645..be9116a5d0 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1861,7 +1861,8 @@ typedef enum { SCSC_DEBUG_SQL, SCSC_SQL, SCSC_API_EXPANSION, - SCSC_RECOVER + SCSC_RECOVER, + SCSC_SPS_PEAK } switch_session_ctl_t; typedef enum { diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 1837328356..2c6195c431 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -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); diff --git a/src/mod/event_handlers/mod_snmp/subagent.c b/src/mod/event_handlers/mod_snmp/subagent.c index 3232f026c6..0a6771c137 100644 --- a/src/mod/event_handlers/mod_snmp/subagent.c +++ b/src/mod/event_handlers/mod_snmp/subagent.c @@ -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); diff --git a/src/mod/event_handlers/mod_snmp/subagent.h b/src/mod/event_handlers/mod_snmp/subagent.h index 47a982ce4f..60bd7e5735 100644 --- a/src/mod/event_handlers/mod_snmp/subagent.h +++ b/src/mod/event_handlers/mod_snmp/subagent.h @@ -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 diff --git a/src/switch_core.c b/src/switch_core.c index bf23033458..de6fda4bb7 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -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); @@ -2464,6 +2465,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; diff --git a/src/switch_time.c b/src/switch_time.c index c5f07af687..1c25b11e69 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -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;