Skip to content

Commit 15661e6

Browse files
committed
Searching keyword in Alert log using Simple text full scan
1 parent aaf0067 commit 15661e6

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

src/main/java/root/core/usecase/constracts/ServerMonitoringUsecase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public interface ServerMonitoringUsecase {
1919

2020
List<OSDiskUsage> getCurrentOSDiskUsage();
2121

22-
AlertLog getAlertLogDuringPeriod(AlertLogCommand alc, String startDate, String endDate);
22+
AlertLog getAlertLogDuringPeriod(AlertLogCommand alc, String startDate, String endDate, String... searchKeywords);
2323
}

src/main/java/root/core/usecase/implement/ServerMonitoringUsecaseImpl.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.Date;
1414
import java.util.List;
1515

16+
import org.apache.commons.lang.StringUtils;
1617
import org.apache.poi.ss.usermodel.Sheet;
1718
import org.apache.poi.ss.usermodel.Workbook;
1819

@@ -37,7 +38,8 @@ public class ServerMonitoringUsecaseImpl implements ServerMonitoringUsecase {
3738
private ServerMonitoringRepository serverCheckRepository;
3839
private ReportRepository reportRepository;
3940

40-
public ServerMonitoringUsecaseImpl(ServerMonitoringRepository serverCheckRepository, ReportRepository reportRepository) {
41+
public ServerMonitoringUsecaseImpl(ServerMonitoringRepository serverCheckRepository,
42+
ReportRepository reportRepository) {
4143
this.serverCheckRepository = serverCheckRepository;
4244
this.reportRepository = reportRepository;
4345
}
@@ -266,8 +268,12 @@ public List<OSDiskUsage> getCurrentOSDiskUsage() {
266268
}
267269

268270
@Override
269-
public AlertLog getAlertLogDuringPeriod(AlertLogCommand alc, String startDate, String endDate) {
270-
log.debug(String.format("alert log file monitoring, %s (%s ~ %s)", alc.getReadFilePath(), startDate, endDate));
271+
public AlertLog getAlertLogDuringPeriod(AlertLogCommand alc, String startDate, String endDate,
272+
String... searchKeywords) {
273+
log.debug(String.format("alert log file monitoring, %s (%s ~ %s), Search Keywords: %s", alc.getReadFilePath(),
274+
startDate, endDate, StringUtils.join(searchKeywords, ",")));
275+
276+
long start = System.currentTimeMillis();
271277

272278
AlertLog alertLog = new AlertLog();
273279
String fullAlertLogString = getAlertLogStringFromCertainDate(alc, startDate);
@@ -285,10 +291,11 @@ public AlertLog getAlertLogDuringPeriod(AlertLogCommand alc, String startDate, S
285291
String logTimeStamp = "";
286292
List<String> logContents = new ArrayList<>();
287293
StringBuffer sb = new StringBuffer();
294+
boolean containsSearchKeyword = searchKeywords.length == 0;
288295

289296
for (int i = 0; i < lines.length; i++) {
290297
String line = lines[i];
291-
298+
292299
// 조회시작일자 찾기
293300
if (!isStartDate) {
294301
LocalDate parsedDate = DateUtils.parse(line);
@@ -301,15 +308,15 @@ public AlertLog getAlertLogDuringPeriod(AlertLogCommand alc, String startDate, S
301308
logTimeStamp = line;
302309

303310
// [조회종료일자 > 조회 시작일자 >= 최초 로그기록일자]일 때 최초 로그기록일자부터 읽기 시작
304-
if(DateUtils.getDateDiffTime("yyyy-MM-dd", parsedDateString, endDate) > 0) {
311+
if (DateUtils.getDateDiffTime("yyyy-MM-dd", parsedDateString, endDate) > 0) {
305312
isEndDate = true;
306313
readEndIndex = i;
307314
break;
308315
}
309316
}
310317
}
311318
}
312-
319+
313320
// 로그 저장 시작 & 조회종료일자 찾기
314321
if (isStartDate) {
315322
LocalDate parsedDate = DateUtils.parse(line);
@@ -327,11 +334,22 @@ public AlertLog getAlertLogDuringPeriod(AlertLogCommand alc, String startDate, S
327334
}
328335

329336
if (i != readStartIndex) {
330-
alertLog.addLog(new Log(alertLog.getAlertLogs().size(), logTimeStamp, logContents));
337+
if (containsSearchKeyword) {
338+
alertLog.addLog(new Log(alertLog.getAlertLogs().size(), logTimeStamp, logContents));
339+
containsSearchKeyword = searchKeywords.length == 0;
340+
}
331341
logContents = new ArrayList<>();
332342
logTimeStamp = line;
333343
}
334344
} else { // Log Content Line
345+
346+
// 검색 키워드가 포함되었는지 확인
347+
for (String keyword : searchKeywords) {
348+
if (line.contains(keyword) || containsSearchKeyword) {
349+
containsSearchKeyword = true;
350+
break;
351+
}
352+
}
335353
logContents.add(line);
336354
}
337355

@@ -353,10 +371,15 @@ public AlertLog getAlertLogDuringPeriod(AlertLogCommand alc, String startDate, S
353371
} catch (Exception e) {
354372
log.error(e.getMessage());
355373
}
356-
374+
375+
long end = System.currentTimeMillis();
376+
log.info(String.format("Alert Log monitoring result (Log count: %d, Total line count: %d",
377+
alertLog.getAlertLogs().size(), alertLog.getTotalLineCount()));
378+
log.debug(String.format("Alert Log monitoring elapsed time: (%,.3f)ms", (end - start) / 1000.0));
379+
357380
return alertLog;
358381
}
359-
382+
360383
private String getAlertLogStringFromCertainDate(AlertLogCommand alc, String startDate) {
361384
int alertLogFileLineCnt = serverCheckRepository.getAlertLogFileLineCount(alc);
362385
String fullAlertLogString = serverCheckRepository.checkAlertLog(alc);

src/main/java/root/javafx/Controller/AlertLogMonitoringMenuController.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public class AlertLogMonitoringMenuController implements Initializable {
7575

7676
@FXML
7777
StackPane alertLogSummarySP;
78-
78+
7979
@FXML
8080
HBox searchKeywordHBox;
81-
81+
8282
@FXML
8383
TextField navigatorTF;
8484

@@ -92,7 +92,7 @@ public class AlertLogMonitoringMenuController implements Initializable {
9292
AnchorPane summaryNodataAP;
9393

9494
TagBar tagBar = new TagBar();
95-
95+
9696
Map<String, AlertLog> alertLogMonitoringResultMap;
9797

9898
public AlertLogMonitoringMenuController() {
@@ -192,7 +192,7 @@ public void handle(KeyEvent e) {
192192
}
193193
}
194194
});
195-
195+
196196
// Search Keyword Tagbar
197197
ScrollPane tagBarWrapper = new ScrollPane(tagBar);
198198
tagBarWrapper.setStyle("-fx-border-width: 0.2px; -fx-border-color: gray;");
@@ -202,12 +202,12 @@ public void handle(KeyEvent e) {
202202
tagBarWrapper.setFitToHeight(true);
203203
tagBarWrapper.prefHeightProperty().bind(searchKeywordHBox.heightProperty());
204204
tagBarWrapper.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);
205-
HBox.setMargin(tagBarWrapper, new Insets(0, 0, 0, 25));
206-
searchKeywordHBox.getChildren().add(tagBarWrapper);
205+
HBox.setMargin(tagBarWrapper, new Insets(0, 0, 0, 25));
206+
searchKeywordHBox.getChildren().add(tagBarWrapper);
207+
208+
tagBar.setMaxWidth(355);
209+
tagBarWrapper.vvalueProperty().bind(tagBar.heightProperty());
207210

208-
tagBar.setMaxWidth(355);
209-
tagBarWrapper.vvalueProperty().bind(tagBar.heightProperty());
210-
211211
// Set view visible
212212
mainNodataAP.setVisible(true);
213213
alertLogLV.setVisible(false);
@@ -273,7 +273,9 @@ public void monitoringAlertLog(ActionEvent e) throws Exception {
273273
}
274274
ServerMonitoringUsecase usecase = new ServerMonitoringUsecaseImpl(repo, ReportFileRepo.getInstance());
275275

276-
AlertLog result = usecase.getAlertLogDuringPeriod(connInfo.getAlc(), alertLogStartDay, alertLogEndDay);
276+
String[] searchKeywords = tagBar.getTags().toArray(new String[0]);
277+
AlertLog result = usecase.getAlertLogDuringPeriod(connInfo.getAlc(), alertLogStartDay, alertLogEndDay,
278+
searchKeywords);
277279
alertLogMonitoringResultMap.put(selectedServer, result);
278280

279281
changeAlertLogListViewData(alertLogServerComboBox.getSelectionModel().getSelectedItem());
@@ -296,7 +298,7 @@ public void prevAlertLog(ActionEvent e) {
296298
updateStatusMessage("첫번째 Log입니다.");
297299
return;
298300
}
299-
301+
300302
navigatorTF.setText(String.valueOf(toIndex));
301303
focusAlertLog(e);
302304
}
@@ -307,13 +309,12 @@ public void nextAlertLog(ActionEvent e) {
307309
return;
308310
}
309311

310-
311312
int toIndex = Integer.parseInt(input) + 1;
312313
if (toIndex > alertLogLV.getItems().size()) {
313314
updateStatusMessage("마지막 Log입니다.");
314315
return;
315316
}
316-
317+
317318
navigatorTF.setText(String.valueOf(toIndex));
318319
focusAlertLog(e);
319320
}

0 commit comments

Comments
 (0)