add heartbeat event and core uuid
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4347 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
4dd3e158a0
commit
a88da36253
|
@ -477,6 +477,12 @@ SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session
|
|||
*/
|
||||
SWITCH_DECLARE(char *) switch_core_session_get_uuid(switch_core_session_t *session);
|
||||
|
||||
/*!
|
||||
\brief Retrieve the unique identifier from the core
|
||||
\return a string representing the uuid
|
||||
*/
|
||||
SWITCH_DECLARE(char *) switch_core_get_uuid(void);
|
||||
|
||||
#ifdef SWITCH_DEBUG_RWLOCKS
|
||||
SWITCH_DECLARE(switch_core_session_t *) switch_core_session_perform_locate(char *uuid_str,
|
||||
const char *file,
|
||||
|
|
|
@ -747,6 +747,7 @@ typedef enum {
|
|||
SWITCH_EVENT_BACKGROUND_JOB - Background Job
|
||||
SWITCH_EVENT_DETECTED_SPEECH - Detected Speech
|
||||
SWITCH_EVENT_PRIVATE_COMMAND - A private command event
|
||||
SWITCH_EVENT_HEARTBEAT - Machine is alive
|
||||
SWITCH_EVENT_ALL - All events at once
|
||||
</pre>
|
||||
|
||||
|
@ -787,6 +788,7 @@ typedef enum {
|
|||
SWITCH_EVENT_BACKGROUND_JOB,
|
||||
SWITCH_EVENT_DETECTED_SPEECH,
|
||||
SWITCH_EVENT_PRIVATE_COMMAND,
|
||||
SWITCH_EVENT_HEARTBEAT,
|
||||
SWITCH_EVENT_ALL
|
||||
} switch_event_types_t;
|
||||
|
||||
|
|
|
@ -145,6 +145,7 @@ struct switch_core_runtime {
|
|||
uint32_t no_new_sessions;
|
||||
uint32_t shutting_down;
|
||||
uint8_t running;
|
||||
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
||||
};
|
||||
|
||||
/* Prototypes */
|
||||
|
@ -748,6 +749,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_event_send(char *uuid_str, s
|
|||
return status;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(char *) switch_core_get_uuid(void)
|
||||
{
|
||||
return runtime.uuid_str;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(char *) switch_core_session_get_uuid(switch_core_session_t *session)
|
||||
{
|
||||
return session->uuid_str;
|
||||
|
@ -3808,7 +3814,7 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
|
|||
void *pop;
|
||||
uint32_t itterations = 0;
|
||||
uint8_t trans = 0, nothing_in_queue = 0;
|
||||
uint32_t freq = 1000, target = 1000;
|
||||
uint32_t target = 1000;
|
||||
switch_size_t len = 0, sql_len = SQLLEN;
|
||||
const char *begin_sql = "BEGIN DEFERRED TRANSACTION CORE1;\n";
|
||||
char *end_sql = "END TRANSACTION CORE1";
|
||||
|
@ -3817,13 +3823,15 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
|
|||
char *sqlbuf = (char *) malloc(sql_len);
|
||||
char *sql;
|
||||
switch_size_t newlen;
|
||||
|
||||
uint32_t loops = 0;
|
||||
|
||||
if (!runtime.event_db) {
|
||||
runtime.event_db = switch_core_db_handle();
|
||||
}
|
||||
switch_queue_create(&runtime.sql_queue, SWITCH_SQL_QUEUE_LEN, runtime.memory_pool);
|
||||
|
||||
|
||||
|
||||
for(;;) {
|
||||
if (switch_queue_trypop(runtime.sql_queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
||||
sql = (char *) pop;
|
||||
|
@ -3873,10 +3881,42 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
|
|||
len = 0;
|
||||
*sqlbuf = '\0';
|
||||
}
|
||||
|
||||
if (loops++ >= 5000) {
|
||||
switch_event_t *event;
|
||||
switch_core_time_duration_t duration;
|
||||
|
||||
switch_core_measure_time(switch_core_uptime(), &duration);
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_HEARTBEAT) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Ready");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Up-Time",
|
||||
"%u year%s, "
|
||||
"%u day%s, "
|
||||
"%u hour%s, "
|
||||
"%u minute%s, "
|
||||
"%u second%s, "
|
||||
"%u millisecond%s, "
|
||||
"%u microsecond%s\n",
|
||||
duration.yr, duration.yr == 1 ? "" : "s",
|
||||
duration.day, duration.day == 1 ? "" : "s",
|
||||
duration.hr, duration.hr == 1 ? "" : "s",
|
||||
duration.min, duration.min == 1 ? "" : "s",
|
||||
duration.sec, duration.sec == 1 ? "" : "s",
|
||||
duration.ms, duration.ms == 1 ? "" : "s",
|
||||
duration.mms, duration.mms == 1 ? "" : "s"
|
||||
);
|
||||
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Count", "%u", switch_core_session_count());
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
|
||||
loops = 0;
|
||||
}
|
||||
|
||||
if (nothing_in_queue) {
|
||||
switch_yield(freq);
|
||||
}
|
||||
switch_yield(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -4130,6 +4170,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(char *console, const char **err
|
|||
switch_xml_t xml = NULL, cfg = NULL;
|
||||
memset(&runtime, 0, sizeof(runtime));
|
||||
runtime.session_limit = 1000;
|
||||
switch_uuid_t uuid;
|
||||
|
||||
switch_core_set_globals();
|
||||
|
||||
|
@ -4276,6 +4317,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(char *console, const char **err
|
|||
switch_core_hash_init(&runtime.stack_table, runtime.memory_pool);
|
||||
#endif
|
||||
runtime.initiated = switch_time_now();
|
||||
|
||||
|
||||
switch_uuid_get(&uuid);
|
||||
switch_uuid_format(runtime.uuid_str, &uuid);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -131,6 +131,7 @@ static char *EVENT_NAMES[] = {
|
|||
"BACKGROUND_JOB",
|
||||
"DETECTED_SPEECH",
|
||||
"PRIVATE_COMMAND",
|
||||
"HEARTBEAT",
|
||||
"ALL"
|
||||
};
|
||||
|
||||
|
@ -811,21 +812,21 @@ SWITCH_DECLARE(switch_status_t) switch_event_fire_detailed(char *file, char *fun
|
|||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-Line-Number", "%d", line);
|
||||
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-Function", "%s", func);
|
||||
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-File", "%s", switch_cut_path(file));
|
||||
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Name", "%s", switch_event_name((*event)->event_id));
|
||||
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Core-UUID", "%s", switch_core_get_uuid());
|
||||
switch_time_exp_lt(&tm, switch_time_now());
|
||||
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
|
||||
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Date-Local", "%s", date);
|
||||
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Date-Local", "%s", date);
|
||||
switch_rfc822_date(date, switch_time_now());
|
||||
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Date-GMT", "%s", date);
|
||||
if ((*event)->subclass) {
|
||||
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Subclass", "%s", (*event)->subclass->name);
|
||||
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Subclass-Owner", "%s", (*event)->subclass->owner);
|
||||
}
|
||||
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Name", "%s", switch_event_name((*event)->event_id));
|
||||
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Date-GMT", "%s", date);
|
||||
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-File", "%s", switch_cut_path(file));
|
||||
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Function", "%s", func);
|
||||
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Line-Number", "%d", line);
|
||||
|
||||
if ((*event)->subclass) {
|
||||
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Subclass", "%s", (*event)->subclass->name);
|
||||
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Subclass-Owner", "%s", (*event)->subclass->owner);
|
||||
}
|
||||
|
||||
if (user_data) {
|
||||
(*event)->event_user_data = user_data;
|
||||
|
|
Loading…
Reference in New Issue