Search in sources :

Example 6 with LogMessage

use of com.emc.storageos.systemservices.impl.logsvc.LogMessage in project coprhd-controller by CoprHD.

the class LogNetworkReader method readNextLogMessage.

@Override
public LogMessage readNextLogMessage() {
    try {
        while (true) {
            byte flag = (byte) dis.read();
            if (flag == LogACKCode.ACK_FIN) {
                logger.debug("received FIN");
                logger.debug("logMessageCount_Reader={}", logMessageCount);
                isFinished = true;
                return null;
            } else if (flag == LogACKCode.ACK_STATUS) {
                status.readAndAppend(dis);
            } else if (flag == LogACKCode.ACK_LOG_ENTRY) {
                LogMessage log = LogMessage.read(dis);
                logMessageCount++;
                log.setNodeId(LogUtil.nodeIdToBytes(nodeId));
                log.setNodeName(LogUtil.nodeNameToBytes(nodeName));
                if (logMessageCount % 100000 == 0) {
                    logger.debug("processing the {}th log messages", logMessageCount);
                }
                return log;
            } else {
                logger.info("receive {} -- ERROR", flag);
            }
        }
    } catch (IOException e) {
        // TODO: generate a dynamic error log message
        logger.error("IOException:", e);
        return null;
    }
}
Also used : LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) IOException(java.io.IOException)

Example 7 with LogMessage

use of com.emc.storageos.systemservices.impl.logsvc.LogMessage in project coprhd-controller by CoprHD.

the class SysLogReaderTest method testLogCountSysParser.

/**
 * Test if reader could recognize the correct count of system logs
 */
@Test
public void testLogCountSysParser() throws Exception {
    System.out.println("starting testLogCountSysParser");
    LogStatusInfo status = new LogStatusInfo();
    final int WARN = 5;
    // four kinds of different patterns in file
    String filePath = "src/main/data/testReaderData/testSyslogParser.log";
    long logCount = 47;
    LogReader reader = null;
    LogRequest req = new LogRequest.Builder().logLevel(WARN).build();
    reader = new LogReader(filePath, req, status, null);
    while (true) {
        LogMessage log = reader.readNextLogMessage();
        if (log == null) {
            assertEquals("Log count should match", logCount, reader.getLogCount());
            break;
        }
    }
    System.out.println("done testLogCountSysParser");
}
Also used : LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Test(org.junit.Test)

Example 8 with LogMessage

use of com.emc.storageos.systemservices.impl.logsvc.LogMessage in project coprhd-controller by CoprHD.

the class SysLogReaderTest method testLogStatusInfo.

/**
 * Test if reader could record correct status information
 */
@Test
public void testLogStatusInfo() throws Exception {
    System.out.println("starting testLogStatusInfo");
    LogStatusInfo status = new LogStatusInfo();
    String filePath = "src/main/data/testReaderData/testStatus.log";
    long logCount = 42;
    LogReader reader = null;
    LogRequest req = new LogRequest.Builder().build();
    reader = new LogReader(filePath, req, status, null);
    while (true) {
        LogMessage log = reader.readNextLogMessage();
        if (log == null) {
            assertEquals("Log count should match", logCount, reader.getLogCount());
            break;
        }
    }
    BufferedReader br = new BufferedReader(new FileReader("src/main/data/testReaderData/testStatusResult.log"));
    String line = br.readLine();
    int index = 0;
    while (line != null) {
        assertTrue("status's size is not correct!", status.getStatus().size() > index);
        assertEquals("status's contect is not correct!", line, status.getStatus().get(index));
        index++;
        line = br.readLine();
    }
    assertEquals("status's size is not correct!", status.getStatus().size(), index);
    br.close();
    System.out.println("done testLogStatusInfo");
}
Also used : LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 9 with LogMessage

use of com.emc.storageos.systemservices.impl.logsvc.LogMessage in project coprhd-controller by CoprHD.

the class LogStreamPerfTest method testPerformance.

@Test
public void testPerformance() throws Exception {
    List<File> files = new ArrayList<>();
    files.add(new File("/opt/storageos/logs/testData/controllersvc.log"));
    files.add(new File("/opt/storageos/logs/testData/controllersvc.log.20131120-163817.gz"));
    LogRequest req = new LogRequest.Builder().build();
    LogStatusInfo status = new LogStatusInfo();
    LogFileStream stream = new LogFileStream("", files, req, status);
    long startTime = 0;
    long endTime = 0;
    startTime = System.nanoTime();
    while (true) {
        LogMessage log = stream.readNextLogMessage();
        if (log == null) {
            endTime = System.nanoTime();
            break;
        }
    }
    double elapsedTime = (double) (endTime - startTime) / 1000000000.0;
    double speed = 1510.8 / elapsedTime;
    System.out.println("Total read 1510.8 MB; Used " + elapsedTime + " sec; Average " + speed + " MB/sec.");
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogFileStream(com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 10 with LogMessage

use of com.emc.storageos.systemservices.impl.logsvc.LogMessage in project coprhd-controller by CoprHD.

the class LogAnalyser method analysisLogs.

public void analysisLogs() {
    // parse db and zk error logs and alert if match pre-defined errors/fatals
    try {
        String serviceNameList = getServiceNameList();
        _log.info("Starting parse error logs for services : {}, and will alert if match pre-defined errors/fatals", serviceNameList);
        LogNetworkStreamMerger logRequestMgr = getNodeErrorLogs();
        LogMessage msg = logRequestMgr.readNextMergedLogMessage();
        int finalCount = 0;
        if (msg != null) {
            do {
                List<LogMessage> currentLogBatch = new ArrayList<>();
                LogMessage startLogOfNextBatch = logRequestMgr.readLogBatch(msg, currentLogBatch);
                if (!LogUtil.permitNextLogBatch(maxCount, finalCount, currentLogBatch.size())) {
                    // discard this batch
                    break;
                }
                for (LogMessage logMsg : currentLogBatch) {
                    parseErrorLogAndCompareWithPatterns(logMsg);
                    finalCount++;
                }
                msg = startLogOfNextBatch;
            } while (msg != null);
        }
        _log.info("Total error/fatal logs number is {}", finalCount);
    } catch (Exception e) {
        _log.error("Get exception when achieve logs with error msg: {}; stack trace is {}", e.getMessage(), e.getStackTrace());
    }
}
Also used : LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) ArrayList(java.util.ArrayList) LogNetworkStreamMerger(com.emc.storageos.systemservices.impl.logsvc.merger.LogNetworkStreamMerger)

Aggregations

LogMessage (com.emc.storageos.systemservices.impl.logsvc.LogMessage)25 LogRequest (com.emc.vipr.model.sys.logging.LogRequest)15 Test (org.junit.Test)15 LogStatusInfo (com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo)12 Date (java.util.Date)9 LogReader (com.emc.storageos.systemservices.impl.logsvc.stream.LogReader)7 ArrayList (java.util.ArrayList)7 Calendar (java.util.Calendar)6 File (java.io.File)5 Ignore (org.junit.Ignore)5 LogFileStream (com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream)4 LogStreamMerger (com.emc.storageos.systemservices.impl.logsvc.merger.LogStreamMerger)3 IOException (java.io.IOException)3 BufferedOutputStream (java.io.BufferedOutputStream)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1