class MonitorController {

    @Autowired
    private MonitorService monitorService;

    @PostMapping
    @Operation(summary = "Add a monitoring application", description = "新增一个监控应用")
    public ResponseEntity<Message<Void>> addNewMonitor(@Valid @RequestBody MonitorDto monitorDto) {
        // Verify request data  校验请求数据
        monitorService.validate(monitorDto, false);
        if (monitorDto.isDetected()) {
            // Probe    进行探测
            monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams(), monitorDto.getCollector());
        }
        monitorService.addMonitor(monitorDto.getMonitor(), monitorDto.getParams(), monitorDto.getCollector());
        return ResponseEntity.ok(Message.success("Add success"));
    }

    @PutMapping
    @Operation(summary = "Modify an existing monitoring application", description = "修改一个已存在监控应用")
    public ResponseEntity<Message<Void>> modifyMonitor(@Valid @RequestBody MonitorDto monitorDto) {
        // Verify request data  校验请求数据
        monitorService.validate(monitorDto, true);
        if (monitorDto.isDetected()) {
            // Probe    进行探测
            monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams(), monitorDto.getCollector());
        }
        monitorService.modifyMonitor(monitorDto.getMonitor(), monitorDto.getParams(), monitorDto.getCollector());
        return ResponseEntity.ok(Message.success("Modify success"));
    }

    @GetMapping(path = "/{id}")
    @Operation(summary = "Obtain monitoring information based on monitoring ID", description = "根据监控任务ID获取监控信息")
    public ResponseEntity<Message<MonitorDto>> getMonitor(
            @Parameter(description = "监控任务ID", example = "6565463543") @PathVariable("id") final long id) {<FILL_FUNCTION_BODY>}

    @DeleteMapping(path = "/{id}")
    @Operation(summary = "Delete monitoring application based on monitoring ID", description = "根据监控任务ID删除监控应用")
    public ResponseEntity<Message<Void>> deleteMonitor(
            @Parameter(description = "en: Monitor ID,zh: 监控任务ID", example = "6565463543") @PathVariable("id") final long id) {
        // delete monitor 删除监控
        Monitor monitor = monitorService.getMonitor(id);
        if (monitor == null) {
            return ResponseEntity.ok(Message.success("The specified monitoring was not queried, please check whether the parameters are correct"));
        }
        monitorService.deleteMonitor(id);
        return ResponseEntity.ok(Message.success("Delete success"));
    }

    @PostMapping(path = "/detect")
    @Operation(summary = "Perform availability detection on this monitoring based on monitoring information", description = "根据监控信息去对此监控进行可用性探测")
    public ResponseEntity<Message<Void>> detectMonitor(@Valid @RequestBody MonitorDto monitorDto) {
        monitorService.validate(monitorDto, null);
        monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams(), monitorDto.getCollector());
        return ResponseEntity.ok(Message.success("Detect success."));
    }

    @PostMapping("/optional")
    @Operation(summary = "Add a monitor that can select metrics", description = "新增一个可选指标的监控器")
    public ResponseEntity<Message<Void>> addNewMonitorOptionalMetrics(@Valid @RequestBody MonitorDto monitorDto) {
        monitorService.validate(monitorDto, false);
        if (monitorDto.isDetected()) {
            monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams(), monitorDto.getCollector());
        }
        monitorService.addNewMonitorOptionalMetrics(monitorDto.getMetrics(), monitorDto.getMonitor(), monitorDto.getParams());
        return ResponseEntity.ok(Message.success("Add success"));
    }

    @GetMapping(value = {"/metric/{app}", "/metric"})
    @Operation(summary = "get app metric", description = "根据app名称获取该app可监控指标，不传为获取全部指标")
    public ResponseEntity<Message<List<String>>> getMonitorMetrics(
            @PathVariable(value = "app", required = false) String app) {
        List<String> metricNames = monitorService.getMonitorMetrics(app);
        return ResponseEntity.ok(Message.success(metricNames));
    }

}

        // Get monitoring information
        // 获取监控信息
        MonitorDto monitorDto = monitorService.getMonitorDto(id);
        if (monitorDto == null) {
            return ResponseEntity.ok(Message.fail(MONITOR_NOT_EXIST_CODE, "Monitor not exist."));
        } else {
            return ResponseEntity.ok(Message.success(monitorDto));
        }
    
<no_super_class>