Search in sources :

Example 21 with AcsLogLevelDefinition

use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.

the class AcsContainer method ping.

/**
	 * Replies with <code>true</code> so that Manager sees that this container is alive.
	 * <p>
	 * Prints a message to System.out, so that it's visible on the local console that the container is doing ok. Does
	 * not log anything, because a failure to reply would show up remotely anyway.
	 * <p>
	 * No message is printed if the container log level is above INFO, see http://jira.alma.cl/browse/COMP-1736.
	 * 
	 * @see si.ijs.maci.ClientOperations#ping()
	 */
public boolean ping() {
    // we cannot use m_logger.isLoggable because only the stdout log level should be considered,
    // and it would be even worse a hack to go from the logger to its stdout handler to ask for the level there.
    AcsLogLevelDefinition stdoutLevel;
    try {
        stdoutLevel = AcsLogLevelDefinition.fromXsdLogLevel(logConfig.getNamedLoggerConfig(m_containerName).getMinLogLevelLocal());
    } catch (AcsJIllegalArgumentEx ex) {
        stdoutLevel = AcsLogLevelDefinition.DEBUG;
        ex.printStackTrace();
    }
    if (stdoutLevel.compareTo(AcsLogLevelDefinition.DEBUG) <= 0) {
        Runtime rt = Runtime.getRuntime();
        long totalMemKB = rt.totalMemory() / 1024;
        long usedMemKB = totalMemKB - rt.freeMemory() / 1024;
        String memStatus = "Memory usage " + usedMemKB + " of " + totalMemKB + " kB ";
        long maxMem = rt.maxMemory();
        if (maxMem < Long.MAX_VALUE) {
            long maxMemKB = maxMem / 1024;
            memStatus += "(= " + (usedMemKB * 1000 / maxMemKB) / 10.0 + "% of JVM growth limit " + maxMemKB + " kB) ";
        }
        String timestamp = IsoDateFormat.formatCurrentDate();
        System.out.println(timestamp + " [" + m_containerName + "] ping received, container alive. " + memStatus);
    }
    return true;
}
Also used : AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition) AcsJIllegalArgumentEx(alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx)

Aggregations

AcsLogLevelDefinition (alma.acs.logging.level.AcsLogLevelDefinition)21 AcsLogLevel (alma.acs.logging.AcsLogLevel)4 LogConfig (alma.acs.logging.config.LogConfig)3 UnnamedLogger (alma.maci.loggingconfig.UnnamedLogger)3 LogRecord (java.util.logging.LogRecord)3 AcsLogRecord (alma.acs.logging.AcsLogRecord)2 LogParameterUtil (alma.acs.logging.LogParameterUtil)2 LogReceiver (alma.acs.logging.engine.LogReceiver)2 StopWatch (alma.acs.util.StopWatch)2 AlarmTestComponent (alma.alarmContainerTest.AlarmTestComponent)2 LoggingConfig (alma.maci.loggingconfig.LoggingConfig)2 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Date (java.util.Date)2 Map (java.util.Map)2 Level (java.util.logging.Level)2 Test (org.junit.Test)2 ContainerLogLevelSpec (acs.benchmark.util.ContainerUtil.ContainerLogLevelSpec)1 ACSComponentOperations (alma.ACS.ACSComponentOperations)1