Skip to content

Commit

Permalink
[bug fixed]When importing and exporting monitoring, support export co…
Browse files Browse the repository at this point in the history
…llectors, configure collectors when importing (#1178)
  • Loading branch information
zqr10159 authored Aug 12, 2023
1 parent 0fe238c commit 0b5614b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public void importConfig(InputStream is) {
.map(this::convert)
.collect(Collectors.toUnmodifiableList());
if (!CollectionUtils.isEmpty(formList)) {
formList.forEach(it -> {
monitorService.validate(it, false);
if (it.isDetected()) {
monitorService.detectMonitor(it.getMonitor(), it.getParams(), it.getCollector());
formList.forEach(monitorDto -> {
monitorService.validate(monitorDto, false);
if (monitorDto.isDetected()) {
monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams(), monitorDto.getCollector());
}
monitorService.addMonitor(it.getMonitor(), it.getParams(), it.getCollector());
monitorService.addMonitor(monitorDto.getMonitor(), monitorDto.getParams(), monitorDto.getCollector());
});
}
}
Expand Down Expand Up @@ -116,6 +116,7 @@ private ExportMonitorDTO convert(MonitorDto dto) {
.collect(Collectors.toUnmodifiableList()));
exportMonitor.setMetrics(dto.getMetrics());
exportMonitor.setDetected(false);
exportMonitor.getMonitor().setCollector(dto.getCollector());
return exportMonitor;
}

Expand All @@ -130,6 +131,7 @@ private MonitorDto convert(ExportMonitorDTO exportMonitor) {
filter(tag -> !(tag.getName().equals(CommonConstants.TAG_MONITOR_ID) || tag.getName().equals(CommonConstants.TAG_MONITOR_NAME)))
.collect(Collectors.toList()));
monitorDto.setMonitor(monitor);
monitorDto.setCollector(exportMonitor.getMonitor().getCollector());
monitorDto.setMetrics(exportMonitor.metrics);
monitorDto.setParams(exportMonitor.params.stream()
.map(it -> {
Expand Down Expand Up @@ -181,6 +183,8 @@ protected static class MonitorDTO {
private String description;
@Excel(name = "Tags")
private List<Long> tags;
@Excel(name = "Collector")
private String collector;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public List<ExportMonitorDTO> parseImport(InputStream is) {
ExportMonitorDTO exportMonitor = new ExportMonitorDTO();
exportMonitor.setMonitor(monitor);
monitors.add(exportMonitor);
String metrics = getCellValueAsString(row.getCell(10));
String metrics = getCellValueAsString(row.getCell(11));
if (StringUtils.hasText(metrics)) {
List<String> metricList = Arrays.stream(metrics.split(",")).collect(Collectors.toList());
exportMonitor.setMetrics(metricList);
}
boolean detected = getCellValueAsBoolean(row.getCell(11));
boolean detected = getCellValueAsBoolean(row.getCell(12));
exportMonitor.setDetected(detected);
}
}
Expand Down Expand Up @@ -133,17 +133,19 @@ private MonitorDTO extractMonitorDataFromRow(Row row) {
.collect(Collectors.toList());
monitor.setTags(tags);
}
monitor.setCollector(getCellValueAsString(row.getCell(7)));


return monitor;
}

private ParamDTO extractParamDataFromRow(Row row) {
String fieldName = getCellValueAsString(row.getCell(7));
String fieldName = getCellValueAsString(row.getCell(8));
if (StringUtils.hasText(fieldName)) {
ParamDTO param = new ParamDTO();
param.setField(fieldName);
param.setType(getCellValueAsByte(row.getCell(8)));
param.setValue(getCellValueAsString(row.getCell(9)));
param.setType(getCellValueAsByte(row.getCell(9)));
param.setValue(getCellValueAsString(row.getCell(10)));
return param;
}
return null;
Expand Down Expand Up @@ -220,7 +222,7 @@ void writeOs(List<ExportMonitorDTO> monitorList, OutputStream os) {
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
// 设置表头
String[] headers = { "name", "app", "host", "intervals", "status", "description", "tags", "field", "type", "value", "metrics", "detected" };
String[] headers = { "name", "app", "host", "intervals", "status", "description", "tags", "collector(default null if system dispatch)", "field", "type", "value", "metrics", "detected" };
Row headerRow = sheet.createRow(0);
for (int i = 0; i < headers.length; i++) {
Cell cell = headerRow.createCell(i);
Expand Down Expand Up @@ -263,25 +265,28 @@ void writeOs(List<ExportMonitorDTO> monitorList, OutputStream os) {
Cell tagsCell = row.createCell(6);
tagsCell.setCellValue(monitorDTO.getTags().stream().map(Object::toString).collect(Collectors.joining(",")));
tagsCell.setCellStyle(cellStyle);
Cell collectorCell = row.createCell(7);
collectorCell.setCellValue(monitorDTO.getCollector());
collectorCell.setCellStyle(cellStyle);
if (metricList != null && i < metricList.size()) {
Cell metricCell = row.createCell(10);
Cell metricCell = row.createCell(11);
metricCell.setCellValue(String.join(",", metricList));
metricCell.setCellStyle(cellStyle);
}
Cell detectedCell = row.createCell(11);
Cell detectedCell = row.createCell(12);
detectedCell.setCellValue(monitor.getDetected() != null && monitor.getDetected());
detectedCell.setCellStyle(cellStyle);
}
// 填写参数信息
if (i < paramList.size()) {
ParamDTO paramDTO = paramList.get(i);
Cell fieldCell = row.createCell(7);
Cell fieldCell = row.createCell(8);
fieldCell.setCellValue(paramDTO.getField());
fieldCell.setCellStyle(cellStyle);
Cell typeCell = row.createCell(8);
Cell typeCell = row.createCell(9);
typeCell.setCellValue(paramDTO.getType());
typeCell.setCellStyle(cellStyle);
Cell valueCell = row.createCell(9);
Cell valueCell = row.createCell(10);
valueCell.setCellValue(paramDTO.getValue());
valueCell.setCellStyle(cellStyle);
}
Expand Down

0 comments on commit 0b5614b

Please sign in to comment.