add peak sps to stats and a command to reset it

This commit is contained in:
Anthony Minessale 2013-07-19 15:16:42 -05:00
parent 4e74ef3914
commit 578361bea3
7 changed files with 27 additions and 4 deletions

View File

@ -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;

View File

@ -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 {

View 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);

View 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);

View 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

View 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);
@ -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;

View 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;