/****** uti/sge_log/sge_do_log() *********************************************** * NAME * sge_do_log() -- Write message to log file * * SYNOPSIS * static void sge_do_log(int aLevel, const char *aMessage, const char * * FUNCTION * ??? * * INPUTS * int aLevel - log level * const char *aMessage - log message * * RESULT * void - none * * NOTES * MT-NOTE: sge_do_log() is MT safe. * *******************************************************************************/ static void sge_do_log(u_long32 me, const char* progname, const char* unqualified_hostname, int aLevel, const char *aMessage) { int fd; if (me == QMASTER || me == EXECD || me == SCHEDD || me == SHADOWD) { if ((fd = SGE_OPEN3(log_state_get_log_file(), O_WRONLY | O_APPEND | O_CREAT, 0666)) >= 0) { char msg2log[4*MAX_STRING_SIZE]; dstring msg; int len; sge_dstring_init(&msg, msg2log, sizeof(msg2log)); append_time((time_t)sge_get_gmt(), &msg, false); sge_dstring_sprintf_append(&msg, "|%6.6s|%s|%c|%s\n", progname, unqualified_hostname, aLevel, aMessage); len = strlen(msg2log); if (write(fd, msg2log, len) != len) { /* we are in error logging here - the only chance to log this problem * might be to write it to stderr */ fprintf(stderr, "can't log to file %s: %s\n", log_state_get_log_file(), sge_strerror(errno, &msg)); } close(fd); } } return; } /* sge_do_log() */
/****** uti/sge_log/sge_do_log() *********************************************** * NAME * sge_do_log() -- Write message to log file * * SYNOPSIS * static void sge_do_log(int aLevel, const char *aMessage, const char * * FUNCTION * ??? * * INPUTS * int aLevel - log level * const char *aMessage - log message * * RESULT * void - none * * NOTES * MT-NOTE: sge_do_log() is MT safe. * *******************************************************************************/ static void sge_do_log(u_long32 me, const char* progname, const char* unqualified_hostname, int aLevel, const char *aMessage) { int fd; if (me == QMASTER || me == EXECD || me == SCHEDD || me == SHADOWD) { if ((fd = SGE_OPEN3(log_state_get_log_file(), O_WRONLY | O_APPEND | O_CREAT, 0666)) >= 0) { char msg2log[4*MAX_STRING_SIZE]; dstring msg; sge_dstring_init(&msg, msg2log, sizeof(msg2log)); append_time((time_t)sge_get_gmt(), &msg, false); sge_dstring_sprintf_append(&msg, "|%6.6s|%s|%c|%s\n", progname, unqualified_hostname, aLevel, aMessage); write(fd, msg2log, strlen(msg2log)); close(fd); } } return; } /* sge_do_log() */
/****** uti/monitor/sge_monitor_status() *************************************** * NAME * sge_monitor_status() -- generates the status for qping / commlib * * SYNOPSIS * u_long32 sge_monitor_status(char **info_message, u_long32 monitor_time) * * FUNCTION * This method creats the health monitoring output and returns the monitoring * info to the commlib. * * INPUTS * char **info_message - info_message pointer, has to point to a NULL string * u_long32 monitor_time - the configured monitoring interval * * RESULT * u_long32 - 0 : everything is okay * 1 : warning * 2 : error * 3 : init problems * * NOTES * MT-NOTE: sge_monitor_status() is MT safe * *******************************************************************************/ u_long32 sge_monitor_status(char **info_message, u_long32 monitor_time) { u_long32 ret = 0; char date[40]; dstring ddate; DENTER(GDI_LAYER, "sge_monitor_status"); if (info_message == NULL) { DEXIT; return 3; } sge_dstring_init(&ddate, date, sizeof(date)); sge_mutex_lock("sge_monitor_status", SGE_FUNC, __LINE__, &global_mutex); sge_dstring_clear(&Info_Line); {/* this is the qping info section, it checks if each thread is still alive */ int i; int error_count = 0; struct timeval now; double time; char state = 'R'; gettimeofday(&now,NULL); for (i = 0; i < MAX_OUTPUT_LINES; i++) { sge_mutex_lock("sge_monitor_status", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex)); if (Output[i].name != NULL) { time = now.tv_usec - Output[i].last_wait_time.tv_usec; time = now.tv_sec - Output[i].last_wait_time.tv_sec + (time /1000000); if (Output[i].warning_timeout != NO_WARNING) { if (Output[i].warning_timeout < time) { if (Output[i].error_timeout < time) { state = 'E'; } else { state = 'W'; } error_count++; } } sge_dstring_sprintf_append(&Info_Line, MSG_UTI_MONITOR_INFO_SCF, Output[i].name, state, time); } sge_mutex_unlock("sge_monitor_status", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex)); } if (error_count == 0) { sge_dstring_append(&Info_Line, MSG_UTI_MONITOR_OK); } else if (error_count == 1) { ret = 1; sge_dstring_append(&Info_Line, MSG_UTI_MONITOR_WARNING); } else { ret = 2; sge_dstring_append(&Info_Line, MSG_UTI_MONITOR_ERROR); } sge_dstring_append(&Info_Line, "\n"); } #if defined(LINUX) || defined(AIX43) || defined(AIX51) || defined(IRIX) || defined(SOLARIS) || defined(HP11) if (mallinfo_func_pointer != NULL) { struct mallinfo mallinfo_data = mallinfo_func_pointer(); sge_dstring_sprintf_append(&Info_Line, MSG_UTI_MONITOR_SCHEXT_UUUUUUUUUU, mallinfo_data.arena, mallinfo_data.ordblks, mallinfo_data.smblks, mallinfo_data.hblks, mallinfo_data.hblkhd, mallinfo_data.usmblks, mallinfo_data.fsmblks, mallinfo_data.uordblks, mallinfo_data.fordblks, mallinfo_data.keepcost); sge_dstring_append(&Info_Line, "\n"); } #endif if (monitor_time != 0) { /* generates the output monitoring output data */ int i; sge_dstring_append(&Info_Line, MSG_UTI_MONITOR_COLON); sge_dstring_append(&Info_Line, "\n"); for (i = 0; i < MAX_OUTPUT_LINES; i++) { sge_mutex_lock("sge_monitor_status", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex)); if (Output[i].name != NULL) { append_time(Output[i].update_time, &Info_Line, false); sge_dstring_append(&Info_Line, " | "); sge_dstring_append_dstring(&Info_Line, Output[i].output); sge_dstring_append(&Info_Line,"\n"); } sge_mutex_unlock("sge_monitor_status", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex)); } } else { sge_dstring_append(&Info_Line, MSG_UTI_MONITOR_DISABLED); sge_dstring_append(&Info_Line, "\n"); } *info_message = strdup(sge_dstring_get_string(&Info_Line)); sge_mutex_unlock("sge_monitor_status", SGE_FUNC, __LINE__, &global_mutex); DEXIT; return ret; }
// appends the current UTP timestamp void append_current_time() { append_time(get_current_ntp_time()); }