Skip to content

Commit bdd0ba0

Browse files
authored
Merge pull request #231 from Dokyeongyun/ft-220501-alertLogSearchTags
Ft 220501 alert log search tags
2 parents d0b55f0 + 2c5b27f commit bdd0ba0

File tree

10 files changed

+381
-90
lines changed

10 files changed

+381
-90
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,12 @@
209209
<artifactId>commons-pool2</artifactId>
210210
<version>2.11.1</version>
211211
</dependency>
212+
213+
<!-- richtext -->
214+
<dependency>
215+
<groupId>org.fxmisc.richtext</groupId>
216+
<artifactId>richtextfx</artifactId>
217+
<version>0.10.5</version>
218+
</dependency>
212219
</dependencies>
213220
</project>

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: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
import javafx.event.EventHandler;
1919
import javafx.fxml.FXML;
2020
import javafx.fxml.Initializable;
21+
import javafx.geometry.Insets;
2122
import javafx.scene.control.Alert.AlertType;
2223
import javafx.scene.control.DatePicker;
24+
import javafx.scene.control.ScrollPane;
25+
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
2326
import javafx.scene.control.TextField;
2427
import javafx.scene.input.KeyCode;
2528
import javafx.scene.input.KeyEvent;
2629
import javafx.scene.layout.AnchorPane;
30+
import javafx.scene.layout.HBox;
2731
import javafx.scene.layout.StackPane;
2832
import lombok.extern.slf4j.Slf4j;
2933
import root.common.server.implement.JschServer;
@@ -43,6 +47,7 @@
4347
import root.javafx.CustomView.AlertLogListViewCell;
4448
import root.javafx.CustomView.AlertLogMonitoringSummaryAP;
4549
import root.javafx.CustomView.NumberTextFormatter;
50+
import root.javafx.CustomView.TagBar;
4651
import root.javafx.CustomView.dateCell.DisableAfterTodayDateCell;
4752
import root.utils.AlertUtils;
4853

@@ -71,6 +76,9 @@ public class AlertLogMonitoringMenuController implements Initializable {
7176
@FXML
7277
StackPane alertLogSummarySP;
7378

79+
@FXML
80+
HBox searchKeywordHBox;
81+
7482
@FXML
7583
TextField navigatorTF;
7684

@@ -83,6 +91,8 @@ public class AlertLogMonitoringMenuController implements Initializable {
8391
@FXML
8492
AnchorPane summaryNodataAP;
8593

94+
TagBar tagBar = new TagBar();
95+
8696
Map<String, AlertLog> alertLogMonitoringResultMap;
8797

8898
public AlertLogMonitoringMenuController() {
@@ -124,12 +134,20 @@ public void initialize(URL location, ResourceBundle resources) {
124134
}
125135

126136
private void changeAlertLogListViewData(String serverID) {
137+
// AlertLog ListView
138+
String[] hightlightKeywords = tagBar.getTags().toArray(new String[0]);
139+
alertLogLV.setCellFactory(categoryList -> new AlertLogListViewCell(hightlightKeywords));
140+
127141
alertLogLV.getItems().clear();
128142
AlertLog alertLog = alertLogMonitoringResultMap.get(serverID);
129143
if (alertLog != null) {
130144
// Alert Log ListView
131145
alertLogLV.getItems().addAll(alertLog.getAlertLogs());
132-
146+
Platform.runLater(() -> {
147+
alertLogLV.scrollTo(0);
148+
alertLogLV.getSelectionModel().select(0);
149+
});
150+
133151
// Alert Log Summary
134152
alertLogSummarySP.getChildren().add(new AlertLogMonitoringSummaryAP(alertLog));
135153
} else {
@@ -168,9 +186,6 @@ private void initAlertLogMonitoringElements() {
168186
}
169187
});
170188

171-
// AlertLog ListView
172-
alertLogLV.setCellFactory(categoryList -> new AlertLogListViewCell());
173-
174189
// AlertLog Navigator
175190
navigatorTF.setTextFormatter(new NumberTextFormatter());
176191
navigatorTF.setOnKeyReleased(new EventHandler<KeyEvent>() {
@@ -183,6 +198,21 @@ public void handle(KeyEvent e) {
183198
}
184199
});
185200

201+
// Search Keyword Tagbar
202+
ScrollPane tagBarWrapper = new ScrollPane(tagBar);
203+
tagBarWrapper.setStyle("-fx-border-width: 0.2px; -fx-border-color: gray;");
204+
tagBarWrapper.getStyleClass().add("gray-scrollbar");
205+
tagBarWrapper.setMaxWidth(375);
206+
tagBarWrapper.setMinHeight(45);
207+
tagBarWrapper.setFitToHeight(true);
208+
tagBarWrapper.prefHeightProperty().bind(searchKeywordHBox.heightProperty());
209+
tagBarWrapper.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);
210+
HBox.setMargin(tagBarWrapper, new Insets(0, 0, 0, 25));
211+
searchKeywordHBox.getChildren().add(tagBarWrapper);
212+
213+
tagBar.setMaxWidth(355);
214+
tagBarWrapper.vvalueProperty().bind(tagBar.heightProperty());
215+
186216
// Set view visible
187217
mainNodataAP.setVisible(true);
188218
alertLogLV.setVisible(false);
@@ -248,7 +278,9 @@ public void monitoringAlertLog(ActionEvent e) throws Exception {
248278
}
249279
ServerMonitoringUsecase usecase = new ServerMonitoringUsecaseImpl(repo, ReportFileRepo.getInstance());
250280

251-
AlertLog result = usecase.getAlertLogDuringPeriod(connInfo.getAlc(), alertLogStartDay, alertLogEndDay);
281+
String[] searchKeywords = tagBar.getTags().toArray(new String[0]);
282+
AlertLog result = usecase.getAlertLogDuringPeriod(connInfo.getAlc(), alertLogStartDay, alertLogEndDay,
283+
searchKeywords);
252284
alertLogMonitoringResultMap.put(selectedServer, result);
253285

254286
changeAlertLogListViewData(alertLogServerComboBox.getSelectionModel().getSelectedItem());
@@ -271,7 +303,7 @@ public void prevAlertLog(ActionEvent e) {
271303
updateStatusMessage("첫번째 Log입니다.");
272304
return;
273305
}
274-
306+
275307
navigatorTF.setText(String.valueOf(toIndex));
276308
focusAlertLog(e);
277309
}
@@ -282,13 +314,12 @@ public void nextAlertLog(ActionEvent e) {
282314
return;
283315
}
284316

285-
286317
int toIndex = Integer.parseInt(input) + 1;
287318
if (toIndex > alertLogLV.getItems().size()) {
288319
updateStatusMessage("마지막 Log입니다.");
289320
return;
290321
}
291-
322+
292323
navigatorTF.setText(String.valueOf(toIndex));
293324
focusAlertLog(e);
294325
}

0 commit comments

Comments
 (0)