diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index 8ba0ebbca8..2b9cf628e7 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -241,6 +241,7 @@ struct switch_runtime { int32_t sps; int32_t sps_last; int32_t sps_peak; + int32_t sps_peak_fivemin; 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 034c4c1cd3..3554d213c0 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1888,7 +1888,8 @@ typedef enum { SCSC_SQL, SCSC_API_EXPANSION, SCSC_RECOVER, - SCSC_SPS_PEAK + SCSC_SPS_PEAK, + SCSC_SPS_PEAK_FIVEMIN } 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 2c6195c431..627d812738 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, max_sps = 0; + int sps = 0, last_sps = 0, max_sps = 0, max_sps_fivemin = 0; switch_bool_t html = SWITCH_FALSE; /* shortcut to format.html */ char * nl = "\n"; /* shortcut to format.nl */ stream_format format = { 0 }; @@ -2059,7 +2059,8 @@ SWITCH_STANDARD_API(status_function) switch_core_session_ctl(SCSC_LAST_SPS, &last_sps); switch_core_session_ctl(SCSC_SPS, &sps); 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); + switch_core_session_ctl(SCSC_SPS_PEAK_FIVEMIN, &max_sps_fivemin); + stream->write_function(stream, "%d session(s) - %d out of max %d per sec peak %d (%d last 5min) %s", switch_core_session_count(), last_sps, sps, max_sps, max_sps_fivemin, 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); diff --git a/src/mod/event_handlers/mod_snmp/FREESWITCH-MIB b/src/mod/event_handlers/mod_snmp/FREESWITCH-MIB index b68f3e537e..6b5aeace95 100644 --- a/src/mod/event_handlers/mod_snmp/FREESWITCH-MIB +++ b/src/mod/event_handlers/mod_snmp/FREESWITCH-MIB @@ -146,9 +146,17 @@ peakSessionsPerSecond OBJECT-TYPE MAX-ACCESS read-only STATUS current DESCRIPTION - "Maximum sessions per second" + "Peak sessions per second" ::= { systemStats 8 } +peakSessionsPerSecond OBJECT-TYPE + SYNTAX Gauge32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "Peak sessions per second last 5 minutes" + ::= { systemStats 9 } + ChannelEntry ::= SEQUENCE { chanIndex Integer32, diff --git a/src/mod/event_handlers/mod_snmp/subagent.c b/src/mod/event_handlers/mod_snmp/subagent.c index 179dda11e7..f9bd4610d6 100644 --- a/src/mod/event_handlers/mod_snmp/subagent.c +++ b/src/mod/event_handlers/mod_snmp/subagent.c @@ -158,7 +158,7 @@ void init_subagent(switch_memory_pool_t *pool) DEBUGMSGTL(("init_subagent", "mod_snmp subagent initializing\n")); netsnmp_register_scalar_group(netsnmp_create_handler_registration("identity", handle_identity, identity_oid, OID_LENGTH(identity_oid), HANDLER_CAN_RONLY), 1, 2); - netsnmp_register_scalar_group(netsnmp_create_handler_registration("systemStats", handle_systemStats, systemStats_oid, OID_LENGTH(systemStats_oid), HANDLER_CAN_RONLY), 1, 8); + netsnmp_register_scalar_group(netsnmp_create_handler_registration("systemStats", handle_systemStats, systemStats_oid, OID_LENGTH(systemStats_oid), HANDLER_CAN_RONLY), 1, 9); ch_table_info = switch_core_alloc(pool, sizeof(netsnmp_table_registration_info)); netsnmp_table_helper_add_indexes(ch_table_info, ASN_INTEGER, 0); @@ -216,6 +216,7 @@ int handle_systemStats(netsnmp_mib_handler *handler, netsnmp_handler_registratio switch(reqinfo->mode) { case MODE_GET: subid = requests->requestvb->name[reginfo->rootoid_len - 2]; + snmp_log(LOG_DEBUG, "systemStats OID-suffix requested (%d)\n", (int) subid); switch (subid) { case SS_UPTIME: @@ -261,6 +262,10 @@ int handle_systemStats(netsnmp_mib_handler *handler, netsnmp_handler_registratio switch_core_session_ctl(SCSC_SPS_PEAK, &int_val); snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val); break; + case SS_PEAK_SESSIONS_PER_FIVEMIN: + switch_core_session_ctl(SCSC_SPS_PEAK_FIVEMIN, &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 60bd7e5735..2cf5d3f964 100644 --- a/src/mod/event_handlers/mod_snmp/subagent.h +++ b/src/mod/event_handlers/mod_snmp/subagent.h @@ -47,6 +47,7 @@ #define SS_SESSIONS_PER_SECOND 6 #define SS_MAX_SESSIONS_PER_SECOND 7 #define SS_PEAK_SESSIONS_PER_SECOND 8 +#define SS_PEAK_SESSIONS_PER_FIVEMIN 9 /* .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 151915c2b0..5964fa3019 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -89,6 +89,7 @@ static void send_heartbeat(void) 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-Per-Sec-FiveMin", "%u", runtime.sps_peak_fivemin); 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); @@ -2484,6 +2485,9 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void * } newintval = runtime.sps_peak; break; + case SCSC_SPS_PEAK_FIVEMIN: + newintval = runtime.sps_peak_fivemin; + 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 1c25b11e69..d1c5926c8c 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -802,7 +802,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime) { switch_time_t too_late = runtime.microseconds_per_tick * 1000; uint32_t current_ms = 0; - uint32_t x, tick = 0; + uint32_t x, tick = 0, sps_interval_ticks = 0; switch_time_t ts = 0, last = 0; int fwd_errs = 0, rev_errs = 0; int profile_tick = 0; @@ -1009,6 +1009,16 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime) switch_mutex_lock(runtime.throttle_mutex); runtime.sps_last = runtime.sps_total - runtime.sps; + if (sps_interval_ticks >= 300) { + runtime.sps_peak_fivemin = 0; + sps_interval_ticks = 0; + } + sps_interval_ticks++; + + if (runtime.sps_last > runtime.sps_peak_fivemin) { + runtime.sps_peak_fivemin = runtime.sps_last; + } + if (runtime.sps_last > runtime.sps_peak) { runtime.sps_peak = runtime.sps_last; }