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;
}
}
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");
}
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");
}
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.");
}
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());
}
}
Aggregations