├── .gitignore ├── aiops-admin ├── .gitignore ├── pom.xml ├── spy.log └── src │ └── main │ ├── java │ └── com │ │ └── coocaa │ │ └── admin │ │ └── AiopsAdminApplication.java │ └── resources │ ├── bootstrap.yml │ └── templates │ └── mapper.xml.ftl ├── aiops-auth ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── coocaa │ │ └── auth │ │ ├── AuthApplication.java │ │ ├── controller │ │ └── AuthController.java │ │ └── service │ │ ├── AuthService.java │ │ └── impl │ │ └── AuthServiceImpl.java │ └── resources │ └── bootstrap.yml ├── aiops-common ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── coocaa │ └── common │ ├── constant │ ├── AppConstant.java │ ├── Constant.java │ ├── RedisConstant.java │ ├── StringConstant.java │ └── TableConstant.java │ ├── entity │ └── NoticeMail.java │ ├── request │ ├── PageRequestBean.java │ ├── PageWithTeamRequestBean.java │ ├── RequestBean.java │ └── RequestUtil.java │ └── util │ ├── CodeGeneratorUtil.java │ ├── DateUtil.java │ └── RegexUtil.java ├── aiops-core ├── aiops-core-boot │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── coocaa │ │ │ └── core │ │ │ └── boot │ │ │ ├── config │ │ │ ├── ExecutorConfiguration.java │ │ │ ├── MybatisPlusConfiguration.java │ │ │ ├── RedisTemplateConfiguration.java │ │ │ ├── RestTemplateConfiguration.java │ │ │ ├── RetryConfiguration.java │ │ │ └── WebMvcConfiguration.java │ │ │ ├── logger │ │ │ └── RequestLogAspect.java │ │ │ ├── props │ │ │ └── AsyncProperties.java │ │ │ ├── redis │ │ │ ├── RedisKeySerializer.java │ │ │ └── RedisUtil.java │ │ │ └── resolver │ │ │ └── TokenArgumentResolver.java │ │ └── resources │ │ ├── banner.txt │ │ ├── bootstrap.yml │ │ ├── config │ │ └── ehcache.xml │ │ ├── log │ │ ├── logback_dev.xml │ │ ├── logback_prod.xml │ │ └── logback_test.xml │ │ └── static │ │ └── favicon.ico ├── aiops-core-cloud │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── core │ │ └── cloud │ │ ├── config │ │ └── FeignConfiguration.java │ │ └── feign │ │ ├── FeignHystrixConcurrencyStrategy.java │ │ └── FeignRequestHeaderInterceptor.java ├── aiops-core-log │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── core │ │ └── log │ │ ├── annotation │ │ └── ApiLog.java │ │ ├── aspect │ │ └── ApiLogAspect.java │ │ ├── config │ │ ├── AiopsErrorMvcAutoConfiguration.java │ │ └── AiopsLogToolAutoConfiguration.java │ │ ├── constant │ │ └── EventConstant.java │ │ ├── error │ │ ├── AiopsErrorAttributes.java │ │ ├── AiopsErrorController.java │ │ └── AiopsRestExceptionTranslator.java │ │ ├── event │ │ ├── ApiLogEvent.java │ │ ├── ApiLogListener.java │ │ ├── ErrorLogEvent.java │ │ ├── ErrorLogListener.java │ │ ├── UsualLogEvent.java │ │ └── UsualLogListener.java │ │ ├── exception │ │ ├── ApiException.java │ │ ├── ApiResultEnum.java │ │ └── ServiceException.java │ │ ├── feign │ │ ├── ILogClient.java │ │ └── LogClientFallback.java │ │ ├── logger │ │ └── AiOpsLogger.java │ │ ├── model │ │ ├── LogAbstract.java │ │ ├── LogApi.java │ │ ├── LogApiVo.java │ │ ├── LogError.java │ │ ├── LogErrorVo.java │ │ ├── LogUsual.java │ │ └── LogUsualVo.java │ │ ├── props │ │ └── AiopsProperties.java │ │ ├── publisher │ │ ├── ApiLogPublisher.java │ │ ├── ErrorLogPublisher.java │ │ └── UsualLogPublisher.java │ │ ├── response │ │ ├── ResponseHelper.java │ │ └── ResultBean.java │ │ ├── server │ │ └── ServerInfo.java │ │ └── utils │ │ ├── INetUtil.java │ │ └── LogAbstractUtil.java ├── aiops-core-mybatis │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── com │ │ └── coocaa │ │ │ └── core │ │ │ └── mybatis │ │ │ ├── AiopsMetaObjectHandler.java │ │ │ ├── base │ │ │ ├── BaseEntity.java │ │ │ ├── BaseService.java │ │ │ └── BaseServiceImpl.java │ │ │ └── support │ │ │ ├── BaseEntityWrapper.java │ │ │ ├── Condition.java │ │ │ └── Query.java │ │ └── io │ │ └── jsonwebtoken │ │ └── impl │ │ └── Base64Codec.java ├── aiops-core-secure │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── core │ │ └── secure │ │ ├── AiOpsUser.java │ │ ├── AuthInfo.java │ │ ├── config │ │ ├── LdapConfiguration.java │ │ ├── RegistryConfiguration.java │ │ └── SecureConfiguration.java │ │ ├── constant │ │ ├── AppConstant.java │ │ ├── SecureConstant.java │ │ └── TokenConstant.java │ │ ├── exception │ │ └── SecureException.java │ │ ├── interceptor │ │ ├── ClientInterceptor.java │ │ └── SecureInterceptor.java │ │ ├── registry │ │ └── SecureRegistry.java │ │ └── utils │ │ ├── LdapUtil.java │ │ └── SecureUtil.java ├── aiops-core-swagger │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── core │ │ └── swagger │ │ ├── SwaggerAutoConfiguration.java │ │ └── SwaggerProperties.java ├── aiops-core-tool │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── core │ │ └── tool │ │ ├── api │ │ ├── IResultCode.java │ │ ├── R.java │ │ └── ResultCode.java │ │ ├── base │ │ └── BaseException.java │ │ ├── config │ │ ├── JacksonConfiguration.java │ │ ├── MessageConfiguration.java │ │ └── ToolConfiguration.java │ │ ├── constant │ │ ├── AiOpsConstant.java │ │ ├── RoleConstant.java │ │ └── SystemConstant.java │ │ ├── exception │ │ └── ExceptionResolver.java │ │ ├── jackson │ │ ├── AbstractReadWriteJackson2HttpMessageConverter.java │ │ ├── AiopsBeanSerializerModifier.java │ │ ├── AiopsJavaTimeModule.java │ │ ├── JsonUtil.java │ │ └── MappingApiJackson2HttpMessageConverter.java │ │ ├── node │ │ ├── BaseNode.java │ │ ├── ForestNode.java │ │ ├── ForestNodeManager.java │ │ ├── ForestNodeMerger.java │ │ ├── INode.java │ │ ├── NodeTest.java │ │ └── TreeNode.java │ │ ├── response │ │ ├── CodeEnum.java │ │ ├── Constant.java │ │ ├── PromNorm.java │ │ ├── ReturnData.java │ │ └── WarnStatusEnum.java │ │ ├── singleton │ │ └── SingleTonContextEnum.java │ │ ├── support │ │ ├── BaseBeanCopier.java │ │ ├── BeanProperty.java │ │ ├── FastStringWriter.java │ │ ├── IMultiOutputStream.java │ │ ├── ImagePosition.java │ │ ├── Kv.java │ │ ├── StrFormatter.java │ │ ├── StrSpliter.java │ │ ├── Try.java │ │ └── xss │ │ │ ├── HtmlFilter.java │ │ │ ├── XssFilter.java │ │ │ ├── XssHttpServletRequestWrapper.java │ │ │ └── XssProperties.java │ │ └── utils │ │ ├── AesUtil.java │ │ ├── Base64Util.java │ │ ├── BeanUtil.java │ │ ├── BindingResultUtil.java │ │ ├── Charsets.java │ │ ├── ClassUtil.java │ │ ├── CollectionUtil.java │ │ ├── ConcurrentDateFormat.java │ │ ├── DateTimeUtil.java │ │ ├── DateUtil.java │ │ ├── DigestUtil.java │ │ ├── Exceptions.java │ │ ├── Func.java │ │ ├── HelpUtil.java │ │ ├── ImageUtil.java │ │ ├── IoUtil.java │ │ ├── IpUtil.java │ │ ├── Lazy.java │ │ ├── MapUtil.java │ │ ├── NumberUtil.java │ │ ├── ObjectUtil.java │ │ ├── OkHttpUtil.java │ │ ├── PathUtil.java │ │ ├── ProtostuffUtil.java │ │ ├── RandomType.java │ │ ├── RegexUtil.java │ │ ├── ResourceUtil.java │ │ ├── SpringUtil.java │ │ ├── SqlUtil.java │ │ ├── StringPool.java │ │ ├── StringUtil.java │ │ ├── SuffixFileFilter.java │ │ ├── UrlUtil.java │ │ ├── WebUtil.java │ │ ├── XmlUtil.java │ │ └── http │ │ └── HttpHelper.java └── pom.xml ├── aiops-gateway ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── coocaa │ │ └── gateway │ │ ├── GateWayApplication.java │ │ ├── config │ │ ├── ErrorHandlerConfiguration.java │ │ ├── GatewayConfig.java │ │ ├── RateLimiterConfiguration.java │ │ └── RouterFunctionConfiguration.java │ │ ├── controller │ │ └── DiscoveryClientController.java │ │ ├── filter │ │ └── RequestGlobalFilter.java │ │ ├── handler │ │ ├── ErrorExceptionHandler.java │ │ ├── HystrixFallbackHandler.java │ │ ├── RequestBodyRoutePredicateFactory.java │ │ ├── SwaggerResourceHandler.java │ │ ├── SwaggerSecurityHandler.java │ │ └── SwaggerUiHandler.java │ │ └── provider │ │ └── SwaggerProvider.java │ └── resources │ └── bootstrap.yml ├── aiops-service-api ├── aiops-detector-api │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── detector │ │ ├── entity │ │ ├── Count.java │ │ ├── Detector.java │ │ ├── DetectorResult.java │ │ ├── MetricsCsvVo.java │ │ ├── Model.java │ │ ├── QueryModel.java │ │ ├── QuerySample.java │ │ ├── SampleDataset.java │ │ └── Train.java │ │ └── feign │ │ ├── IDetectorClient.java │ │ └── IDetectorClientFallback.java ├── aiops-notice-api │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── notice │ │ ├── entity │ │ ├── Mail.java │ │ └── MsgLog.java │ │ └── feign │ │ ├── INoticeClient.java │ │ └── INoticeClientFallback.java ├── aiops-prometheus-api │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── prometheus │ │ ├── common │ │ ├── PromBaseLables.java │ │ └── PromNorm.java │ │ ├── constant │ │ ├── EventConstant.java │ │ └── KPIListing.java │ │ ├── dto │ │ └── MetisDto.java │ │ ├── entity │ │ ├── Kpi.java │ │ ├── MatrixData.java │ │ ├── MetisException.java │ │ ├── Metric.java │ │ ├── PromMatrixData.java │ │ ├── PrometheusConfig.java │ │ ├── QueryInstant.java │ │ ├── QueryRange.java │ │ ├── Targets.java │ │ ├── Task.java │ │ ├── TaskError.java │ │ └── VectorData.java │ │ ├── feign │ │ └── ITaskClient.java │ │ ├── input │ │ ├── GetValuesInput.java │ │ ├── MetisCsvInputVo.java │ │ ├── MetisExceptionInputVo.java │ │ ├── QueryMetricProperty.java │ │ └── TaskInputVo.java │ │ └── output │ │ ├── KpiOutputVo.java │ │ ├── MetisCsvOutputVo.java │ │ ├── MetisExceptionOutputVo.java │ │ ├── MetricsCsvVo.java │ │ ├── TaskOutputVo.java │ │ └── httpRequestToTal │ │ └── MatrixResult.java ├── aiops-user-api │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── user │ │ ├── entity │ │ ├── Team.java │ │ ├── User.java │ │ ├── UserInfo.java │ │ └── WxUser.java │ │ ├── feign │ │ └── IUserClient.java │ │ ├── input │ │ ├── LoginUserVo.java │ │ ├── TeamInputVo.java │ │ └── UserInputVo.java │ │ └── output │ │ └── TeamOutputVo.java └── pom.xml ├── aiops-service ├── aiops-detector │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── coocaa │ │ │ └── detector │ │ │ ├── DetectorApplication.java │ │ │ ├── config │ │ │ └── AMQPConfig.java │ │ │ ├── controller │ │ │ └── MetisController.java │ │ │ ├── feign │ │ │ └── DetectorClient.java │ │ │ ├── mapper │ │ │ ├── MetisSourceMapper.java │ │ │ ├── SampleDatasetMapper.java │ │ │ └── TrainMapper.java │ │ │ ├── servcie │ │ │ ├── MetisService.java │ │ │ └── impl │ │ │ │ └── MetisServiceImpl.java │ │ │ └── util │ │ │ ├── MyJSON.java │ │ │ └── metis │ │ │ ├── SourceUtils.java │ │ │ └── TimeSeriesDetector.java │ │ └── resources │ │ └── bootstrap.yml ├── aiops-log │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── coocaa │ │ │ └── core │ │ │ └── log │ │ │ ├── LogApplication.java │ │ │ ├── controller │ │ │ ├── LogApiController.java │ │ │ ├── LogErrorController.java │ │ │ └── LogUsualController.java │ │ │ ├── feign │ │ │ └── LogClient.java │ │ │ ├── mapper │ │ │ ├── LogApiMapper.java │ │ │ ├── LogApiMapper.xml │ │ │ ├── LogErrorMapper.java │ │ │ ├── LogErrorMapper.xml │ │ │ ├── LogUsualMapper.java │ │ │ └── LogUsualMapper.xml │ │ │ └── service │ │ │ ├── ILogApiService.java │ │ │ ├── ILogErrorService.java │ │ │ ├── ILogUsualService.java │ │ │ └── impl │ │ │ ├── LogApiServiceImpl.java │ │ │ ├── LogErrorServiceImpl.java │ │ │ └── LogUsualServiceImpl.java │ │ └── resources │ │ └── bootstrap.yml ├── aiops-notice │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── coocaa │ │ │ │ └── notice │ │ │ │ ├── WarnNoticeApplication.java │ │ │ │ ├── config │ │ │ │ └── RabbitConfig.java │ │ │ │ ├── controller │ │ │ │ └── MailNoticeController.java │ │ │ │ ├── feign │ │ │ │ └── NoticeClient.java │ │ │ │ ├── mapper │ │ │ │ ├── MsgLogMapper.java │ │ │ │ └── MsgLogMapper.xml │ │ │ │ ├── mq │ │ │ │ ├── BaseConsumerProxy.java │ │ │ │ ├── consumer │ │ │ │ │ ├── BaseConsumer.java │ │ │ │ │ └── MailConsumer.java │ │ │ │ └── listener │ │ │ │ │ └── MailListener.java │ │ │ │ ├── service │ │ │ │ ├── IMailService.java │ │ │ │ └── impl │ │ │ │ │ └── MailServiceImpl.java │ │ │ │ ├── task │ │ │ │ └── ResendMsg.java │ │ │ │ └── util │ │ │ │ ├── MailUtil.java │ │ │ │ └── MessageHelper.java │ │ └── resources │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── notice │ │ └── WarnTestNoticeApplication.java ├── aiops-prometheus │ ├── pom.xml │ └── src │ │ ├── docker │ │ └── Dockerfile │ │ ├── main │ │ ├── docs │ │ │ └── asciidoc │ │ │ │ ├── generated │ │ │ │ ├── definitions.adoc │ │ │ │ ├── overview.adoc │ │ │ │ └── paths.adoc │ │ │ │ └── html │ │ │ │ ├── definitions.html │ │ │ │ ├── overview.html │ │ │ │ └── paths.html │ │ ├── java │ │ │ └── com │ │ │ │ └── coocaa │ │ │ │ └── prometheus │ │ │ │ ├── PrometheusApplication.java │ │ │ │ ├── config │ │ │ │ ├── BeanAutoConfig.java │ │ │ │ ├── RabbitConfig.java │ │ │ │ ├── ScheduleConfig.java │ │ │ │ └── WebSocketConfig.java │ │ │ │ ├── controller │ │ │ │ ├── KpiController.java │ │ │ │ ├── MetisExceptionController.java │ │ │ │ ├── PrometheusController.java │ │ │ │ ├── TaskController.java │ │ │ │ └── WebSocketController.java │ │ │ │ ├── event │ │ │ │ ├── ErrorTaskPublisher.java │ │ │ │ ├── TaskErrorEvent.java │ │ │ │ └── TaskErrorListener.java │ │ │ │ ├── feign │ │ │ │ └── TaskClient.java │ │ │ │ ├── mapper │ │ │ │ ├── KpiMapper.java │ │ │ │ ├── KpiMapper.xml │ │ │ │ ├── MetisExceptionMapper.java │ │ │ │ ├── MetisExceptionMapper.xml │ │ │ │ ├── TaskMapper.java │ │ │ │ └── TaskMapper.xml │ │ │ │ ├── rabbitMQ │ │ │ │ ├── TimingDataReceiverAndPusher.java │ │ │ │ └── TimingDataSender.java │ │ │ │ ├── service │ │ │ │ ├── KpiService.java │ │ │ │ ├── MetisExceptionService.java │ │ │ │ ├── NormSearchService.java │ │ │ │ ├── PromQLService.java │ │ │ │ ├── TaskService.java │ │ │ │ └── impl │ │ │ │ │ ├── AsyncServiceTask.java │ │ │ │ │ ├── KpiServiceImpl.java │ │ │ │ │ ├── MetisExceptionServiceImpl.java │ │ │ │ │ ├── NormSearchServiceImpl.java │ │ │ │ │ ├── PromQLServiceImpl.java │ │ │ │ │ └── TaskServiceImpl.java │ │ │ │ ├── system │ │ │ │ ├── SystemExit.java │ │ │ │ └── SystemInit.java │ │ │ │ └── util │ │ │ │ ├── FileJsonUtil.java │ │ │ │ ├── PoiUtil.java │ │ │ │ ├── PromQLUtil.java │ │ │ │ ├── SingletonEnum.java │ │ │ │ ├── TaskManager.java │ │ │ │ └── runnable │ │ │ │ └── QueryMetricTask.java │ │ └── resources │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── prometheus │ │ ├── PromtheusApiTest.java │ │ └── RestemplateTest.java ├── aiops-user │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── coocaa │ │ │ │ └── user │ │ │ │ ├── UserApplication.java │ │ │ │ ├── controller │ │ │ │ ├── TeamController.java │ │ │ │ └── UserController.java │ │ │ │ ├── feign │ │ │ │ └── UserClient.java │ │ │ │ ├── mapper │ │ │ │ ├── TeamMapper.java │ │ │ │ ├── TeamMapper.xml │ │ │ │ ├── UserMapper.java │ │ │ │ └── UserMapper.xml │ │ │ │ └── service │ │ │ │ ├── TeamService.java │ │ │ │ ├── UserService.java │ │ │ │ └── impl │ │ │ │ ├── TeamServiceImpl.java │ │ │ │ └── UserServiceImpl.java │ │ └── resources │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── coocaa │ │ └── user │ │ └── UserTestApplication.java └── pom.xml ├── docs ├── config │ ├── aiops-auth-dev.yaml │ ├── aiops-detector-dev.yaml │ ├── aiops-gateway-dev.yaml │ ├── aiops-log-dev.yaml │ ├── aiops-notice-dev.yaml │ ├── aiops-prometheus-dev.yaml │ ├── aiops-user-dev.yaml │ └── env.list └── 接口文档.pdf ├── pom.xml ├── readme.md └── sql └── aiops.sql /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /aiops-admin/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /aiops-admin/src/main/java/com/coocaa/admin/AiopsAdminApplication.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.admin; 2 | 3 | import de.codecentric.boot.admin.server.config.EnableAdminServer; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.cloud.client.SpringCloudApplication; 6 | 7 | @EnableAdminServer 8 | @SpringCloudApplication 9 | public class AiopsAdminApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AiopsAdminApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /aiops-admin/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 10002 3 | undertow: 4 | # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 5 | io-threads: 4 6 | # 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载 7 | worker-threads: 20 8 | # 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理 9 | buffer-size: 1024 10 | # 是否分配的直接内存 11 | direct-buffers: true 12 | 13 | spring: 14 | application: 15 | name: aiops-admin 16 | cloud: 17 | nacos: 18 | discovery: 19 | server-addr: 39.108.106.167:8848 20 | config: 21 | server-addr: 39.108.106.167:8848 22 | file-extension: yaml 23 | profiles: 24 | active: dev -------------------------------------------------------------------------------- /aiops-admin/src/main/resources/templates/mapper.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <#if enableCache> 6 | 7 | 8 | 9 | 10 | <#if baseResultMap> 11 | 12 | 13 | <#list table.fields as field> 14 | <#if field.keyFlag><#--生成主键排在第一位--> 15 | 16 | 17 | 18 | <#list table.commonFields as field><#--生成公共字段 --> 19 | 20 | 21 | <#list table.fields as field> 22 | <#if !field.keyFlag><#--生成普通字段 --> 23 | 24 | 25 | 26 | 27 | 28 | 29 | <#if baseColumnList> 30 | 31 | 32 | <#list table.commonFields as field> 33 | ${field.name}, 34 | 35 | ${table.fieldNames} 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /aiops-auth/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /aiops-auth/src/main/java/com/coocaa/auth/AuthApplication.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.auth; 2 | 3 | import com.coocaa.core.secure.constant.AppConstant; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cache.annotation.EnableCaching; 7 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | import org.springframework.cloud.openfeign.EnableFeignClients; 10 | 11 | @SpringBootApplication(scanBasePackages = {"com.coocaa"}) 12 | @EnableDiscoveryClient 13 | @EnableCircuitBreaker 14 | @EnableFeignClients(AppConstant.BASE_PACKAGES) 15 | @EnableCaching 16 | public class AuthApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(AuthApplication.class, args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /aiops-auth/src/main/java/com/coocaa/auth/service/AuthService.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.auth.service; 2 | 3 | import com.coocaa.core.log.response.ResultBean; 4 | import org.springframework.http.ResponseEntity; 5 | 6 | /** 7 | * @description: 8 | * @author: dongyang_wu 9 | * @create: 2019-07-29 10:19 10 | */ 11 | public interface AuthService { 12 | ResponseEntity token(String account, String password); 13 | 14 | ResponseEntity tokenByLdap(String account, String password); 15 | 16 | String testCache(String a); 17 | } -------------------------------------------------------------------------------- /aiops-auth/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: aiops-auth 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: 39.108.106.167:8848 8 | config: 9 | server-addr: 39.108.106.167:8848 10 | file-extension: yaml 11 | sentinel: 12 | transport: 13 | dashboard: 47.107.139.6:8858 14 | 15 | profiles: 16 | active: dev -------------------------------------------------------------------------------- /aiops-common/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /aiops-common/src/main/java/com/coocaa/common/constant/RedisConstant.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.common.constant; 2 | 3 | /** 4 | * @description: Redis常量 5 | * @author: dongyang_wu 6 | * @create: 2019-07-31 09:09 7 | */ 8 | public class RedisConstant { 9 | public interface Redis { 10 | String OK = "OK"; 11 | // 过期时间, 60s, 一分钟 12 | Integer EXPIRE_TIME_MINUTE = 60; 13 | // 过期时间, 一小时 14 | Integer EXPIRE_TIME_HOUR = 60 * 60; 15 | // 过期时间, 一天 16 | Integer EXPIRE_TIME_DAY = 60 * 60 * 24; 17 | // 5分钟 18 | Integer EXPIRE_TIME_FIVE_MINUTE = 5 * 60; 19 | } 20 | 21 | public interface AUTH_TOKEN { 22 | String PREFIX = "AUTH_TOKEN"; 23 | String TOKEN_PREFIX = "AUTH_TOKEN_%s"; 24 | 25 | } 26 | } -------------------------------------------------------------------------------- /aiops-common/src/main/java/com/coocaa/common/constant/StringConstant.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.common.constant; 2 | 3 | public interface StringConstant { 4 | 5 | String LIKE = "like"; 6 | 7 | String GREATER_STR = "大于"; 8 | String LESS_STR = "小于"; 9 | String NOT_EQUAL_STR = "不等于"; 10 | String GREATER = ">"; 11 | String LESS = "<"; 12 | String NOT_EQUAL = "<>"; 13 | 14 | String AND = "and"; 15 | String AND_NOT = "and not"; 16 | String OR = "or"; 17 | String IN = "in"; 18 | String NOT = "not"; 19 | 20 | String DESC = "desc"; 21 | String ASC = "asc"; 22 | 23 | String OK = "操作成功"; 24 | String FAIL = "操作失败"; 25 | 26 | String COMMA = ","; 27 | } 28 | -------------------------------------------------------------------------------- /aiops-common/src/main/java/com/coocaa/common/entity/NoticeMail.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.common.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author 陈煜坤 7 | * @date 2019/7/29 20:34 8 | * @package_name com.common.parent_model.entity 9 | */ 10 | @Data 11 | public class NoticeMail { 12 | 13 | private String to; 14 | private String from; 15 | private String subject; 16 | private String text; 17 | } 18 | -------------------------------------------------------------------------------- /aiops-common/src/main/java/com/coocaa/common/request/PageRequestBean.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.common.request; 2 | 3 | import lombok.*; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @description: 请求分页参数 9 | * @author: dongyang_wu 10 | * @create: 2019-08-06 09:58 11 | */ 12 | @Data 13 | @Builder 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class PageRequestBean { 17 | private Integer page = 0; 18 | private Integer count = 5; 19 | private String conditionConnection; 20 | private String orderBy; 21 | private String sortType; 22 | private List conditions; 23 | 24 | @Data 25 | @Builder 26 | @AllArgsConstructor 27 | @NoArgsConstructor 28 | public static class PageRequestItem { 29 | private String query; 30 | private String connection; 31 | private String queryString; 32 | } 33 | 34 | @Data 35 | @Builder 36 | @AllArgsConstructor 37 | @NoArgsConstructor 38 | public static class PageTeamRequestItem { 39 | private String connection; 40 | private String queryString; 41 | } 42 | } -------------------------------------------------------------------------------- /aiops-common/src/main/java/com/coocaa/common/request/PageWithTeamRequestBean.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.common.request; 2 | 3 | import lombok.*; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @description: 请求分页参数 9 | * @author: dongyang_wu 10 | * @create: 2019-08-06 09:58 11 | */ 12 | @EqualsAndHashCode(callSuper = true) 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class PageWithTeamRequestBean extends PageRequestBean { 17 | private List teamConditions; 18 | } -------------------------------------------------------------------------------- /aiops-common/src/main/java/com/coocaa/common/request/RequestBean.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.common.request; 2 | 3 | import lombok.*; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @program: intelligent_maintenance 9 | * @description: 请求体 10 | * @author: dongyang_wu 11 | * @create: 2019-08-01 16:46 12 | */ 13 | @Data 14 | @Builder 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | public class RequestBean { 18 | private List items; 19 | 20 | @Data 21 | @Builder 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | public static class RequestItem { 25 | private String query; 26 | private String queryString; 27 | } 28 | } -------------------------------------------------------------------------------- /aiops-common/src/main/java/com/coocaa/common/request/RequestUtil.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.common.request; 2 | 3 | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; 4 | import com.baomidou.mybatisplus.core.toolkit.StringUtils; 5 | import com.coocaa.common.constant.StringConstant; 6 | import com.coocaa.common.constant.TableConstant; 7 | 8 | import java.util.Optional; 9 | 10 | /** 11 | * @program: intelligent_maintenance 12 | * @description: 请求工具类 13 | * @author: dongyang_wu 14 | * @create: 2019-08-01 12:38 15 | */ 16 | public class RequestUtil { 17 | 18 | public static boolean isInValidParameter(Integer min, Integer max, Integer... list) { 19 | for (Integer args : list) { 20 | if (args < min || args > max) 21 | return true; 22 | } 23 | return false; 24 | } 25 | 26 | public static void setDefaultPageBean(PageRequestBean pageRequestBean) { 27 | pageRequestBean.setPage(Optional.ofNullable(pageRequestBean.getPage()).orElse(0)); 28 | pageRequestBean.setCount(Optional.ofNullable(pageRequestBean.getCount()).orElse(5)); 29 | pageRequestBean.setOrderBy(Optional.ofNullable(pageRequestBean.getOrderBy()).orElse(TableConstant.ID)); 30 | pageRequestBean.setSortType(Optional.ofNullable(pageRequestBean.getSortType()).orElse(StringConstant.DESC)); 31 | if (!CollectionUtils.isEmpty(pageRequestBean.getConditions()) && StringUtils.isEmpty(pageRequestBean.getConditionConnection())) 32 | pageRequestBean.setConditionConnection(StringConstant.AND); 33 | } 34 | } -------------------------------------------------------------------------------- /aiops-common/src/main/java/com/coocaa/common/util/RegexUtil.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.common.util; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.toolkit.StringUtils; 5 | 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | public class RegexUtil { 10 | public static boolean checkEmail(String email) { 11 | if(StringUtils.isEmpty(email)) 12 | return false; 13 | boolean flag; 14 | try { 15 | String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; 16 | Pattern regex = Pattern.compile(check); 17 | Matcher matcher = regex.matcher(email); 18 | flag = matcher.matches(); 19 | } catch (Exception e) { 20 | flag = false; 21 | } 22 | return flag; 23 | } 24 | public static boolean checkPhoneNumber(String mobileNumber) { 25 | if(StringUtils.isEmpty(mobileNumber)) 26 | return false; 27 | boolean flag ; 28 | try { 29 | // Pattern regex = Pattern.compile("^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$"); 30 | Pattern regex = Pattern.compile("^[1][3-5,7-8]\\d{9}$"); 31 | Matcher matcher = regex.matcher(mobileNumber); 32 | flag = matcher.matches(); 33 | } catch (Exception e) { 34 | flag = false; 35 | } 36 | return flag; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-boot/src/main/java/com/coocaa/core/boot/config/MybatisPlusConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.boot.config; 2 | 3 | import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector; 4 | import com.baomidou.mybatisplus.extension.plugins.*; 5 | import com.coocaa.core.secure.constant.AppConstant; 6 | import org.mybatis.spring.annotation.MapperScan; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 8 | import org.springframework.context.annotation.*; 9 | 10 | /** 11 | * mybatisplus 配置 12 | * 13 | * @author dongyang_wu 14 | */ 15 | @Configuration 16 | @MapperScan("com.coocaa.**.mapper.**") 17 | public class MybatisPlusConfiguration { 18 | 19 | @Bean 20 | @ConditionalOnMissingBean(PaginationInterceptor.class) 21 | public PaginationInterceptor paginationInterceptor() { 22 | return new PaginationInterceptor(); 23 | } 24 | 25 | @Bean 26 | public LogicSqlInjector logicSqlInjector() { 27 | return new LogicSqlInjector(); 28 | } 29 | 30 | /** 31 | * SQL执行效率插件 32 | * 33 | * @return PerformanceInterceptor 34 | */ 35 | @Bean 36 | @Profile({AppConstant.DEV_CODE, AppConstant.TEST_CODE}) 37 | public PerformanceInterceptor performanceInterceptor() { 38 | return new PerformanceInterceptor(); 39 | } 40 | 41 | /** 42 | * 乐观锁插件 43 | * @return 44 | */ 45 | @Bean 46 | public OptimisticLockerInterceptor optimisticLockerInterceptor() { 47 | return new OptimisticLockerInterceptor(); 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-boot/src/main/java/com/coocaa/core/boot/config/RestTemplateConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.boot.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.http.client.ClientHttpRequestFactory; 6 | import org.springframework.http.client.SimpleClientHttpRequestFactory; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | 10 | /** 11 | * @description: 12 | * @author: dongyang_wu 13 | * @create: 2019-07-31 12:02 14 | */ 15 | @Configuration 16 | public class RestTemplateConfiguration { 17 | 18 | @Bean 19 | public RestTemplate restTemplate(ClientHttpRequestFactory factory) { 20 | return new RestTemplate(factory); 21 | } 22 | 23 | @Bean 24 | public ClientHttpRequestFactory simpleClientHttpRequestFactory() { 25 | SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); 26 | //单位为ms 27 | factory.setReadTimeout(5000); 28 | //单位为ms 29 | factory.setConnectTimeout(5000); 30 | return factory; 31 | } 32 | } -------------------------------------------------------------------------------- /aiops-core/aiops-core-boot/src/main/java/com/coocaa/core/boot/config/RetryConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.boot.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.retry.interceptor.RetryInterceptorBuilder; 8 | import org.springframework.retry.interceptor.RetryOperationsInterceptor; 9 | 10 | /** 11 | * 重试机制 12 | * 13 | * @author dongyang_wu 14 | */ 15 | @Slf4j 16 | @Configuration 17 | public class RetryConfiguration { 18 | 19 | @Bean 20 | @ConditionalOnMissingBean(name = "configServerRetryInterceptor") 21 | public RetryOperationsInterceptor configServerRetryInterceptor() { 22 | log.info(String.format( 23 | "configServerRetryInterceptor: Changing backOffOptions " + 24 | "to initial: %s, multiplier: %s, maxInterval: %s", 25 | 1000, 1.2, 5000)); 26 | return RetryInterceptorBuilder 27 | .stateless() 28 | .backOffOptions(1000, 1.2, 5000) 29 | .maxAttempts(10) 30 | .build(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-boot/src/main/java/com/coocaa/core/boot/props/AsyncProperties.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.boot.props; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | 7 | /** 8 | * 异步配置 9 | * @author dongyang_wu 10 | */ 11 | @Getter 12 | @Setter 13 | @ConfigurationProperties("blade.async") 14 | public class AsyncProperties { 15 | /** 16 | * 异步核心线程数,默认:2 17 | */ 18 | private int corePoolSize = 2; 19 | /** 20 | * 异步最大线程数,默认:50 21 | */ 22 | private int maxPoolSize = 50; 23 | /** 24 | * 队列容量,默认:10000 25 | */ 26 | private int queueCapacity = 10000; 27 | /** 28 | * 线程存活时间,默认:300 29 | */ 30 | private int keepAliveSeconds = 300; 31 | } 32 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-boot/src/main/java/com/coocaa/core/boot/resolver/TokenArgumentResolver.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.boot.resolver; 2 | 3 | import com.coocaa.core.secure.AiOpsUser; 4 | import com.coocaa.core.secure.utils.SecureUtil; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.core.MethodParameter; 7 | import org.springframework.web.bind.support.WebDataBinderFactory; 8 | import org.springframework.web.context.request.NativeWebRequest; 9 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 10 | import org.springframework.web.method.support.ModelAndViewContainer; 11 | 12 | /** 13 | * Token转化AiopsUser 14 | * 15 | * @author dongyang_wu 16 | */ 17 | @Slf4j 18 | public class TokenArgumentResolver implements HandlerMethodArgumentResolver { 19 | 20 | /** 21 | * 入参筛选 22 | * 23 | * @param methodParameter 参数集合 24 | * @return 格式化后的参数 25 | */ 26 | @Override 27 | public boolean supportsParameter(MethodParameter methodParameter) { 28 | return methodParameter.getParameterType().equals(AiOpsUser.class); 29 | } 30 | 31 | /** 32 | * 出参设置 33 | * 34 | * @param methodParameter 入参集合 35 | * @param modelAndViewContainer model 和 view 36 | * @param nativeWebRequest web相关 37 | * @param webDataBinderFactory 入参解析 38 | * @return 包装对象 39 | */ 40 | @Override 41 | public Object resolveArgument(MethodParameter methodParameter, 42 | ModelAndViewContainer modelAndViewContainer, 43 | NativeWebRequest nativeWebRequest, 44 | WebDataBinderFactory webDataBinderFactory) { 45 | return SecureUtil.getUser(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-boot/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////// 2 | // _ooOoo_ // 3 | // o8888888o // 4 | // 88" . "88 // 5 | // (| ^_^ |) // 6 | // O\ = /O // 7 | // ____/`---'\____ // 8 | // .' \\| |// `. // 9 | // / \\||| : |||// \ // 10 | // / _||||| -:- |||||- \ // 11 | // | | \\\ - /// | | // 12 | // | \_| ''\---/'' | | // 13 | // \ .-\__ `-` ___/-. / // 14 | // ___`. .' /--.--\ `. . ___ // 15 | // ."" '< `.___\_<|>_/___.' >'"". // 16 | // | | : `- \`.;`\ _ /`;.`/ - ` : | | // 17 | // \ \ `-. \_ __\ /__ _/ .-` / / // 18 | // ========`-.____`-.___\_____/___.-`____.-'======== // 19 | // `=---=' // 20 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // 21 | // 佛祖保佑 永不宕机 永无BUG // 22 | //////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------- /aiops-core/aiops-core-boot/src/main/resources/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vipsql/AIOPS/7acff6391a99f50df71c905753859b2ed5881650/aiops-core/aiops-core-boot/src/main/resources/static/favicon.ico -------------------------------------------------------------------------------- /aiops-core/aiops-core-cloud/src/main/java/com/coocaa/core/cloud/config/FeignConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.cloud.config; 2 | 3 | import com.coocaa.core.cloud.feign.FeignHystrixConcurrencyStrategy; 4 | import com.coocaa.core.cloud.feign.FeignRequestHeaderInterceptor; 5 | import feign.RequestInterceptor; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 8 | import org.springframework.cache.annotation.EnableCaching; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.core.Ordered; 12 | import org.springframework.core.annotation.Order; 13 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 14 | 15 | /** 16 | * WEB配置 17 | * 18 | * @author dongyang_wu 19 | */ 20 | @Slf4j 21 | @Configuration 22 | @EnableCaching 23 | @Order(Ordered.HIGHEST_PRECEDENCE) 24 | public class FeignConfiguration implements WebMvcConfigurer { 25 | 26 | @Bean 27 | @ConditionalOnMissingBean 28 | public RequestInterceptor requestInterceptor() { 29 | return new FeignRequestHeaderInterceptor(); 30 | } 31 | 32 | @Bean 33 | public FeignHystrixConcurrencyStrategy feignHystrixConcurrencyStrategy() { 34 | return new FeignHystrixConcurrencyStrategy(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.coocaa 7 | aiops-core 8 | 2.3.1 9 | 10 | 4.0.0 11 | 12 | aiops-core-log 13 | ${project.artifactId} 14 | ${aiops.tool.version} 15 | jar 16 | 17 | 18 | 19 | com.coocaa 20 | aiops-core-tool 21 | ${aiops.tool.version} 22 | 23 | 24 | com.coocaa 25 | aiops-core-secure 26 | ${aiops.tool.version} 27 | 28 | 29 | com.coocaa 30 | aiops-core-cloud 31 | ${aiops.tool.version} 32 | 33 | 34 | 35 | com.baomidou 36 | mybatis-plus 37 | ${mybatis.plus.version} 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/annotation/ApiLog.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 操作日志注解 7 | * 8 | * @author dongyang_wu 9 | */ 10 | @Target(ElementType.METHOD) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | public @interface ApiLog { 14 | 15 | /** 16 | * 日志描述 17 | * 18 | * @return {String} 19 | */ 20 | String value() default "日志记录"; 21 | } 22 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/aspect/ApiLogAspect.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.aspect; 2 | 3 | import com.coocaa.core.log.annotation.ApiLog; 4 | import com.coocaa.core.log.publisher.ApiLogPublisher; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.aspectj.lang.ProceedingJoinPoint; 7 | import org.aspectj.lang.annotation.Around; 8 | import org.aspectj.lang.annotation.Aspect; 9 | 10 | /** 11 | * 操作日志使用spring event异步入库 12 | * 13 | * @author dongyang_wu 14 | */ 15 | @Slf4j 16 | @Aspect 17 | public class ApiLogAspect { 18 | 19 | @Around("@annotation(apiLog)") 20 | public Object around(ProceedingJoinPoint point, ApiLog apiLog) throws Throwable { 21 | //获取类名 22 | String className = point.getTarget().getClass().getName(); 23 | //获取方法 24 | String methodName = point.getSignature().getName(); 25 | // 发送异步日志事件 26 | long beginTime = System.currentTimeMillis(); 27 | //执行方法 28 | Object result = point.proceed(); 29 | //执行时长(毫秒) 30 | long time = System.currentTimeMillis() - beginTime; 31 | //记录日志 32 | ApiLogPublisher.publishEvent(methodName, className, apiLog, time); 33 | return result; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/config/AiopsLogToolAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.config; 2 | 3 | import com.coocaa.core.log.aspect.ApiLogAspect; 4 | import com.coocaa.core.log.event.*; 5 | import com.coocaa.core.log.logger.AiOpsLogger; 6 | import com.coocaa.core.log.props.AiopsProperties; 7 | import com.coocaa.core.log.server.ServerInfo; 8 | import com.coocaa.core.log.feign.ILogClient; 9 | import lombok.AllArgsConstructor; 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | /** 15 | * 日志工具自动配置 16 | * 17 | * @author dongyang_wu 18 | */ 19 | @Configuration 20 | @AllArgsConstructor 21 | @ConditionalOnWebApplication 22 | public class AiopsLogToolAutoConfiguration { 23 | 24 | private final ILogClient logService; 25 | private final ServerInfo serverInfo; 26 | private final AiopsProperties aiopsProperties; 27 | 28 | @Bean 29 | public ApiLogAspect apiLogAspect() { 30 | return new ApiLogAspect(); 31 | } 32 | 33 | @Bean 34 | public AiOpsLogger bladeLogger() { 35 | return new AiOpsLogger(); 36 | } 37 | 38 | @Bean 39 | public ApiLogListener apiLogListener() { 40 | return new ApiLogListener(logService, serverInfo, aiopsProperties); 41 | } 42 | 43 | @Bean 44 | public ErrorLogListener errorEventListener() { 45 | return new ErrorLogListener(logService, serverInfo, aiopsProperties); 46 | } 47 | 48 | @Bean 49 | public UsualLogListener bladeEventListener() { 50 | return new UsualLogListener(logService, serverInfo, aiopsProperties); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/constant/EventConstant.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.constant; 17 | 18 | /** 19 | * 事件常量 20 | * 21 | * @author Chill 22 | */ 23 | public interface EventConstant { 24 | 25 | /** 26 | * log 27 | */ 28 | String EVENT_LOG = "log"; 29 | /** 30 | * request 31 | */ 32 | String EVENT_REQUEST = "request"; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/error/AiopsErrorController.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.error; 2 | 3 | import com.coocaa.core.tool.jackson.JsonUtil; 4 | import org.springframework.boot.autoconfigure.web.ErrorProperties; 5 | import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController; 6 | import org.springframework.boot.web.servlet.error.ErrorAttributes; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.web.servlet.ModelAndView; 10 | import org.springframework.web.servlet.view.json.MappingJackson2JsonView; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.util.Map; 15 | 16 | /** 17 | * 更改html请求异常为ajax 18 | * 19 | * @author dongyang_wu 20 | */ 21 | public class AiopsErrorController extends BasicErrorController { 22 | 23 | public AiopsErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties) { 24 | super(errorAttributes, errorProperties); 25 | } 26 | 27 | @Override 28 | public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) { 29 | Map body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL)); 30 | HttpStatus status = getStatus(request); 31 | response.setStatus(status.value()); 32 | MappingJackson2JsonView view = new MappingJackson2JsonView(); 33 | view.setObjectMapper(JsonUtil.getInstance()); 34 | view.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); 35 | return new ModelAndView(view, body); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/event/ApiLogEvent.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.event; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * 系统日志事件 9 | * 10 | * @author dongyang_wu 11 | */ 12 | public class ApiLogEvent extends ApplicationEvent { 13 | 14 | public ApiLogEvent(Map source) { 15 | super(source); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/event/ApiLogListener.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.event; 2 | 3 | import com.coocaa.core.log.feign.ILogClient; 4 | import com.coocaa.core.log.props.AiopsProperties; 5 | import com.coocaa.core.log.server.ServerInfo; 6 | import com.coocaa.core.log.constant.EventConstant; 7 | import com.coocaa.core.log.model.LogApi; 8 | import com.coocaa.core.log.utils.LogAbstractUtil; 9 | import lombok.AllArgsConstructor; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.context.event.EventListener; 12 | import org.springframework.core.annotation.Order; 13 | import org.springframework.scheduling.annotation.Async; 14 | 15 | import java.util.Map; 16 | 17 | 18 | /** 19 | * 异步监听日志事件 20 | * 21 | * @author dongyang_wu 22 | */ 23 | @Slf4j 24 | @AllArgsConstructor 25 | public class ApiLogListener { 26 | 27 | private final ILogClient logService; 28 | private final ServerInfo serverInfo; 29 | private final AiopsProperties aiopsProperties; 30 | 31 | 32 | @Async 33 | @Order 34 | @EventListener(ApiLogEvent.class) 35 | public void saveApiLog(ApiLogEvent event) { 36 | Map source = (Map) event.getSource(); 37 | LogApi logApi = (LogApi) source.get(EventConstant.EVENT_LOG); 38 | LogAbstractUtil.addOtherInfoToLog(logApi, aiopsProperties, serverInfo); 39 | logService.saveApiLog(logApi); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/event/ErrorLogEvent.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.event; 2 | 3 | 4 | import org.springframework.context.ApplicationEvent; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * 错误日志事件 10 | * 11 | * @author dongyang_wu 12 | */ 13 | public class ErrorLogEvent extends ApplicationEvent { 14 | 15 | public ErrorLogEvent(Map source) { 16 | super(source); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/event/ErrorLogListener.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.event; 2 | import com.coocaa.core.log.feign.ILogClient; 3 | import com.coocaa.core.log.props.AiopsProperties; 4 | import com.coocaa.core.log.server.ServerInfo; 5 | import com.coocaa.core.log.constant.EventConstant; 6 | import com.coocaa.core.log.model.LogError; 7 | import com.coocaa.core.log.utils.LogAbstractUtil; 8 | import lombok.AllArgsConstructor; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.context.event.EventListener; 11 | import org.springframework.core.annotation.Order; 12 | import org.springframework.scheduling.annotation.Async; 13 | 14 | import java.util.Map; 15 | 16 | /** 17 | * 异步监听错误日志事件 18 | * 19 | * @author dongyang_wu 20 | */ 21 | @Slf4j 22 | @AllArgsConstructor 23 | public class ErrorLogListener { 24 | 25 | private final ILogClient logService; 26 | private final ServerInfo serverInfo; 27 | private final AiopsProperties aiopsProperties; 28 | 29 | @Async 30 | @Order 31 | @EventListener(ErrorLogEvent.class) 32 | public void saveErrorLog(ErrorLogEvent event) { 33 | Map source = (Map) event.getSource(); 34 | LogError logError = (LogError) source.get(EventConstant.EVENT_LOG); 35 | LogAbstractUtil.addOtherInfoToLog(logError, aiopsProperties, serverInfo); 36 | logService.saveErrorLog(logError); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/event/UsualLogEvent.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.event; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * 系统日志事件 9 | * 10 | * @author dongyang_wu 11 | */ 12 | public class UsualLogEvent extends ApplicationEvent { 13 | 14 | public UsualLogEvent(Map source) { 15 | super(source); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/exception/ApiException.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.exception; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | @Data 7 | @EqualsAndHashCode 8 | public class ApiException extends RuntimeException { 9 | private Integer code; 10 | private String message; 11 | 12 | public ApiException() { 13 | } 14 | 15 | public ApiException(Integer code, String message) { 16 | this.code = code; 17 | this.message = message; 18 | } 19 | 20 | public ApiException(ApiResultEnum apiResultEnum) { 21 | this.message = apiResultEnum.getMessage(); 22 | this.code = apiResultEnum.getCode(); 23 | } 24 | 25 | public ApiException(String message) { 26 | this.message = message; 27 | this.code = 0; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "错误码:" + code + " " + "错误信息:" + message; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/feign/LogClientFallback.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.feign; 2 | 3 | import com.coocaa.core.log.model.*; 4 | import com.coocaa.core.tool.api.R; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * 日志fallback 10 | * 11 | * @author dongyang_wu 12 | */ 13 | @Slf4j 14 | @Component 15 | public class LogClientFallback implements ILogClient { 16 | 17 | @Override 18 | public R saveUsualLog(LogUsual log) { 19 | return R.fail("usual log send fail"); 20 | } 21 | 22 | @Override 23 | public R saveApiLog(LogApi log) { 24 | return R.fail("api log send fail"); 25 | } 26 | 27 | @Override 28 | public R saveErrorLog(LogError log) { 29 | return R.fail("error log send fail"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/logger/AiOpsLogger.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.logger; 2 | 3 | import com.coocaa.core.log.publisher.UsualLogPublisher; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.InitializingBean; 6 | import org.springframework.beans.factory.annotation.Value; 7 | 8 | /** 9 | * 日志工具类 10 | * 11 | * @author dongyang_wu 12 | */ 13 | @Slf4j 14 | public class AiOpsLogger implements InitializingBean { 15 | 16 | @Value("${spring.application.name}") 17 | private String serviceId; 18 | 19 | public void info(String id, String data) { 20 | UsualLogPublisher.publishEvent("info", id, data); 21 | } 22 | 23 | public void debug(String id, String data) { 24 | UsualLogPublisher.publishEvent("debug", id, data); 25 | } 26 | 27 | public void warn(String id, String data) { 28 | UsualLogPublisher.publishEvent("warn", id, data); 29 | } 30 | 31 | public void error(String id, String data) { 32 | UsualLogPublisher.publishEvent("error", id, data); 33 | } 34 | 35 | @Override 36 | public void afterPropertiesSet() throws Exception { 37 | log.info(serviceId + ": AiOpsLogger init success!"); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/model/LogApi.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.model; 2 | 3 | 4 | import com.baomidou.mybatisplus.annotation.TableName; 5 | import lombok.Data; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * 实体类 11 | * 12 | * @author dongyang_wu 13 | */ 14 | @Data 15 | @TableName("log_api") 16 | public class LogApi extends LogAbstract implements Serializable { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * 日志类型 22 | */ 23 | private String type; 24 | /** 25 | * 日志标题 26 | */ 27 | private String title; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/model/LogApiVo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.model; 17 | 18 | import lombok.Data; 19 | import lombok.EqualsAndHashCode; 20 | 21 | /** 22 | * LogApi视图实体类 23 | * 24 | * @author dongyang_wu 25 | */ 26 | @Data 27 | @EqualsAndHashCode(callSuper = true) 28 | public class LogApiVo extends LogApi { 29 | private static final long serialVersionUID = 1L; 30 | 31 | private String strId; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/model/LogError.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.model; 17 | 18 | 19 | import com.baomidou.mybatisplus.annotation.TableName; 20 | import lombok.Data; 21 | 22 | import java.io.Serializable; 23 | 24 | /** 25 | * 服务 异常 26 | * 27 | * @author dongyang_wu 28 | */ 29 | @Data 30 | @TableName("log_error") 31 | public class LogError extends LogAbstract implements Serializable { 32 | 33 | private static final long serialVersionUID = 1L; 34 | 35 | /** 36 | * 堆栈信息 37 | */ 38 | private String stackTrace; 39 | /** 40 | * 异常名 41 | */ 42 | private String exceptionName; 43 | /** 44 | * 异常消息 45 | */ 46 | private String message; 47 | 48 | /** 49 | * 文件名 50 | */ 51 | private String fileName; 52 | 53 | /** 54 | * 代码行数 55 | */ 56 | private Integer lineNumber; 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/model/LogErrorVo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.model; 17 | 18 | import lombok.Data; 19 | import lombok.EqualsAndHashCode; 20 | 21 | /** 22 | * LogError视图实体类 23 | * 24 | * @author dongyang_wu 25 | */ 26 | @Data 27 | @EqualsAndHashCode(callSuper = true) 28 | public class LogErrorVo extends LogError { 29 | private static final long serialVersionUID = 1L; 30 | 31 | private String strId; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/model/LogUsual.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.model; 17 | 18 | 19 | import com.baomidou.mybatisplus.annotation.TableName; 20 | import lombok.Data; 21 | 22 | import java.io.Serializable; 23 | 24 | /** 25 | * 实体类 26 | * 27 | * @author dongyang_wu 28 | * @since 2018-10-12 29 | */ 30 | @Data 31 | @TableName("log_usual") 32 | public class LogUsual extends LogAbstract implements Serializable { 33 | 34 | private static final long serialVersionUID = 1L; 35 | 36 | /** 37 | * 日志级别 38 | */ 39 | private String logLevel; 40 | /** 41 | * 日志业务id 42 | */ 43 | private String logId; 44 | /** 45 | * 日志数据 46 | */ 47 | private String logData; 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/model/LogUsualVo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.model; 17 | 18 | import lombok.Data; 19 | import lombok.EqualsAndHashCode; 20 | 21 | /** 22 | * LogUsual视图实体类 23 | * 24 | * @author dongyang_wu 25 | */ 26 | @Data 27 | @EqualsAndHashCode(callSuper = true) 28 | public class LogUsualVo extends LogUsual { 29 | private static final long serialVersionUID = 1L; 30 | 31 | private String strId; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/publisher/ApiLogPublisher.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.publisher; 2 | 3 | 4 | import com.coocaa.core.log.event.ApiLogEvent; 5 | import com.coocaa.core.log.model.LogApi; 6 | import com.coocaa.core.log.annotation.ApiLog; 7 | import com.coocaa.core.log.constant.EventConstant; 8 | import com.coocaa.core.log.utils.LogAbstractUtil; 9 | import com.coocaa.core.tool.constant.AiOpsConstant; 10 | import com.coocaa.core.tool.utils.SpringUtil; 11 | import com.coocaa.core.tool.utils.WebUtil; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | /** 18 | * API日志信息事件发送 19 | * 20 | * @author dongyang_wu 21 | */ 22 | public class ApiLogPublisher { 23 | 24 | public static void publishEvent(String methodName, String methodClass, ApiLog apiLog, long time) { 25 | HttpServletRequest request = WebUtil.getRequest(); 26 | LogApi logApi = new LogApi(); 27 | logApi.setType(AiOpsConstant.LOG_NORMAL_TYPE); 28 | logApi.setTitle(apiLog.value()); 29 | logApi.setTime(String.valueOf(time)); 30 | logApi.setMethodClass(methodClass); 31 | logApi.setMethodName(methodName); 32 | 33 | LogAbstractUtil.addRequestInfoToLog(request, logApi); 34 | Map event = new HashMap<>(16); 35 | event.put(EventConstant.EVENT_LOG, logApi); 36 | SpringUtil.publishEvent(new ApiLogEvent(event)); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/publisher/UsualLogPublisher.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.publisher; 2 | 3 | 4 | import com.coocaa.core.log.constant.EventConstant; 5 | import com.coocaa.core.log.event.UsualLogEvent; 6 | import com.coocaa.core.log.model.LogUsual; 7 | import com.coocaa.core.log.utils.LogAbstractUtil; 8 | import com.coocaa.core.tool.utils.SpringUtil; 9 | import com.coocaa.core.tool.utils.WebUtil; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | /** 16 | * 日志信息事件发送 17 | * 18 | * @author dongyang_wu 19 | */ 20 | public class UsualLogPublisher { 21 | 22 | public static void publishEvent(String level, String id, String data) { 23 | HttpServletRequest request = WebUtil.getRequest(); 24 | LogUsual logUsual = new LogUsual(); 25 | logUsual.setLogLevel(level); 26 | logUsual.setLogId(id); 27 | logUsual.setLogData(data); 28 | 29 | LogAbstractUtil.addRequestInfoToLog(request, logUsual); 30 | Map event = new HashMap<>(16); 31 | event.put(EventConstant.EVENT_LOG, logUsual); 32 | event.put(EventConstant.EVENT_REQUEST, request); 33 | SpringUtil.publishEvent(new UsualLogEvent(event)); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-log/src/main/java/com/coocaa/core/log/server/ServerInfo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.server; 2 | 3 | import com.coocaa.core.log.utils.INetUtil; 4 | import lombok.Getter; 5 | import org.springframework.beans.factory.SmartInitializingSingleton; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.autoconfigure.web.ServerProperties; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * 服务器信息 12 | * 13 | * @author dongyang_wu 14 | */ 15 | @Getter 16 | @Configuration 17 | public class ServerInfo implements SmartInitializingSingleton { 18 | private final ServerProperties serverProperties; 19 | private String hostName; 20 | private String ip; 21 | private Integer port; 22 | private String ipWithPort; 23 | 24 | @Autowired(required = false) 25 | public ServerInfo(ServerProperties serverProperties) { 26 | this.serverProperties = serverProperties; 27 | } 28 | 29 | @Override 30 | public void afterSingletonsInstantiated() { 31 | this.hostName = INetUtil.getHostName(); 32 | this.ip = INetUtil.getHostIp(); 33 | this.port = serverProperties.getPort(); 34 | this.ipWithPort = String.format("%s:%d", ip, port); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-mybatis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.coocaa 7 | aiops-core 8 | 2.3.1 9 | 10 | 4.0.0 11 | 12 | aiops-core-mybatis 13 | ${project.artifactId} 14 | ${aiops.tool.version} 15 | jar 16 | 17 | 18 | 19 | com.baomidou 20 | mybatis-plus 21 | ${mybatis.plus.version} 22 | 23 | 24 | com.coocaa 25 | aiops-core-secure 26 | ${aiops.tool.version} 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-mybatis/src/main/java/com/coocaa/core/mybatis/AiopsMetaObjectHandler.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.mybatis; 2 | 3 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.apache.ibatis.reflection.MetaObject; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * mybatisplus自定义填充 12 | * 13 | * @author dongyang_wu 14 | */ 15 | @Slf4j 16 | @Component 17 | public class AiopsMetaObjectHandler implements MetaObjectHandler { 18 | 19 | @Override 20 | public void insertFill(MetaObject metaObject) { 21 | // 获取到需要被填充的字段的值 22 | // Object fieldValue = getFieldValByName("createTime", metaObject); 23 | System.err.println("**********插入操作 满足填充条件**********"); 24 | this.setFieldValByName("createTime", new Date(), metaObject); 25 | this.setFieldValByName("updateTime", new Date(), metaObject); 26 | } 27 | 28 | @Override 29 | public void updateFill(MetaObject metaObject) { 30 | // 获取到需要被填充的字段的值 31 | // Object fieldValue = getFieldValByName("updateTime", metaObject); 32 | System.err.println("**********更新操作 满足填充条件**********"); 33 | this.setFieldValByName("updateTime", new Date(), metaObject); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-mybatis/src/main/java/com/coocaa/core/mybatis/base/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.mybatis.base; 2 | 3 | 4 | import com.baomidou.mybatisplus.annotation.TableLogic; 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | import com.coocaa.core.tool.utils.DateUtil; 7 | import io.swagger.annotations.ApiModelProperty; 8 | import lombok.Data; 9 | import org.springframework.format.annotation.DateTimeFormat; 10 | 11 | import java.io.Serializable; 12 | import java.time.LocalDateTime; 13 | 14 | /** 15 | * @description: 基础实体类 16 | * @author: dongyang_wu 17 | * @create: 2019-07-28 22:09 18 | */ 19 | @Data 20 | public class BaseEntity implements Serializable { 21 | 22 | /** 23 | * 创建人 24 | */ 25 | @ApiModelProperty(value = "创建人") 26 | private Integer createUser; 27 | 28 | /** 29 | * 创建时间 30 | */ 31 | @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) 32 | @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) 33 | @ApiModelProperty(value = "创建时间") 34 | private LocalDateTime createTime; 35 | 36 | /** 37 | * 更新人 38 | */ 39 | @ApiModelProperty(value = "更新人") 40 | private Integer updateUser; 41 | 42 | /** 43 | * 更新时间 44 | */ 45 | @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) 46 | @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) 47 | @ApiModelProperty(value = "更新时间") 48 | private LocalDateTime updateTime; 49 | 50 | /** 51 | * 状态[1:正常] 52 | */ 53 | @ApiModelProperty(value = "业务状态") 54 | private Integer status; 55 | 56 | /** 57 | * 状态[0:未删除,1:删除] 58 | */ 59 | @TableLogic 60 | @ApiModelProperty(value = "是否已删除") 61 | private Integer isDeleted; 62 | } 63 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-mybatis/src/main/java/com/coocaa/core/mybatis/base/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.mybatis.base; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.coocaa.common.request.RequestBean; 5 | 6 | import javax.validation.constraints.NotEmpty; 7 | import java.util.List; 8 | 9 | /** 10 | * 基础业务接口 11 | * 12 | * @param 13 | * @author dongyang_wu 14 | */ 15 | public interface BaseService extends IService { 16 | 17 | /** 18 | * 逻辑删除 19 | * 20 | * @param ids id集合(逗号分隔) 21 | * @return 22 | */ 23 | boolean deleteLogic(@NotEmpty List ids); 24 | 25 | /** 26 | * 批量删除 27 | * 28 | * @param requestBean 29 | */ 30 | void deletes(RequestBean requestBean); 31 | } 32 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-mybatis/src/main/java/com/coocaa/core/mybatis/support/Query.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.mybatis.support; 17 | 18 | import io.swagger.annotations.ApiModel; 19 | import io.swagger.annotations.ApiModelProperty; 20 | import lombok.Data; 21 | import lombok.experimental.Accessors; 22 | 23 | /** 24 | * 分页工具 25 | * 26 | * @author dongyang_wu 27 | */ 28 | @Data 29 | @Accessors(chain = true) 30 | @ApiModel(description = "查询条件") 31 | public class Query { 32 | 33 | /** 34 | * 当前页 35 | */ 36 | @ApiModelProperty(value = "当前页") 37 | private Integer current; 38 | 39 | /** 40 | * 每页的数量 41 | */ 42 | @ApiModelProperty(value = "每页的数量") 43 | private Integer size; 44 | 45 | /** 46 | * 排序的字段名 47 | */ 48 | @ApiModelProperty(hidden = true) 49 | private String ascs; 50 | 51 | /** 52 | * 排序方式 53 | */ 54 | @ApiModelProperty(hidden = true) 55 | private String descs; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-mybatis/src/main/java/io/jsonwebtoken/impl/Base64Codec.java: -------------------------------------------------------------------------------- 1 | package io.jsonwebtoken.impl; 2 | 3 | import java.util.Base64; 4 | 5 | /** 6 | * Base64Codec 7 | * 8 | * @author jjwt 9 | */ 10 | public class Base64Codec extends AbstractTextCodec { 11 | 12 | @Override 13 | public String encode(byte[] data) { 14 | return Base64.getEncoder().encodeToString(data); 15 | } 16 | 17 | @Override 18 | public byte[] decode(String encoded) { 19 | return Base64.getDecoder().decode(encoded); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-secure/src/main/java/com/coocaa/core/secure/AiOpsUser.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.secure; 2 | 3 | import io.swagger.annotations.ApiModelProperty; 4 | import lombok.*; 5 | 6 | 7 | /** 8 | * 用户实体 9 | * 10 | * @author dongyang_wu 11 | */ 12 | @Data 13 | @Builder 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | public class AiOpsUser { 17 | 18 | /** 19 | * 用户id 20 | */ 21 | @ApiModelProperty(hidden = true) 22 | private Long userId; 23 | /** 24 | * 昵称 25 | */ 26 | @ApiModelProperty(hidden = true) 27 | private String userName; 28 | /** 29 | * 账号 30 | */ 31 | @ApiModelProperty(hidden = true) 32 | private String account; 33 | /** 34 | * 角色id 35 | */ 36 | @ApiModelProperty(hidden = true) 37 | private String roleId; 38 | /** 39 | * 角色名 40 | */ 41 | @ApiModelProperty(hidden = true) 42 | private String roleName; 43 | /** 44 | * 用户所属Team 45 | */ 46 | @ApiModelProperty(hidden = true) 47 | private String teamIds; 48 | } 49 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-secure/src/main/java/com/coocaa/core/secure/AuthInfo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.secure; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * AuthInfo 9 | * 10 | * @author dongyang_wu 11 | */ 12 | @Data 13 | @ApiModel(description = "认证信息") 14 | public class AuthInfo { 15 | @ApiModelProperty(value = "令牌") 16 | private String accessToken; 17 | @ApiModelProperty(value = "令牌类型") 18 | private String tokenType; 19 | @ApiModelProperty(value = "头像") 20 | private String avatar = "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png"; 21 | @ApiModelProperty(value = "角色名") 22 | private String authority; 23 | @ApiModelProperty(value = "用户名") 24 | private String userName; 25 | @ApiModelProperty(value = "账号名") 26 | private String account; 27 | @ApiModelProperty(value = "过期时间") 28 | private long expiresIn; 29 | @ApiModelProperty(value = "许可证") 30 | private String license = "powered by ronghui"; 31 | } 32 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-secure/src/main/java/com/coocaa/core/secure/config/LdapConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.secure.config; 2 | 3 | import com.coocaa.core.secure.utils.LdapUtil; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * @description: 域账号登录 9 | * @author: dongyang_wu 10 | * @create: 2019-07-30 18:49 11 | */ 12 | @Component 13 | public class LdapConfiguration { 14 | @Bean 15 | public LdapUtil getLdapUtil() { 16 | return new LdapUtil(); 17 | }} -------------------------------------------------------------------------------- /aiops-core/aiops-core-secure/src/main/java/com/coocaa/core/secure/config/RegistryConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.secure.config; 17 | 18 | 19 | import com.coocaa.core.secure.registry.SecureRegistry; 20 | import org.springframework.boot.autoconfigure.AutoConfigureBefore; 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | import org.springframework.core.annotation.Order; 25 | 26 | /** 27 | * secure注册默认配置 28 | * 29 | * @author dongyang_wu 30 | */ 31 | @Order 32 | @Configuration 33 | @AutoConfigureBefore(SecureConfiguration.class) 34 | public class RegistryConfiguration { 35 | 36 | @Bean 37 | @ConditionalOnMissingBean(SecureRegistry.class) 38 | public SecureRegistry secureRegistry() { 39 | return new SecureRegistry(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-secure/src/main/java/com/coocaa/core/secure/config/SecureConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.secure.config; 2 | 3 | 4 | import com.coocaa.core.secure.interceptor.SecureInterceptor; 5 | import com.coocaa.core.secure.registry.SecureRegistry; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.core.annotation.Order; 9 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 11 | 12 | /** 13 | * 安全配置类 14 | * 15 | * @author dongyang_wu 16 | */ 17 | @Order 18 | @Configuration 19 | @AllArgsConstructor 20 | public class SecureConfiguration implements WebMvcConfigurer { 21 | private SecureRegistry secureRegistry; 22 | 23 | @Override 24 | public void addInterceptors(InterceptorRegistry registry) { 25 | 26 | if (secureRegistry.isEnable()) { 27 | registry.addInterceptor(new SecureInterceptor()) 28 | .excludePathPatterns(secureRegistry.getExcludePatterns()) 29 | .excludePathPatterns(secureRegistry.getDefaultExcludePatterns()); 30 | } 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-secure/src/main/java/com/coocaa/core/secure/constant/SecureConstant.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.secure.constant; 2 | 3 | /** 4 | * 授权校验常量 5 | * 6 | * @author dongyang_wu 7 | */ 8 | public interface SecureConstant { 9 | 10 | /** 11 | * 认证请求头 12 | */ 13 | String BASIC_HEADER_KEY = "Authorization"; 14 | 15 | /** 16 | * 认证请求头前缀 17 | */ 18 | String BASIC_HEADER_PREFIX = "Basic "; 19 | 20 | /** 21 | * blade_client表字段 22 | */ 23 | String CLIENT_FIELDS = "client_id, client_secret, access_token_validity, refresh_token_validity"; 24 | 25 | /** 26 | * blade_client查询语句 27 | */ 28 | String BASE_STATEMENT = "select " + CLIENT_FIELDS + " from blade_client"; 29 | 30 | /** 31 | * blade_client查询排序 32 | */ 33 | String DEFAULT_FIND_STATEMENT = BASE_STATEMENT + " order by client_id"; 34 | 35 | /** 36 | * 查询client_id 37 | */ 38 | String DEFAULT_SELECT_STATEMENT = BASE_STATEMENT + " where client_id = ?"; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-secure/src/main/java/com/coocaa/core/secure/constant/TokenConstant.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.secure.constant; 2 | 3 | /** 4 | * Token配置常量. 5 | * 6 | * @author dongyang_wu 7 | */ 8 | public interface TokenConstant { 9 | 10 | String SIGN_KEY = "Blade"; 11 | String AVATAR = "avatar"; 12 | String HEADER = "AIOPS-TOKEN"; 13 | String BEARER = "bearer"; 14 | String ACCESS_TOKEN = "access_token"; 15 | String REFRESH_TOKEN = "refresh_token"; 16 | String TOKEN_TYPE = "token_type"; 17 | String EXPIRES_IN = "expires_in"; 18 | String ACCOUNT = "account"; 19 | String USER_ID = "user_id"; 20 | String ROLE_ID = "role_id"; 21 | String TEAM_IDS = "team_ids"; 22 | String USER_NAME = "user_name"; 23 | String ROLE_NAME = "role_name"; 24 | String TENANT_CODE = "tenant_code"; 25 | String CLIENT_ID = "client_id"; 26 | String LICENSE = "license"; 27 | String LICENSE_NAME = "powered by blade"; 28 | String DEFAULT_AVATAR = "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png"; 29 | Integer AUTH_LENGTH = 7; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-secure/src/main/java/com/coocaa/core/secure/exception/SecureException.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.secure.exception; 2 | 3 | import com.coocaa.core.tool.api.IResultCode; 4 | import com.coocaa.core.tool.api.ResultCode; 5 | import lombok.Getter; 6 | 7 | /** 8 | * Secure异常 9 | * 10 | * @author dongyang_wu 11 | */ 12 | public class SecureException extends RuntimeException { 13 | private static final long serialVersionUID = 2359767895161832954L; 14 | 15 | @Getter 16 | private final IResultCode resultCode; 17 | 18 | public SecureException(String message) { 19 | super(message); 20 | this.resultCode = ResultCode.UN_AUTHORIZED; 21 | } 22 | 23 | public SecureException(IResultCode resultCode) { 24 | super(resultCode.getMessage()); 25 | this.resultCode = resultCode; 26 | } 27 | 28 | public SecureException(IResultCode resultCode, Throwable cause) { 29 | super(cause); 30 | this.resultCode = resultCode; 31 | } 32 | 33 | @Override 34 | public Throwable fillInStackTrace() { 35 | return this; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/api/IResultCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.api; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * 业务代码接口 22 | * 23 | * @author dongyang_wu 24 | */ 25 | public interface IResultCode extends Serializable { 26 | 27 | /** 28 | * 消息 29 | * 30 | * @return String 31 | */ 32 | String getMessage(); 33 | 34 | /** 35 | * 状态码 36 | * 37 | * @return int 38 | */ 39 | int getCode(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/base/BaseException.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.base; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * @Auther: wyx 7 | * @Date: 2019-07-25 15:29 8 | * @Description: 基础异常 9 | */ 10 | @Getter 11 | public class BaseException extends RuntimeException { 12 | 13 | private Integer code; 14 | 15 | private String msg; 16 | 17 | public BaseException(Integer code, String msg){ 18 | this.code = code; 19 | this.msg = msg; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/constant/RoleConstant.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.constant; 17 | 18 | /** 19 | * 系统默认角色 20 | * 21 | * @author dongyang_wu 22 | */ 23 | public class RoleConstant { 24 | 25 | public static final String ADMIN = "administrator"; 26 | 27 | public static final String HAS_ROLE_ADMIN = "hasRole('" + ADMIN + "')"; 28 | 29 | public static final String USER = "user"; 30 | 31 | public static final String HAS_ROLE_USER = "hasRole('" + USER + "')"; 32 | 33 | public static final String TEST = "test"; 34 | 35 | public static final String HAS_ROLE_TEST = "hasRole('" + TEST + "')"; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/exception/ExceptionResolver.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.exception; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * @description: 8 | * @author: dongyang_wu 9 | * @create: 2019-07-30 22:46 10 | */ 11 | @Slf4j 12 | @Configuration 13 | public class ExceptionResolver { 14 | } -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/node/BaseNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.node; 17 | 18 | import com.fasterxml.jackson.annotation.JsonInclude; 19 | import lombok.Data; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** 25 | * 节点基类 26 | * 27 | * @author Chill 28 | */ 29 | @Data 30 | public class BaseNode implements INode { 31 | 32 | /** 33 | * 主键ID 34 | */ 35 | protected Integer id; 36 | 37 | /** 38 | * 父节点ID 39 | */ 40 | protected Integer parentId; 41 | 42 | /** 43 | * 子孙节点 44 | */ 45 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 46 | protected List children = new ArrayList<>(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/node/ForestNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.node; 17 | 18 | import lombok.Data; 19 | import lombok.EqualsAndHashCode; 20 | 21 | 22 | /** 23 | * 森林节点类 24 | * 25 | * @author Chill 26 | */ 27 | @Data 28 | @EqualsAndHashCode(callSuper = false) 29 | public class ForestNode extends BaseNode { 30 | 31 | /** 32 | * 节点内容 33 | */ 34 | private Object content; 35 | 36 | public ForestNode(Integer id, Integer parentId, Object content) { 37 | this.id = id; 38 | this.parentId = parentId; 39 | this.content = content; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/node/ForestNodeMerger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.node; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * 森林节点归并类 22 | * 23 | * @author Chill 24 | */ 25 | public class ForestNodeMerger { 26 | 27 | /** 28 | * 将节点数组归并为一个森林(多棵树)(填充节点的children域) 29 | * 时间复杂度为O(n^2) 30 | * 31 | * @param items 节点域 32 | * @param T 泛型标记 33 | * @return 多棵树的根节点集合 34 | */ 35 | public static List merge(List items) { 36 | ForestNodeManager forestNodeManager = new ForestNodeManager<>(items); 37 | items.forEach(forestNode -> { 38 | if (forestNode.getParentId() != 0) { 39 | INode node = forestNodeManager.getTreeNodeAT(forestNode.getParentId()); 40 | if (node != null) { 41 | node.getChildren().add(forestNode); 42 | } else { 43 | forestNodeManager.addParentId(forestNode.getId()); 44 | } 45 | } 46 | }); 47 | return forestNodeManager.getRoot(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/node/INode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.node; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * Created by Blade. 22 | * 23 | * @author Chill 24 | */ 25 | public interface INode { 26 | 27 | /** 28 | * 主键 29 | * 30 | * @return Integer 31 | */ 32 | Integer getId(); 33 | 34 | /** 35 | * 父主键 36 | * 37 | * @return Integer 38 | */ 39 | Integer getParentId(); 40 | 41 | /** 42 | * 子孙节点 43 | * 44 | * @return List 45 | */ 46 | List getChildren(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/node/NodeTest.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.node; 2 | 3 | 4 | import com.coocaa.core.tool.jackson.JsonUtil; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by Blade. 11 | * 12 | * @author Chill 13 | */ 14 | public class NodeTest { 15 | 16 | public static void main(String[] args) { 17 | List list = new ArrayList<>(); 18 | list.add(new ForestNode(1, 0, "1")); 19 | list.add(new ForestNode(2, 0, "2")); 20 | list.add(new ForestNode(3, 1, "3")); 21 | list.add(new ForestNode(4, 2, "4")); 22 | list.add(new ForestNode(5, 3, "5")); 23 | list.add(new ForestNode(6, 4, "6")); 24 | list.add(new ForestNode(7, 3, "7")); 25 | list.add(new ForestNode(8, 5, "8")); 26 | list.add(new ForestNode(9, 6, "9")); 27 | list.add(new ForestNode(10, 9, "10")); 28 | List tns = ForestNodeMerger.merge(list); 29 | tns.forEach(node -> 30 | System.out.println(JsonUtil.toJson(node)) 31 | ); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/node/TreeNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.node; 17 | 18 | import lombok.Data; 19 | import lombok.EqualsAndHashCode; 20 | 21 | /** 22 | * 树型节点类 23 | * 24 | * @author Chill 25 | */ 26 | @Data 27 | @EqualsAndHashCode(callSuper = false) 28 | public class TreeNode extends BaseNode { 29 | 30 | private String title; 31 | 32 | private Integer key; 33 | 34 | private Integer value; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/response/CodeEnum.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.response; 2 | 3 | /** 4 | * @Auther: wyx 5 | * @Date: 2019-07-22 15:07 6 | * @Description: 返回码枚举类 7 | */ 8 | public enum CodeEnum { 9 | 10 | REQUEST_SUCCESS(1001, "请求成功"), 11 | UN_KNOW_ERROR(2001, "未知异常"), 12 | PARAM_ILLEGAL(2002, "参数异常"), 13 | DATABASE_OPERATE_FAILURE(2003, "数据库操作异常"), 14 | NO_DATA(2004, "所查找数据不存在"), 15 | SYSTEM_ERROR(2005, "系统错误"), 16 | TOKEN_INVALID(2006, "登录失效"), 17 | PROMETHEUS_QUERY_ERROR(2007, "Prometheus 查询错误"); 18 | 19 | private Integer code; 20 | 21 | private String msg; 22 | 23 | CodeEnum(Integer code, String msg){ 24 | this.code = code; 25 | this.msg = msg; 26 | } 27 | 28 | public Integer getCode(){ 29 | return code; 30 | } 31 | 32 | public String getMsg(){ 33 | return msg; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/response/Constant.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.response; 2 | 3 | /** 4 | * @Auther: wyx 5 | * @Date: 2019-07-26 10:52 6 | * @Description: 常量对照 7 | */ 8 | public class Constant { 9 | 10 | public static final String JWT_TIMEOUT = "jwtTimeout"; 11 | 12 | public static final String JWT_VERIFY_SUCCESS = "jwtVerifySuccess"; 13 | 14 | public static final String REDIS_USER_PREFFIX = "userId_"; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/response/PromNorm.java: -------------------------------------------------------------------------------- 1 | package com.monitoring.data_manipulation.common; 2 | 3 | /** 4 | * @Auther: wyx 5 | * @Date: 2019-07-27 23:44 6 | * @Description: 要监控的指标 7 | */ 8 | public class PromNorm { 9 | 10 | /** 11 | * 请求总数 12 | */ 13 | public static final String REQUEST_TOTAL = "http_requests_total"; 14 | 15 | /** 16 | * CPU 一分钟内平均负载 17 | */ 18 | public static final String CPU_LOAD = "node_load1"; 19 | 20 | /** 21 | * 磁盘总容量 22 | */ 23 | public static final String DISK_TOTAL_CAPACITY = "node_filesystem_size_bytes"; 24 | 25 | /** 26 | * 磁盘剩余容量 27 | */ 28 | public static final String DISK_FREE_CAPACITY = "node_filesystem_free_bytes"; 29 | 30 | /** 31 | * 磁盘使用率 32 | */ 33 | public static final String DISK_USED_RATE = "node_filesystem_used_rate"; 34 | 35 | /** 36 | * 上传带宽 37 | */ 38 | public static final String UPLOAD_BAND_WIDTH = "sum(irate(node_network_receive_bytes_total{device!~\"bond.*?|lo\"}[5m])/128)"; 39 | 40 | /** 41 | * 下载带宽 42 | */ 43 | public static final String DOWNLOAD_BAND_WIDTH = "sum(irate(node_network_transmit_bytes_total{device!~\"bond.*?|lo\"}[5m])/128)"; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/response/ReturnData.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.response; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Auther: wyx 7 | * @Date: 2019-07-22 15:22 8 | * @Description: 封装返回值 9 | */ 10 | @Data 11 | public class ReturnData { 12 | 13 | private Integer code; 14 | 15 | private String msg; 16 | 17 | private Object data; 18 | 19 | private ReturnData(Integer code, String msg, Object data){ 20 | this.code = code; 21 | this.msg = msg; 22 | this.data = data; 23 | } 24 | 25 | private ReturnData(Integer code, String msg){ 26 | this.code = code; 27 | this.msg = msg; 28 | } 29 | 30 | public static ReturnData success(){ 31 | return new ReturnData(CodeEnum.REQUEST_SUCCESS.getCode(), CodeEnum.REQUEST_SUCCESS.getMsg()); 32 | } 33 | 34 | public static ReturnData success(Object data){ 35 | return new ReturnData(CodeEnum.REQUEST_SUCCESS.getCode(), CodeEnum.REQUEST_SUCCESS.getMsg(), data); 36 | } 37 | 38 | public static ReturnData fail(Integer code, String msg){ 39 | return new ReturnData(code, msg); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/response/WarnStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.response; 2 | 3 | /** 4 | * @author 陈煜坤 5 | * @date 2019/7/24 14:07 6 | * @package_name com.monitoring.data_manipulation.common 7 | */ 8 | public enum WarnStatusEnum { 9 | 10 | OK(0), 11 | FAIL(500); 12 | 13 | private int code ; 14 | 15 | WarnStatusEnum(int code) { 16 | this.code=code; 17 | } 18 | 19 | public int getCode() { 20 | return code; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/singleton/SingleTonContextEnum.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.singleton; 2 | 3 | import com.coocaa.core.tool.utils.IpUtil; 4 | import com.coocaa.core.tool.utils.SpringUtil; 5 | import lombok.Getter; 6 | 7 | /** 8 | * @author: dongyang_wu 9 | * @create: 2019-08-29 10:23 10 | * @description: 枚举单例 11 | */ 12 | public enum SingleTonContextEnum { 13 | INSTANCE; 14 | @Getter 15 | private IpUtil ipUtil; 16 | 17 | SingleTonContextEnum() { 18 | ipUtil = SpringUtil.getBean(IpUtil.class); 19 | } 20 | } -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/support/BeanProperty.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.support; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | /** 7 | * Bean属性 8 | * 9 | * @author Chill 10 | */ 11 | @Getter 12 | @AllArgsConstructor 13 | public class BeanProperty { 14 | private final String name; 15 | private final Class type; 16 | } 17 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/support/IMultiOutputStream.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.support; 17 | 18 | import java.io.OutputStream; 19 | 20 | /** 21 | * A factory for creating MultiOutputStream objects. 22 | * 23 | * @author Chill 24 | */ 25 | public interface IMultiOutputStream { 26 | 27 | /** 28 | * Builds the output stream. 29 | * 30 | * @param params the params 31 | * @return the output stream 32 | */ 33 | OutputStream buildOutputStream(Integer... params); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/support/Try.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.support; 2 | 3 | 4 | import com.coocaa.core.tool.utils.Exceptions; 5 | 6 | import java.util.Objects; 7 | import java.util.function.Function; 8 | 9 | /** 10 | * 当 Lambda 遇上受检异常 11 | * https://segmentfault.com/a/1190000007832130 12 | * 13 | * @author Chill 14 | */ 15 | public class Try { 16 | 17 | public static Function of(UncheckedFunction mapper) { 18 | Objects.requireNonNull(mapper); 19 | return t -> { 20 | try { 21 | return mapper.apply(t); 22 | } catch (Exception e) { 23 | throw Exceptions.unchecked(e); 24 | } 25 | }; 26 | } 27 | 28 | @FunctionalInterface 29 | public interface UncheckedFunction { 30 | /** 31 | * 调用 32 | * @param t t 33 | * @return R 34 | * @throws Exception Exception 35 | */ 36 | R apply(T t) throws Exception; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/support/xss/XssProperties.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.support.xss; 17 | 18 | import lombok.Data; 19 | import org.springframework.boot.context.properties.ConfigurationProperties; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** 25 | * Xss配置类 26 | * 27 | * @author Chill 28 | */ 29 | @Data 30 | @ConfigurationProperties("blade.xss.url") 31 | public class XssProperties { 32 | 33 | private final List excludePatterns = new ArrayList<>(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/utils/BindingResultUtil.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.utils; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.validation.BindingResult; 5 | import org.springframework.validation.ObjectError; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @Auther: wyx 11 | * @Date: 2019-07-25 15:27 12 | * @Description: BindingResult助手类 13 | */ 14 | @Slf4j 15 | public class BindingResultUtil { 16 | 17 | public static void logError(BindingResult br){ 18 | List ls=br.getAllErrors(); 19 | 20 | for (int i = 0; i < ls.size(); i++) { 21 | log.error(ls.get(i).getDefaultMessage()); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/utils/HelpUtil.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.utils; 2 | 3 | 4 | import com.coocaa.core.tool.base.BaseException; 5 | import com.coocaa.core.tool.response.CodeEnum; 6 | import com.coocaa.core.tool.response.ReturnData; 7 | 8 | /** 9 | * @Auther: wyx 10 | * @Date: 2019-07-25 20:20 11 | * @Description: 通用方法封装 12 | */ 13 | public class HelpUtil { 14 | 15 | /** 16 | * 判断对象是否为空 17 | * @param object 18 | * @return 19 | */ 20 | public static ReturnData checkEmpty(Object object){ 21 | if(object == null){ 22 | throw new BaseException(CodeEnum.NO_DATA.getCode(), CodeEnum.NO_DATA.getMsg()); 23 | } 24 | return ReturnData.success(object); 25 | } 26 | 27 | /** 28 | * 判断字符串是否为空 29 | * @param string 30 | * @return 31 | */ 32 | public static boolean isStringEmpty(String string){ 33 | return !(string != null && !string.isEmpty()); 34 | } 35 | 36 | /** 37 | * 判断数据库操作是否正确 38 | * @param result 39 | * @return 40 | */ 41 | public static ReturnData checkDBResult(boolean result){ 42 | if (result){ 43 | return ReturnData.success(); 44 | } 45 | 46 | throw new BaseException(CodeEnum.DATABASE_OPERATE_FAILURE.getCode(), CodeEnum.DATABASE_OPERATE_FAILURE.getMsg()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/utils/MapUtil.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.tool.utils; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * @program: intelligent-maintenance 7 | * @description: Map工具类 8 | * @author: dongyang_wu 9 | * @create: 2019-08-07 15:29 10 | */ 11 | public class MapUtil { 12 | /** 13 | * 获取map中第一个key 14 | * @param map 15 | * @param 16 | * @param 17 | * @return 18 | */ 19 | public static K getFirstOrNull(Map map) { 20 | K obj = null; 21 | for (Map.Entry entry : map.entrySet()) { 22 | obj = entry.getKey(); 23 | if (obj != null) { 24 | break; 25 | } 26 | } 27 | return obj; 28 | } 29 | } -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/utils/ObjectUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, DreamLu 卢春梦 (qq596392912@gmail.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.utils; 17 | 18 | import org.springframework.lang.Nullable; 19 | 20 | /** 21 | * 对象工具类 22 | * 23 | * @author L.cm 24 | */ 25 | public class ObjectUtil extends org.springframework.util.ObjectUtils { 26 | 27 | /** 28 | * 判断元素不为空 29 | * @param obj object 30 | * @return boolean 31 | */ 32 | public static boolean isNotEmpty(@Nullable Object obj) { 33 | return !ObjectUtil.isEmpty(obj); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /aiops-core/aiops-core-tool/src/main/java/com/coocaa/core/tool/utils/RandomType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, DreamLu 卢春梦 (qq596392912@gmail.com). 3 | *

4 | * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.gnu.org/licenses/lgpl.html 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.tool.utils; 17 | 18 | /** 19 | * 生成的随机数类型 20 | * 21 | * @author L.cm 22 | */ 23 | public enum RandomType { 24 | /** 25 | * INT STRING ALL 26 | */ 27 | INT, STRING, ALL 28 | } 29 | -------------------------------------------------------------------------------- /aiops-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /aiops-gateway/src/main/java/com/coocaa/gateway/GateWayApplication.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 6 | import org.springframework.scheduling.annotation.EnableScheduling; 7 | 8 | @EnableHystrix 9 | @EnableScheduling 10 | @SpringCloudApplication 11 | public class GateWayApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(GateWayApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /aiops-gateway/src/main/java/com/coocaa/gateway/config/GatewayConfig.java: -------------------------------------------------------------------------------- 1 | //package com.monitoring.gateway.config; 2 | // 3 | //import RequestBodyRoutePredicateFactory; 4 | //import org.springframework.context.annotation.Bean; 5 | //import org.springframework.context.annotation.Configuration; 6 | // 7 | ///** 8 | // * @author ace 9 | // * @create 2019/1/27. 10 | // */ 11 | //@Configuration 12 | //public class GatewayConfig { 13 | // @Bean 14 | // RequestBodyRoutePredicateFactory requestBodyRoutePredicateFactory() { 15 | // return new RequestBodyRoutePredicateFactory(); 16 | // } 17 | //} 18 | -------------------------------------------------------------------------------- /aiops-gateway/src/main/java/com/coocaa/gateway/config/RateLimiterConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.gateway.config; 2 | 3 | import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import reactor.core.publisher.Mono; 7 | 8 | /** 9 | * @description: 路由限流配置 10 | * @author: dongyang_wu 11 | * @create: 2019-07-28 21:25 12 | */ 13 | @Configuration 14 | public class RateLimiterConfiguration { 15 | 16 | @Bean(value = "remoteAddrKeyResolver") 17 | public KeyResolver remoteAddrKeyResolver() { 18 | return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /aiops-gateway/src/main/java/com/coocaa/gateway/controller/DiscoveryClientController.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.gateway.controller; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.cloud.client.ServiceInstance; 6 | import org.springframework.cloud.client.discovery.DiscoveryClient; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.*; 10 | 11 | /** 12 | * @description: 服务发现控制器 13 | * @author: dongyang_wu 14 | * @create: 2019-07-28 21:25 15 | */ 16 | @Slf4j 17 | @RestController 18 | @AllArgsConstructor 19 | @RequestMapping("/discovery") 20 | public class DiscoveryClientController { 21 | 22 | private final DiscoveryClient discoveryClient; 23 | 24 | /** 25 | * 获取服务实例 26 | */ 27 | @GetMapping("/instances") 28 | public Map> instances() { 29 | Map> instances = new HashMap<>(16); 30 | List services = discoveryClient.getServices(); 31 | services.forEach(s -> { 32 | List list = discoveryClient.getInstances(s); 33 | instances.put(s, list); 34 | }); 35 | return instances; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /aiops-gateway/src/main/java/com/coocaa/gateway/handler/HystrixFallbackHandler.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.gateway.handler; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.web.reactive.function.BodyInserters; 8 | import org.springframework.web.reactive.function.server.*; 9 | import reactor.core.publisher.Mono; 10 | 11 | /** 12 | * @program: intelligent_maintenance 13 | * @description: Hystrix 降级处理 14 | * @author: dongyang_wu 15 | * @create: 2019-07-28 21:25 16 | */ 17 | @Slf4j 18 | @Component 19 | public class HystrixFallbackHandler implements HandlerFunction { 20 | @Override 21 | public Mono handle(ServerRequest serverRequest) { 22 | log.error("网关执行请求:{}失败,hystrix服务降级处理", serverRequest.uri()); 23 | return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR.value()) 24 | .contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromObject("服务异常")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /aiops-gateway/src/main/java/com/coocaa/gateway/handler/SwaggerResourceHandler.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.gateway.handler; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.reactive.function.BodyInserters; 9 | import org.springframework.web.reactive.function.server.HandlerFunction; 10 | import org.springframework.web.reactive.function.server.ServerRequest; 11 | import org.springframework.web.reactive.function.server.ServerResponse; 12 | import reactor.core.publisher.Mono; 13 | import springfox.documentation.swagger.web.SwaggerResourcesProvider; 14 | 15 | /** 16 | * @program: intelligent_maintenance 17 | * @description: SwaggerResourceHandler 18 | * @author: dongyang_wu 19 | * @create: 2019-07-28 21:25 20 | */ 21 | @Slf4j 22 | @Component 23 | @AllArgsConstructor 24 | public class SwaggerResourceHandler implements HandlerFunction { 25 | private final SwaggerResourcesProvider swaggerResources; 26 | 27 | /** 28 | * Handle the given request. 29 | * 30 | * @param request the request to handler 31 | * @return the response 32 | */ 33 | @Override 34 | public Mono handle(ServerRequest request) { 35 | return ServerResponse.status(HttpStatus.OK) 36 | .contentType(MediaType.APPLICATION_JSON_UTF8) 37 | .body(BodyInserters.fromObject(swaggerResources.get())); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /aiops-gateway/src/main/java/com/coocaa/gateway/handler/SwaggerSecurityHandler.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.gateway.handler; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.reactive.function.BodyInserters; 9 | import org.springframework.web.reactive.function.server.*; 10 | import reactor.core.publisher.Mono; 11 | import springfox.documentation.swagger.web.SecurityConfiguration; 12 | import springfox.documentation.swagger.web.SecurityConfigurationBuilder; 13 | 14 | import java.util.Optional; 15 | 16 | /** 17 | * @program: intelligent_maintenance 18 | * @description: SwaggerSecurityHandler 19 | * @author: dongyang_wu 20 | * @create: 2019-07-28 21:25 21 | */ 22 | @Slf4j 23 | @Component 24 | public class SwaggerSecurityHandler implements HandlerFunction { 25 | @Autowired(required = false) 26 | private SecurityConfiguration securityConfiguration; 27 | 28 | /** 29 | * Handle the given request. 30 | * 31 | * @param request the request to handler 32 | * @return the response 33 | */ 34 | @Override 35 | public Mono handle(ServerRequest request) { 36 | return ServerResponse.status(HttpStatus.OK) 37 | .contentType(MediaType.APPLICATION_JSON_UTF8) 38 | .body(BodyInserters.fromObject( 39 | Optional.ofNullable(securityConfiguration) 40 | .orElse(SecurityConfigurationBuilder.builder().build()))); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /aiops-gateway/src/main/java/com/coocaa/gateway/handler/SwaggerUiHandler.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.gateway.handler; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.reactive.function.BodyInserters; 9 | import org.springframework.web.reactive.function.server.*; 10 | import reactor.core.publisher.Mono; 11 | import springfox.documentation.swagger.web.UiConfiguration; 12 | import springfox.documentation.swagger.web.UiConfigurationBuilder; 13 | 14 | import java.util.Optional; 15 | 16 | /** 17 | * @program: intelligent_maintenance 18 | * @description: SwaggerUiHandler 19 | * @author: dongyang_wu 20 | * @create: 2019-07-28 21:25 21 | */ 22 | @Slf4j 23 | @Component 24 | public class SwaggerUiHandler implements HandlerFunction { 25 | @Autowired(required = false) 26 | private UiConfiguration uiConfiguration; 27 | 28 | /** 29 | * Handle the given request. 30 | * 31 | * @param request the request to handler 32 | * @return the response 33 | */ 34 | @Override 35 | public Mono handle(ServerRequest request) { 36 | return ServerResponse.status(HttpStatus.OK) 37 | .contentType(MediaType.APPLICATION_JSON_UTF8) 38 | .body(BodyInserters.fromObject( 39 | Optional.ofNullable(uiConfiguration) 40 | .orElse(UiConfigurationBuilder.builder().build()))); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /aiops-gateway/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: aiops-gateway 4 | cloud: 5 | nacos: 6 | config: 7 | server-addr: 39.108.106.167:8848 8 | file-extension: yaml 9 | profiles: 10 | active: dev -------------------------------------------------------------------------------- /aiops-service-api/aiops-detector-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.coocaa 7 | aiops-service-api 8 | 2.3.1 9 | 10 | 4.0.0 11 | 12 | aiops-detector-api 13 | ${project.artifactId} 14 | ${aiops.project.version} 15 | jar 16 | 数据检测服务API 17 | 18 | 19 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-detector-api/src/main/java/com/coocaa/detector/entity/Count.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author 陈煜坤 7 | * @date 2019/8/8 11:04 8 | * @package_name com.monitoring.warn.notice.entity 9 | */ 10 | @Data 11 | public class Count { 12 | 13 | private int total_count; 14 | private int negative_count; 15 | private int positive_count; 16 | } 17 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-detector-api/src/main/java/com/coocaa/detector/entity/DetectorResult.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.entity; 2 | 3 | /** 4 | * @program: intelligent_maintenance 5 | * @description: 检测返回值 6 | * @author: dongyang_wu 7 | * @create: 2019-08-02 11:48 8 | */ 9 | public class DetectorResult { 10 | 11 | /** 12 | * code : 0 13 | * msg : 操作成功 14 | * data : {"ret":0,"p":"0.0021384065"} 15 | */ 16 | 17 | private int code; 18 | private String msg; 19 | private DataBean data; 20 | 21 | public int getCode() { 22 | return code; 23 | } 24 | 25 | public void setCode(int code) { 26 | this.code = code; 27 | } 28 | 29 | public String getMsg() { 30 | return msg; 31 | } 32 | 33 | public void setMsg(String msg) { 34 | this.msg = msg; 35 | } 36 | 37 | public DataBean getData() { 38 | return data; 39 | } 40 | 41 | public void setData(DataBean data) { 42 | this.data = data; 43 | } 44 | 45 | public static class DataBean { 46 | /** 47 | * ret : 0 48 | * p : 0.0021384065 49 | */ 50 | 51 | private int ret; 52 | private String p; 53 | 54 | public int getRet() { 55 | return ret; 56 | } 57 | 58 | public void setRet(int ret) { 59 | this.ret = ret; 60 | } 61 | 62 | public String getP() { 63 | return p; 64 | } 65 | 66 | public void setP(String p) { 67 | this.p = p; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-detector-api/src/main/java/com/coocaa/detector/entity/MetricsCsvVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.entity; 2 | 3 | import lombok.*; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author 陈煜坤 9 | * @date 2019/8/7 16:31 10 | * @package_name com.monitoring.warn.notice.entity 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @Builder 16 | public class MetricsCsvVo implements Serializable { 17 | private Long viewId; 18 | private String viewName; 19 | private Long attrId; 20 | private String attrName; 21 | private String source; 22 | private String trainOrTest; 23 | private String positiveOrNegative; 24 | private Long dateTime; 25 | private String window; 26 | private String dataA; 27 | private String dataB; 28 | private String dataC; 29 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-detector-api/src/main/java/com/coocaa/detector/entity/Model.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | /** 9 | * @author 陈煜坤 10 | * @date 2019/8/12 10:33 11 | * @package_name com.monitoring.warn.notice.entity 12 | */ 13 | @Data 14 | public class Model implements Serializable { 15 | 16 | private int id; 17 | private String taskId; 18 | private int sampleNum; 19 | private int postiveSampleNum; 20 | private int negativeSampleNum; 21 | private int window; 22 | private String modelName; 23 | private String source; 24 | private Date startTime; 25 | private Date endTime; 26 | private String status; 27 | } 28 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-detector-api/src/main/java/com/coocaa/detector/entity/QueryModel.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author 陈煜坤 7 | * @date 2019/8/16 17:16 8 | * @package_name com.common.parent_model.entity 9 | */ 10 | @Data 11 | public class QueryModel { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-detector-api/src/main/java/com/coocaa/detector/entity/QuerySample.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author 陈煜坤 7 | * @date 2019/8/16 17:04 8 | * @package_name com.common.parent_model.entity 9 | */ 10 | @Data 11 | public class QuerySample { 12 | 13 | private String attrId; 14 | private long beginTime; 15 | private long endTime; 16 | private int size; 17 | private String positiveOrNegative = ""; 18 | private int current; 19 | private String data = ""; 20 | private String trainOrTest = ""; 21 | private String viewId; 22 | private String window; 23 | } 24 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-detector-api/src/main/java/com/coocaa/detector/entity/SampleDataset.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * @author 陈煜坤 9 | * @date 2019/8/19 10:56 10 | * @package_name com.monitoring.warn.notice.entity 11 | */ 12 | @Data 13 | public class SampleDataset { 14 | private int id; 15 | private Date updateTime; 16 | private String viewId; 17 | private String viewName; 18 | private String attrName; 19 | private String attrId; 20 | private String source; 21 | private String trainOrTest; 22 | private String positiveOrNegative; 23 | private int window; 24 | private int dataTime; 25 | private String dataC; 26 | private String dataB; 27 | private String dataA; 28 | private int anomalyId; 29 | } 30 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-detector-api/src/main/java/com/coocaa/detector/feign/IDetectorClientFallback.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.feign; 2 | 3 | import com.coocaa.core.tool.api.R; 4 | import com.coocaa.detector.entity.*; 5 | import com.sun.org.apache.xpath.internal.operations.Bool; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * @description: 失败处理 13 | * @author: dongyang_wu 14 | * @create: 2019-08-06 20:40 15 | */ 16 | @Component 17 | public class IDetectorClientFallback implements IDetectorClient { 18 | @Override 19 | public R timeSeriesDetector(Detector detector) { 20 | return R.fail("获取数据失败"); 21 | } 22 | 23 | @Override 24 | public R train(Train train) { 25 | return R.fail("获取数据失败"); 26 | } 27 | 28 | @Override 29 | public R importSample(Map metrics) { 30 | return R.fail("获取数据失败"); 31 | } 32 | 33 | @Override 34 | public R getModelSource() { 35 | return R.fail("获取数据失败"); 36 | } 37 | 38 | @Override 39 | public R getModelSource(String sourceName) { 40 | return R.fail("获取数据失败"); 41 | } 42 | 43 | @Override 44 | public R getQueryTrainSource() { 45 | return R.fail("获取数据失败"); 46 | } 47 | 48 | @Override 49 | public R> getQueryTrainSource(String sourceName) { 50 | return R.fail("获取数据失败"); 51 | } 52 | 53 | @Override 54 | public R getModelStatus(String modelName) { 55 | return R.fail("获取数据失败"); 56 | } 57 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-notice-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.coocaa 7 | aiops-service-api 8 | 2.3.1 9 | 10 | 4.0.0 11 | 12 | aiops-notice-api 13 | ${project.artifactId} 14 | ${aiops.project.version} 15 | jar 16 | 通知服务API 17 | 18 | 19 | com.coocaa 20 | aiops-common 21 | ${aiops.project.version} 22 | 23 | 24 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-notice-api/src/main/java/com/coocaa/notice/entity/Mail.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.entity; 2 | 3 | import lombok.*; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | import javax.validation.constraints.Pattern; 7 | 8 | @Getter 9 | @Setter 10 | @ToString 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | @Builder 14 | public class Mail { 15 | 16 | @Pattern(regexp = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$", message = "邮箱格式不正确") 17 | private String to; 18 | 19 | @NotBlank(message = "标题不能为空") 20 | private String title; 21 | 22 | @NotBlank(message = "正文不能为空") 23 | private String content; 24 | // 消息id 25 | private String msgId; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-notice-api/src/main/java/com/coocaa/notice/entity/MsgLog.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.extension.activerecord.Model; 6 | import com.coocaa.core.tool.jackson.JsonUtil; 7 | import lombok.*; 8 | 9 | import java.util.Date; 10 | 11 | @Getter 12 | @Setter 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | @ToString 16 | @Builder 17 | public class MsgLog extends Model { 18 | @TableId(value = "id", type = IdType.AUTO) 19 | private Long id; 20 | private String msg; 21 | private String exchange; 22 | private String routingKey; 23 | private Integer status; 24 | private Integer tryCount; 25 | private Date nextTryTime; 26 | private Date createTime; 27 | private Date updateTime; 28 | 29 | public void setMsg(Object msg) { 30 | this.msg = JsonUtil.toJson(msg); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-notice-api/src/main/java/com/coocaa/notice/feign/INoticeClient.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.feign; 2 | 3 | import com.coocaa.core.secure.constant.AppConstant; 4 | import com.coocaa.core.tool.api.R; 5 | import com.coocaa.notice.entity.Mail; 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @description: 通知Feign 14 | * @author: dongyang_wu 15 | * @create: 2019-08-07 11:41 16 | */ 17 | @FeignClient( 18 | value = AppConstant.APPLICATION_NOTICE_NAME, 19 | fallback = INoticeClientFallback.class 20 | ) 21 | public interface INoticeClient { 22 | String API_PREFIX = "/notice"; 23 | 24 | @PostMapping(API_PREFIX + "/sendMail") 25 | R sendMail(@RequestBody Mail mail); 26 | 27 | @PostMapping(API_PREFIX + "/sendMails") 28 | R sendMails(@RequestBody List mails); 29 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-notice-api/src/main/java/com/coocaa/notice/feign/INoticeClientFallback.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.feign; 2 | 3 | import com.coocaa.core.tool.api.R; 4 | import com.coocaa.notice.entity.Mail; 5 | import org.springframework.web.bind.annotation.RequestBody; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @description: 通知Feign失败处理 11 | * @author: dongyang_wu 12 | * @create: 2019-08-07 11:43 13 | */ 14 | public class INoticeClientFallback implements INoticeClient { 15 | @Override 16 | public R sendMail(@RequestBody Mail mail) { 17 | return R.fail(); 18 | } 19 | 20 | @Override 21 | public R sendMails(List mails) { 22 | return R.fail(); 23 | } 24 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.coocaa 7 | aiops-service-api 8 | 2.3.1 9 | 10 | 4.0.0 11 | 12 | aiops-prometheus-api 13 | ${project.artifactId} 14 | ${aiops.project.version} 15 | jar 16 | 对接普罗米修斯服务API 17 | 18 | 19 | com.coocaa 20 | aiops-detector-api 21 | 2.3.1 22 | 23 | 24 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/common/PromBaseLables.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.common; 2 | 3 | /** 4 | * @description: 基础标签值 5 | * @author: dongyang_wu 6 | * @create: 2019-08-02 17:26 7 | */ 8 | public interface PromBaseLables { 9 | 10 | String baseLables = "type system module job hostname __name__ prog"; 11 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/constant/EventConstant.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.constant; 2 | 3 | /** 4 | * @program: intelligent_maintenance 5 | * @description: 异常常量 6 | * @author: dongyang_wu 7 | * @create: 2019-08-01 16:23 8 | */ 9 | public interface EventConstant { 10 | /** 11 | * task 12 | */ 13 | String EVENT_TASK = "task"; 14 | String EVENT_TASK_ID = "task_id"; 15 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/dto/MetisDto.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.dto; 2 | 3 | import lombok.*; 4 | 5 | /** 6 | * @description: Metis训练数据DTO 7 | * @author: dongyang_wu 8 | * @create: 2019-08-07 16:47 9 | */ 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @Builder 14 | public class MetisDto { 15 | /** 16 | * 指标集ID 17 | */ 18 | private Long viewId; 19 | /** 20 | * 指标集名 21 | */ 22 | private String viewName; 23 | /** 24 | * 指标ID 25 | */ 26 | private Long attrId; 27 | /** 28 | * 指标名 29 | */ 30 | private String attrName; 31 | /** 32 | * 模型名 33 | */ 34 | private String modelName; 35 | /** 36 | * 样本来源 37 | */ 38 | private String source; 39 | /** 40 | * 测试还是训练 41 | */ 42 | private String trainOrTest; 43 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/entity/Kpi.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import com.baomidou.mybatisplus.extension.activerecord.Model; 5 | import com.fasterxml.jackson.annotation.JsonIgnore; 6 | import lombok.*; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * @description: KPI指标清单实体 12 | * @author: dongyang_wu 13 | * @create: 2019-08-08 09:31 14 | */ 15 | @EqualsAndHashCode(callSuper = true) 16 | @Data 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | @Builder 20 | public class Kpi extends Model { 21 | @TableId(value = "id", type = IdType.AUTO) 22 | private Long id; 23 | private String name; 24 | private String promExpression; 25 | /** 26 | * 更新时间 27 | */ 28 | @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) 29 | private Date updateTime; 30 | /** 31 | * 创建时间 32 | */ 33 | @TableField(value = "create_time", fill = FieldFill.INSERT) 34 | private Date createTime; 35 | @TableLogic 36 | @JsonIgnore 37 | private Integer logic; 38 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/entity/Metric.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.entity; 2 | 3 | import lombok.*; 4 | 5 | /** 6 | * @Auther: wyx 7 | * @Date: 2019-07-27 12:41 8 | * @Description: Prometheus 指标 9 | */ 10 | @Builder 11 | @Setter 12 | @Getter 13 | @ToString 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class Metric { 17 | 18 | private String __name__; 19 | private String instance; 20 | private String job; 21 | private String module; 22 | private String system; 23 | private String type; 24 | 25 | 26 | // http请求属性开始 27 | private String request; 28 | private String status; 29 | // http请求属性结束 30 | 31 | // 磁盘容量属性开始 32 | private String device; 33 | /** 34 | * 分区类型 35 | */ 36 | private String fstype; 37 | 38 | /** 39 | * 挂载点 40 | */ 41 | private String mountpoint; 42 | // 磁盘容量属性结束 43 | 44 | // CPU使用率开始 45 | private String mode; 46 | private String cpu; 47 | // CPU使用率结束 48 | } 49 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/entity/PromMatrixData.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.entity; 2 | 3 | import lombok.*; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @Auther: wyx 9 | * @Date: 2019-07-29 9:37 10 | * @Description: 区间数据 11 | */ 12 | @Builder 13 | @Setter 14 | @Getter 15 | @ToString 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class PromMatrixData { 19 | 20 | private List requests; 21 | 22 | private List disk; 23 | 24 | private List cpuLoad; 25 | 26 | private List upLoadBandWidth; 27 | 28 | private List downLoadBandWidth; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/entity/PrometheusConfig.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.entity; 2 | 3 | import lombok.*; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @program: intelligent_maintenance 9 | * @description: 10 | * @author: dongyang_wu 11 | * @create: 2019-07-31 21:11 12 | */ 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | @Builder 17 | public class PrometheusConfig { 18 | private LabelsBean labels; 19 | private List targets; 20 | 21 | @Data 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | @Builder 25 | public static class LabelsBean { 26 | private String instance; 27 | } 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/entity/QueryInstant.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.entity; 2 | 3 | import lombok.*; 4 | 5 | import java.util.Date; 6 | import java.util.Map; 7 | 8 | /** 9 | * @program: intelligent_maintenance 10 | * @description: 即时查询 11 | * @author: dongyang_wu 12 | * @create: 2019-08-01 15:18 13 | */ 14 | @Data 15 | @Builder 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class QueryInstant { 19 | 20 | private String query; 21 | private Date date; 22 | private Integer timeout; 23 | private Map conditions; 24 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/entity/QueryRange.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import lombok.*; 5 | 6 | import java.util.Date; 7 | import java.util.Map; 8 | 9 | /** 10 | * @program: intelligent_maintenance 11 | * @description: 范围查询 12 | * @author: dongyang_wu 13 | * @create: 2019-08-01 15:20 14 | */ 15 | @Data 16 | @Builder 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class QueryRange { 20 | @JsonIgnore 21 | private Date start; 22 | @JsonIgnore 23 | private Date end; 24 | private String query; 25 | private Integer span; 26 | private Integer step; 27 | private Map conditions; 28 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/entity/Targets.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.entity; 2 | 3 | import lombok.*; 4 | 5 | /** 6 | * @program: intelligent_maintenance 7 | * @description: 监控项 8 | * @author: dongyang_wu 9 | * @create: 2019-08-02 13:01 10 | */ 11 | @Data 12 | @Builder 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class Targets { 16 | /** 17 | * labels : {"instance":"172.16.33.8:3903","job":"adsys","module":"tv-monitor","system":"adsys","type":"nginx"} 18 | * scrapeUrl : http://172.16.33.8:3903/metrics 19 | * lastError : 20 | * lastScrape : 2019-08-02T12:56:49.894858032+08:00 21 | * health : up 22 | */ 23 | private LabelsBean labels; 24 | private String scrapeUrl; 25 | private String lastError; 26 | private String lastScrape; 27 | private String health; 28 | 29 | @Data 30 | @Builder 31 | @AllArgsConstructor 32 | @NoArgsConstructor 33 | public static class LabelsBean { 34 | /** 35 | * instance : 172.16.33.8:3903 36 | * job : adsys 37 | * module : tv-monitor 38 | * system : adsys 39 | * type : nginx 40 | */ 41 | 42 | private String instance; 43 | private String job; 44 | private String module; 45 | private String system; 46 | private String type; 47 | 48 | } 49 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/entity/TaskError.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.entity; 2 | 3 | import lombok.*; 4 | 5 | /** 6 | * @description: 定时任务出错信息 7 | * @author: dongyang_wu 8 | * @create: 2019-08-01 16:21 9 | */ 10 | @Data 11 | @Builder 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class TaskError { 15 | 16 | private Integer taskId; 17 | /** 18 | * 堆栈信息 19 | */ 20 | private String stackTrace; 21 | /** 22 | * 异常名 23 | */ 24 | private String exceptionName; 25 | /** 26 | * 异常消息 27 | */ 28 | private String message; 29 | 30 | /** 31 | * 文件名 32 | */ 33 | private String fileName; 34 | 35 | /** 36 | * 代码行数 37 | */ 38 | private Integer lineNumber; 39 | /** 40 | * 对应的定时任务描述信息 41 | */ 42 | private String description; 43 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/entity/VectorData.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.entity; 2 | 3 | import lombok.*; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @Auther: wyx 9 | * @Date: 2019-07-27 14:17 10 | * @Description: 瞬时向量 11 | */ 12 | @Getter 13 | @Setter 14 | @ToString 15 | @Builder 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class VectorData { 19 | private Metric metric; 20 | 21 | /** 22 | * [ , "" ] 23 | */ 24 | private List value; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/feign/ITaskClient.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.feign; 2 | 3 | import com.coocaa.core.secure.constant.AppConstant; 4 | import com.coocaa.core.tool.api.R; 5 | import com.coocaa.prometheus.entity.Task; 6 | import com.coocaa.prometheus.input.TaskInputVo; 7 | import org.springframework.cloud.openfeign.FeignClient; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @description: 远程定时任务调用Feign 14 | * @author: dongyang_wu 15 | * @create: 2019-08-01 13:22 16 | */ 17 | @FeignClient( 18 | value = AppConstant.APPLICATION_TASK_NAME 19 | ) 20 | public interface ITaskClient { 21 | String API_PREFIX = "/dataManipulation"; 22 | 23 | /** 24 | * 新建定时任务 25 | * 26 | * @return 27 | */ 28 | @GetMapping(API_PREFIX + "/create-task") 29 | R createTask(@RequestBody TaskInputVo task, @RequestParam Integer type); 30 | 31 | @GetMapping(API_PREFIX + "/remove-task") 32 | R removeTask(@RequestParam Long taskId, @RequestParam Integer type); 33 | 34 | @GetMapping(API_PREFIX + "/selectTaskByTeamIds") 35 | R> selectTaskByTeamIds(@RequestParam("teamIds") String teamIds); 36 | 37 | @GetMapping(API_PREFIX + "/deleteTeamIdFromTask") 38 | R deleteTeamIdFromTask(@RequestParam("teamIds") String teamId); 39 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/input/GetValuesInput.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.input; 2 | 3 | import lombok.*; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * @description: 获取数据接口用户输入实体 9 | * @author: dongyang_wu 10 | * @create: 2019-08-06 21:40 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @Builder 16 | public class GetValuesInput { 17 | private String metricsName; 18 | private Long dateTime; 19 | private Integer span; 20 | private Integer step; 21 | Map conditions; 22 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/input/MetisCsvInputVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.input; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.*; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * @description: 导出Metis训练数据用户输入实体 11 | * @author: dongyang_wu 12 | * @create: 2019-08-06 14:42 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Builder 18 | @ApiModel 19 | public class MetisCsvInputVo { 20 | @ApiModelProperty("训练数据开始时间") 21 | private Date begin; 22 | @ApiModelProperty("训练数据结束时间") 23 | private Date end; 24 | @ApiModelProperty("跨度,以分钟为单位") 25 | private Integer span; 26 | @ApiModelProperty("样本来源") 27 | private String source; 28 | @ApiModelProperty("训练集还是测试集") 29 | private String trainOrTest; 30 | @ApiModelProperty("对应指标Id") 31 | private Long taskId; 32 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/input/MetisExceptionInputVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.input; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.*; 6 | 7 | /** 8 | * @description: MetisException用户输入类 9 | * @author: dongyang_wu 10 | * @create: 2019-08-07 15:01 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @Builder 16 | @ApiModel 17 | public class MetisExceptionInputVo { 18 | private Long id; 19 | @ApiModelProperty("0未处理1已修正2已恢复3已修复") 20 | private Integer status; 21 | @ApiModelProperty("用户输入的理由") 22 | private String reason; 23 | 24 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/input/QueryMetricProperty.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.input; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import lombok.*; 5 | 6 | /** 7 | * @description: http请求数查询 8 | * @author: dongyang_wu 9 | * @create: 2019-08-02 13:40 10 | */ 11 | @Data 12 | @Builder 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class QueryMetricProperty { 16 | /** 17 | * 通用属性 18 | */ 19 | private String metricsName; 20 | private String instance; 21 | /** 22 | * http请求数属性 23 | */ 24 | private String request; 25 | private String status; 26 | 27 | public interface HttpRequestsTotalNameKey { 28 | String INSTANCE = "instance"; 29 | String REQUEST = "request"; 30 | String STATUS = "status"; 31 | } 32 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/input/TaskInputVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.input; 2 | 3 | import com.coocaa.prometheus.entity.QueryRange; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.*; 7 | 8 | import javax.validation.constraints.NotEmpty; 9 | 10 | /** 11 | * @description: 定时任务输入实体类 12 | * @author: dongyang_wu 13 | * @create: 2019-08-05 13:40 14 | */ 15 | @Data 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | @Builder 19 | @ApiModel 20 | public class TaskInputVo { 21 | @ApiModelProperty("任务 ID") 22 | private Long id; 23 | @NotEmpty(message = "任务名不能为空") 24 | @ApiModelProperty("任务名") 25 | private String taskName; 26 | @NotEmpty(message = "任务描述不能为空") 27 | @ApiModelProperty("任务描述") 28 | private String taskDescription; 29 | @NotEmpty(message = "定时计划不能为空") 30 | @ApiModelProperty("计划任务定时") 31 | private String taskCron; 32 | @ApiModelProperty("定时任务选用模型名") 33 | private String modelName; 34 | @ApiModelProperty("定时任务所属指标集") 35 | private Long metricsId; 36 | @ApiModelProperty("定时任务所属Team") 37 | private String teamIds; 38 | @ApiModelProperty("定时任务参数--其中span主要用异常展示") 39 | private QueryRange queryRange; 40 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/output/KpiOutputVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.output; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import lombok.*; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * @author: dongyang_wu 11 | * @create: 2019-08-19 10:23 12 | * @description: 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Builder 18 | public class KpiOutputVo { 19 | private Long id; 20 | private String name; 21 | private String promExpression; 22 | private String queryPromExpression; 23 | private Date updateTime; 24 | private Date createTime; 25 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/output/MetisCsvOutputVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.output; 2 | 3 | import com.coocaa.prometheus.input.MetisCsvInputVo; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.*; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @description: 训练数据输出实体类 12 | * @author: dongyang_wu 13 | * @create: 2019-08-08 13:28 14 | */ 15 | @Data 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | @Builder 19 | @ApiModel 20 | public class MetisCsvOutputVo { 21 | @ApiModelProperty("导出训练数据输入Vo") 22 | private MetisCsvInputVo metisCsvInputVo; 23 | @ApiModelProperty("导出训练数据接口返回的接口集") 24 | private List metricsCsvVos; 25 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/output/MetisExceptionOutputVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.output; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.coocaa.prometheus.entity.MatrixData; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.*; 8 | 9 | import java.util.Date; 10 | import java.util.Map; 11 | import java.util.concurrent.ConcurrentHashMap; 12 | 13 | /** 14 | * @author: dongyang_wu 15 | * @create: 2019-08-16 15:11 16 | * @description: 17 | */ 18 | @Data 19 | @AllArgsConstructor 20 | @NoArgsConstructor 21 | @Builder 22 | public class MetisExceptionOutputVo { 23 | private Long id; 24 | @ApiModelProperty("异常所属指标Id") 25 | private Map taskToStringMap; 26 | @ApiModelProperty("异常数据List JSON字符串") 27 | private Object matrixDataJsonMap; 28 | @ApiModelProperty("0未处理1已修正2已恢复3已修复") 29 | private Integer status; 30 | private ConcurrentHashMap> userToReasonJsonMap; 31 | private Object recentUserReason; 32 | @ApiModelProperty("更新时间") 33 | @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) 34 | private Date updateTime; 35 | @ApiModelProperty("创建时间") 36 | @TableField(value = "create_time", fill = FieldFill.INSERT) 37 | private Date createTime; 38 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/output/MetricsCsvVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.output; 2 | 3 | import lombok.*; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * @description: 指标训练实体 9 | * @author: dongyang_wu 10 | * @create: 2019-08-06 14:11 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @Builder 16 | public class MetricsCsvVo { 17 | private Long viewId; 18 | private String viewName; 19 | private Long attrId; 20 | private String attrName; 21 | private String source; 22 | private String trainOrTest; 23 | private String positiveOrNegative; 24 | private Long dateTime; 25 | private String window; 26 | private String dataA; 27 | private String dataB; 28 | private String dataC; 29 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-prometheus-api/src/main/java/com/coocaa/prometheus/output/httpRequestToTal/MatrixResult.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.output.httpRequestToTal; 2 | 3 | import com.coocaa.detector.entity.DetectorResult; 4 | import com.coocaa.prometheus.entity.Metric; 5 | import lombok.*; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @description: 异常检测结果 11 | * @author: dongyang_wu 12 | * @create: 2019-08-02 15:52 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Builder 18 | public class MatrixResult { 19 | private Metric metric; 20 | private DetectorResult.DataBean detectResult; 21 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-user-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.coocaa 7 | aiops-service-api 8 | 2.3.1 9 | 10 | 4.0.0 11 | 12 | aiops-user-api 13 | ${project.artifactId} 14 | ${aiops.project.version} 15 | jar 16 | 用户服务API 17 | 18 | 19 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-user-api/src/main/java/com/coocaa/user/entity/Team.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.user.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import com.baomidou.mybatisplus.extension.activerecord.Model; 5 | import com.fasterxml.jackson.annotation.JsonIgnore; 6 | import lombok.*; 7 | 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | 11 | /** 12 | * @description: Team 13 | * @author: dongyang_wu 14 | * @create: 2019-08-05 16:14 15 | */ 16 | @Getter 17 | @Setter 18 | @Builder 19 | @ToString 20 | @AllArgsConstructor 21 | @NoArgsConstructor 22 | public class Team extends Model { 23 | @TableId(value = "id", type = IdType.AUTO) 24 | private Long id; 25 | private String name; 26 | private Long adminUserId; 27 | @TableLogic 28 | @JsonIgnore 29 | private Integer logic; 30 | @TableField(fill = FieldFill.INSERT) 31 | private Date createTime; 32 | @TableField(fill = FieldFill.INSERT_UPDATE) 33 | private Date updateTime; 34 | 35 | // @TableField(exist = false) 36 | // private User adminUser; 37 | // @TableField(exist = false) 38 | // private List userList; 39 | @Override 40 | protected Serializable pkVal() { 41 | return this.id; 42 | } 43 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-user-api/src/main/java/com/coocaa/user/entity/UserInfo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.user.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.*; 6 | 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | 11 | /** 12 | * 用户信息 13 | * 14 | * @author dongyang_wu 15 | */ 16 | @Data 17 | @Builder 18 | @ApiModel(description = "用户信息") 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | public class UserInfo implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | /** 26 | * 用户基础信息 27 | */ 28 | @ApiModelProperty(value = "用户") 29 | private User user; 30 | 31 | /** 32 | * 权限标识集合 33 | */ 34 | @ApiModelProperty(value = "权限集合") 35 | private List permissions; 36 | 37 | /** 38 | * 角色集合 39 | */ 40 | @ApiModelProperty(value = "角色集合") 41 | private List roles; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-user-api/src/main/java/com/coocaa/user/entity/WxUser.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.user.entity; 2 | 3 | import lombok.*; 4 | 5 | /** 6 | * @program: 微信登录用户 7 | * @description: 8 | * @author: dongyang_wu 9 | * @create: 2019-05-30 23:12 10 | */ 11 | @Data 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | @Builder 15 | public class WxUser { 16 | /** 17 | * openid 18 | */ 19 | private String openid; 20 | /** 21 | * appid 22 | */ 23 | private String appid; 24 | /** 25 | * 头像 26 | */ 27 | private String avatarUrl; 28 | /** 29 | * 昵称 30 | */ 31 | private String nickName; 32 | /** 33 | * 国家 34 | */ 35 | private String country; 36 | /** 37 | * 省份 38 | */ 39 | private String province; 40 | /** 41 | * 城市 42 | */ 43 | private String city; 44 | /** 45 | * 性别 46 | */ 47 | private Byte gender; 48 | private String code; 49 | private String encryptedData; 50 | private String iv; 51 | } 52 | -------------------------------------------------------------------------------- /aiops-service-api/aiops-user-api/src/main/java/com/coocaa/user/input/LoginUserVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.user.input; 2 | 3 | import lombok.*; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | 7 | /** 8 | * @description: 登录用户 9 | * @author: dongyang_wu 10 | * @create: 2019-07-30 21:23 11 | */ 12 | @Data 13 | @Builder 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class LoginUserVo { 17 | @NotBlank(message = "用户名不能为空") 18 | private String userName; 19 | @NotBlank(message = "密码不能为空") 20 | private String password; 21 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-user-api/src/main/java/com/coocaa/user/input/TeamInputVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.user.input; 2 | 3 | import lombok.*; 4 | 5 | /** 6 | * @description: Team输入实体类 7 | * @author: dongyang_wu 8 | * @create: 2019-08-05 19:43 9 | */ 10 | @Data 11 | @Builder 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class TeamInputVo { 15 | private Long id; 16 | private String name; 17 | private Long adminUserId; 18 | /** 19 | * userIdList集合以空格隔开 20 | */ 21 | private String userIdList; 22 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-user-api/src/main/java/com/coocaa/user/input/UserInputVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.user.input; 2 | 3 | import lombok.*; 4 | 5 | import javax.validation.constraints.NotEmpty; 6 | 7 | /** 8 | * @description: 用户输入实体类 9 | * @author: dongyang_wu 10 | * @create: 2019-08-06 11:51 11 | */ 12 | @Data 13 | @Builder 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class UserInputVo { 17 | private Long id; 18 | private String company; 19 | private String department; 20 | private String departmentGroup; 21 | private String organization; 22 | private String mobile; 23 | private String mail; 24 | private String name; 25 | private String account; 26 | private String teamIds; 27 | private String wechat; 28 | } -------------------------------------------------------------------------------- /aiops-service-api/aiops-user-api/src/main/java/com/coocaa/user/output/TeamOutputVo.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.user.output; 2 | 3 | import com.coocaa.user.entity.User; 4 | import lombok.*; 5 | 6 | import java.util.*; 7 | 8 | /** 9 | * @description: Team输出实体类 10 | * @author: dongyang_wu 11 | * @create: 2019-08-07 10:54 12 | */ 13 | @Data 14 | @Builder 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class TeamOutputVo { 18 | private Long id; 19 | private String name; 20 | private User adminUser; 21 | private Integer userListTotal; 22 | private List userList; 23 | private Date createTime; 24 | private Date updateTime; 25 | } -------------------------------------------------------------------------------- /aiops-service/aiops-detector/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | aiops-service 7 | com.coocaa 8 | 2.3.1 9 | 10 | 4.0.0 11 | 12 | aiops-detector 13 | ${project.artifactId} 14 | ${aiops.project.version} 15 | jar 16 | 数据检测服务 17 | 18 | 19 | com.coocaa 20 | aiops-core-boot 21 | ${aiops.tool.version} 22 | 23 | 24 | com.coocaa 25 | aiops-detector-api 26 | ${aiops.project.version} 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-amqp 31 | 32 | 33 | -------------------------------------------------------------------------------- /aiops-service/aiops-detector/src/main/java/com/coocaa/detector/DetectorApplication.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector; 2 | 3 | import com.coocaa.core.secure.constant.AppConstant; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.cloud.openfeign.EnableFeignClients; 9 | 10 | /** 11 | * @program: intelligent_maintenance 12 | * @description: 数据检测服务启动器 13 | * @author: dongyang_wu 14 | * @create: 2019-07-31 11:46 15 | */ 16 | @SpringBootApplication(scanBasePackages = {"com.coocaa"}) 17 | @EnableDiscoveryClient 18 | @EnableCircuitBreaker 19 | @EnableFeignClients(AppConstant.BASE_PACKAGES) 20 | public class DetectorApplication { 21 | public static void main(String[] args) { 22 | SpringApplication.run(DetectorApplication.class, args); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /aiops-service/aiops-detector/src/main/java/com/coocaa/detector/config/AMQPConfig.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.config; 2 | 3 | import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; 4 | import org.springframework.amqp.support.converter.MessageConverter; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @author 陈煜坤 10 | * @date 2019/7/23 12:54 11 | * @package_name com.monitoring.warn_notice.config 12 | */ 13 | @Configuration 14 | public class AMQPConfig { 15 | 16 | @Bean 17 | public MessageConverter messageConverter(){ 18 | return new Jackson2JsonMessageConverter(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /aiops-service/aiops-detector/src/main/java/com/coocaa/detector/mapper/MetisSourceMapper.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.mapper; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.coocaa.detector.entity.Model; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Select; 7 | 8 | import java.util.List; 9 | 10 | 11 | /** 12 | * @author 陈煜坤 13 | * @date 2019/8/7 16:43 14 | * @package_name com.monitoring.warn.notice.mapper 15 | */ 16 | @Mapper 17 | public interface MetisSourceMapper { 18 | 19 | @Select("select source from sample_dataset GROUP BY source") 20 | String[] getAllQueryTrainSource(); 21 | 22 | @Select("select model_name from train_task") 23 | String[] getAllModelSource(); 24 | 25 | @Select("select model_name from train_task where source LIKE CONCAT(CONCAT('%', #{0}), '%')") 26 | String[] getModelSource(String sourceName); 27 | 28 | @Select("select status from train_task where model_name=CONCAT(#{0},'_model')") 29 | String getModelStatus(String str); 30 | 31 | @Select("select sample_num,start_time,end_time from train_task") 32 | List getAllModelTime(); 33 | 34 | @Select("select * from train_task") 35 | List getAllModel(Page page); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /aiops-service/aiops-detector/src/main/java/com/coocaa/detector/mapper/SampleDatasetMapper.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.coocaa.detector.entity.SampleDataset; 5 | 6 | /** 7 | * @author 陈煜坤 8 | * @date 2019/8/19 13:10 9 | * @package_name com.monitoring.warn.notice.mapper 10 | */ 11 | public interface SampleDatasetMapper extends BaseMapper { 12 | } 13 | -------------------------------------------------------------------------------- /aiops-service/aiops-detector/src/main/java/com/coocaa/detector/mapper/TrainMapper.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.coocaa.detector.entity.SampleDataset; 6 | import com.coocaa.detector.entity.Train; 7 | import org.apache.ibatis.annotations.Select; 8 | 9 | import java.util.List; 10 | 11 | 12 | /** 13 | * @author 陈煜坤 14 | * @date 2019/8/19 9:15 15 | * @package_name com.monitoring.warn.notice.mapper 16 | */ 17 | public interface TrainMapper extends BaseMapper { 18 | 19 | @Select("select * from sample_dataset") 20 | List getSD(QueryWrapper qw); 21 | } 22 | -------------------------------------------------------------------------------- /aiops-service/aiops-detector/src/main/java/com/coocaa/detector/util/metis/SourceUtils.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.detector.util.metis; 2 | 3 | /** 4 | * @author 陈煜坤 5 | * @date 2019/8/7 17:14 6 | * @package_name com.monitoring.warn.notice.utils.metis 7 | */ 8 | public class SourceUtils { 9 | 10 | private static final String MODEL_SUFFIX_NAME = "_model"; 11 | 12 | public static String modifyModelSuffixName(String string){ 13 | if (string.contains(MODEL_SUFFIX_NAME)){ 14 | string = string.replaceFirst(MODEL_SUFFIX_NAME,""); 15 | if (string.contains(MODEL_SUFFIX_NAME)){ 16 | return ""; 17 | } 18 | return string; 19 | }else { 20 | return ""; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /aiops-service/aiops-detector/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: aiops-detector 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: 39.108.106.167:8848 8 | config: 9 | server-addr: 39.108.106.167:8848 10 | file-extension: yaml 11 | profiles: 12 | active: dev 13 | 14 | 15 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.coocaa 7 | aiops-service 8 | 2.3.1 9 | 10 | 4.0.0 11 | 12 | aiops-log 13 | ${project.artifactId} 14 | ${aiops.project.version} 15 | jar 16 | 日志服务 17 | 18 | 19 | com.coocaa 20 | aiops-core-boot 21 | ${aiops.tool.version} 22 | 23 | 24 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/LogApplication.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log; 17 | 18 | import com.coocaa.core.secure.constant.AppConstant; 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 22 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 23 | import org.springframework.cloud.openfeign.EnableFeignClients; 24 | 25 | /** 26 | * 日志服务 27 | * 28 | * @author dongyang_wu 29 | */ 30 | @SpringBootApplication(scanBasePackages = {"com.coocaa"}) 31 | @EnableDiscoveryClient 32 | @EnableCircuitBreaker 33 | @EnableFeignClients(AppConstant.BASE_PACKAGES) 34 | public class LogApplication { 35 | 36 | public static void main(String[] args) { 37 | SpringApplication.run(LogApplication.class, args); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/feign/LogClient.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.feign; 2 | 3 | import com.coocaa.core.log.model.*; 4 | import com.coocaa.core.log.service.*; 5 | import com.coocaa.core.tool.api.R; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | 10 | /** 11 | * 日志服务Feign实现类 12 | * 13 | * @author dongyang_wu 14 | */ 15 | @RestController 16 | @AllArgsConstructor 17 | public class LogClient implements ILogClient { 18 | 19 | ILogUsualService usualLogService; 20 | 21 | ILogApiService apiLogService; 22 | ILogErrorService errorLogService; 23 | 24 | @Override 25 | @PostMapping(API_PREFIX + "/saveUsualLog") 26 | public R saveUsualLog(@RequestBody LogUsual log) { 27 | log.setParams(log.getParams().replace("&", "&")); 28 | return R.data(usualLogService.save(log)); 29 | } 30 | 31 | @Override 32 | @PostMapping(API_PREFIX + "/saveApiLog") 33 | public R saveApiLog(@RequestBody LogApi log) { 34 | log.setParams(log.getParams().replace("&", "&")); 35 | apiLogService.deleteLogs(); 36 | return R.data(apiLogService.save(log)); 37 | } 38 | 39 | @Override 40 | @PostMapping(API_PREFIX + "/saveErrorLog") 41 | public R saveErrorLog(@RequestBody LogError log) { 42 | log.setParams(log.getParams().replace("&", "&")); 43 | return R.data(errorLogService.save(log)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/mapper/LogApiMapper.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.coocaa.common.constant.TableConstant; 5 | import com.coocaa.core.log.model.LogApi; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.apache.ibatis.annotations.Select; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Mapper 接口 13 | * 14 | * @author dongyang_wu 15 | */ 16 | public interface LogApiMapper extends BaseMapper { 17 | String FIND_TOP_RECORDS = TableConstant.SELECT_ID_ALL + TableConstant.TABLE.LOG_API + " ORDER BY " + TableConstant.CREATE_TIME + " DESC LIMIT ${logNumber}"; 18 | String FIND_ALL_SIZE = TableConstant.SELECT_COUNT + TableConstant.TABLE.LOG_API; 19 | 20 | @Select(value = FIND_TOP_RECORDS) 21 | List findTopRecords(@Param("logNumber") String logNumber); 22 | 23 | @Select(value = FIND_ALL_SIZE) 24 | Long findAllSize(); 25 | } 26 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/mapper/LogErrorMapper.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.coocaa.core.log.model.LogError; 5 | 6 | /** 7 | * Mapper 接口 8 | * 9 | * @author dongyang_wu 10 | */ 11 | public interface LogErrorMapper extends BaseMapper { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/mapper/LogUsualMapper.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.coocaa.core.log.model.LogUsual; 5 | 6 | /** 7 | * Mapper 接口 8 | * 9 | * @author dongyang_wu 10 | */ 11 | public interface LogUsualMapper extends BaseMapper { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/mapper/LogUsualMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | select id, 25 | create_time AS createTime, 26 | service_id, server_host, server_ip, env, log_level, log_data, method, request_uri, user_agent, params, create_by 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/service/ILogApiService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.service; 17 | 18 | import com.baomidou.mybatisplus.extension.service.IService; 19 | import com.coocaa.core.log.model.LogApi; 20 | 21 | /** 22 | * 服务类 23 | * 24 | * @author dongyang_wu 25 | */ 26 | public interface ILogApiService extends IService { 27 | void deleteLogs(); 28 | } 29 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/service/ILogErrorService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.service; 17 | 18 | import com.baomidou.mybatisplus.extension.service.IService; 19 | import com.coocaa.core.log.model.LogError; 20 | 21 | /** 22 | * 服务类 23 | * 24 | * @author dongyang_wu 25 | */ 26 | public interface ILogErrorService extends IService { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/service/ILogUsualService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.service; 17 | 18 | import com.baomidou.mybatisplus.extension.service.IService; 19 | import com.coocaa.core.log.model.LogUsual; 20 | 21 | /** 22 | * 服务类 23 | * 24 | * @author dongyang_wu 25 | */ 26 | public interface ILogUsualService extends IService { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/service/impl/LogApiServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.core.log.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.coocaa.common.constant.TableConstant; 6 | import com.coocaa.core.log.mapper.LogApiMapper; 7 | import com.coocaa.core.log.model.LogApi; 8 | import com.coocaa.core.log.service.ILogApiService; 9 | import com.coocaa.core.tool.utils.Func; 10 | import lombok.AllArgsConstructor; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.util.CollectionUtils; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * 服务实现类 18 | * 19 | * @author dongyang_wu 20 | */ 21 | @Service 22 | @AllArgsConstructor 23 | public class LogApiServiceImpl extends ServiceImpl implements ILogApiService { 24 | private LogApiMapper logApiMapper; 25 | 26 | @Override 27 | public void deleteLogs() { 28 | if (logApiMapper.findAllSize() > 0) { 29 | List ids = logApiMapper.findTopRecords(Func.toStr(50)); 30 | this.remove(new QueryWrapper().notIn(TableConstant.ID, ids)); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/service/impl/LogErrorServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.service.impl; 17 | 18 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 19 | import com.coocaa.core.log.mapper.LogErrorMapper; 20 | import com.coocaa.core.log.model.LogError; 21 | import com.coocaa.core.log.service.ILogErrorService; 22 | import org.springframework.stereotype.Service; 23 | 24 | /** 25 | * 服务实现类 26 | * 27 | * @author dongyang_wu 28 | * @since 2018-09-26 29 | */ 30 | @Service 31 | public class LogErrorServiceImpl extends ServiceImpl implements ILogErrorService { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/java/com/coocaa/core/log/service/impl/LogUsualServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.core.log.service.impl; 17 | 18 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 19 | import com.coocaa.core.log.mapper.LogUsualMapper; 20 | import com.coocaa.core.log.model.LogUsual; 21 | import com.coocaa.core.log.service.ILogUsualService; 22 | import org.springframework.stereotype.Service; 23 | 24 | /** 25 | * 服务实现类 26 | * 27 | * @author dongyang_wu 28 | * @since 2018-10-12 29 | */ 30 | @Service 31 | public class LogUsualServiceImpl extends ServiceImpl implements ILogUsualService { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /aiops-service/aiops-log/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: aiops-log 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: 39.108.106.167:8848 8 | config: 9 | server-addr: 39.108.106.167:8848 10 | file-extension: yaml 11 | profiles: 12 | active: dev 13 | -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/main/java/com/coocaa/notice/WarnNoticeApplication.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice; 2 | 3 | import com.coocaa.core.secure.constant.AppConstant; 4 | import org.springframework.amqp.rabbit.annotation.EnableRabbit; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | import org.springframework.cloud.openfeign.EnableFeignClients; 10 | 11 | @SpringBootApplication(scanBasePackages = {"com.coocaa"}) 12 | @EnableDiscoveryClient 13 | @EnableCircuitBreaker 14 | @EnableFeignClients(AppConstant.BASE_PACKAGES) 15 | @EnableRabbit 16 | public class WarnNoticeApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(WarnNoticeApplication.class, args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/main/java/com/coocaa/notice/controller/MailNoticeController.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.controller; 2 | 3 | import com.coocaa.core.log.response.ResponseHelper; 4 | import com.coocaa.core.log.response.ResultBean; 5 | import com.coocaa.notice.entity.Mail; 6 | import com.coocaa.notice.service.IMailService; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import lombok.AllArgsConstructor; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.validation.Errors; 12 | import org.springframework.validation.annotation.Validated; 13 | import org.springframework.web.bind.annotation.*; 14 | import springfox.documentation.annotations.ApiIgnore; 15 | 16 | 17 | /** 18 | * @date 2019/7/23 9:24 19 | * @package_name com.monitoring.warn_notice 20 | */ 21 | @RestController 22 | @AllArgsConstructor 23 | @Api(value = "通知模块", tags = "通知接口") 24 | public class MailNoticeController { 25 | 26 | private IMailService mailService; 27 | 28 | @PostMapping("/send") 29 | @ApiOperation("邮件通知") 30 | public ResponseEntity sendMail(@RequestBody @Validated Mail mail, @ApiIgnore Errors errors) { 31 | if (errors.hasErrors()) { 32 | String msg = errors.getFieldError().getDefaultMessage(); 33 | return ResponseHelper.BadRequest(msg); 34 | } 35 | return ResponseHelper.OK(mailService.addMailNoticeToMQ(mail)); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/main/java/com/coocaa/notice/feign/NoticeClient.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.feign; 2 | 3 | import com.coocaa.core.tool.api.R; 4 | import com.coocaa.notice.entity.Mail; 5 | import com.coocaa.notice.service.IMailService; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import springfox.documentation.annotations.ApiIgnore; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @program: intelligent-maintenance 14 | * @description: Feign实现 15 | * @author: dongyang_wu 16 | * @create: 2019-08-07 11:45 17 | */ 18 | @RestController 19 | @AllArgsConstructor 20 | @ApiIgnore 21 | public class NoticeClient implements INoticeClient { 22 | private IMailService mailService; 23 | 24 | @Override 25 | public R sendMail(Mail mail) { 26 | return R.data(mailService.addMailNoticeToMQ(mail)); 27 | } 28 | 29 | @Override 30 | public R sendMails(List mails) { 31 | mails.forEach(mail -> mailService.addMailNoticeToMQ(mail)); 32 | return R.success(); 33 | } 34 | } -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/main/java/com/coocaa/notice/mapper/MsgLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.coocaa.notice.entity.MsgLog; 6 | 7 | import java.util.List; 8 | 9 | public interface MsgLogMapper extends BaseMapper { 10 | 11 | void updateStatus(MsgLog msgLog); 12 | 13 | List selectTimeoutMsg(); 14 | 15 | void updateTryCount(MsgLog msgLog); 16 | 17 | MsgLog selectByPrimaryKey(Long id); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/main/java/com/coocaa/notice/mq/consumer/BaseConsumer.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.mq.consumer; 2 | 3 | import com.rabbitmq.client.Channel; 4 | import org.springframework.amqp.core.Message; 5 | 6 | import java.io.IOException; 7 | 8 | public interface BaseConsumer { 9 | 10 | void consume(Message message, Channel channel) throws IOException; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/main/java/com/coocaa/notice/mq/consumer/MailConsumer.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.mq.consumer; 2 | 3 | import com.coocaa.core.log.exception.ServiceException; 4 | import com.coocaa.notice.util.MessageHelper; 5 | import com.coocaa.notice.entity.Mail; 6 | import com.coocaa.notice.util.MailUtil; 7 | import com.rabbitmq.client.Channel; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.amqp.core.Message; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | @Component 14 | @Slf4j 15 | public class MailConsumer implements BaseConsumer { 16 | 17 | @Autowired 18 | private MailUtil mailUtil; 19 | 20 | @Override 21 | public void consume(Message message, Channel channel) { 22 | Mail mail = MessageHelper.msgToObj(message, Mail.class); 23 | log.info("收到消息: {}", mail.toString()); 24 | 25 | boolean success = mailUtil.send(mail); 26 | if (!success) { 27 | throw new ServiceException("send mail error"); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/main/java/com/coocaa/notice/mq/listener/MailListener.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.mq.listener; 2 | 3 | import com.coocaa.notice.config.RabbitConfig; 4 | import com.coocaa.notice.mq.BaseConsumerProxy; 5 | import com.coocaa.notice.mq.consumer.BaseConsumer; 6 | import com.coocaa.notice.mq.consumer.MailConsumer; 7 | import com.coocaa.notice.service.IMailService; 8 | import com.rabbitmq.client.Channel; 9 | import org.springframework.amqp.core.Message; 10 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.io.IOException; 15 | 16 | @Component 17 | public class MailListener { 18 | 19 | @Autowired 20 | private MailConsumer mailConsumer; 21 | 22 | @Autowired 23 | private IMailService msgLogService; 24 | 25 | @RabbitListener(queues = RabbitConfig.MAIL_QUEUE_NAME) 26 | public void consume(Message message, Channel channel) throws IOException { 27 | BaseConsumerProxy baseConsumerProxy = new BaseConsumerProxy(mailConsumer, msgLogService); 28 | BaseConsumer proxy = (BaseConsumer) baseConsumerProxy.getProxy(); 29 | if (null != proxy) { 30 | proxy.consume(message, channel); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/main/java/com/coocaa/notice/service/IMailService.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.coocaa.core.log.model.LogApi; 5 | import com.coocaa.notice.entity.Mail; 6 | import com.coocaa.notice.entity.MsgLog; 7 | import com.rabbitmq.client.Channel; 8 | import org.springframework.amqp.core.Message; 9 | 10 | import java.util.*; 11 | 12 | /** 13 | * @author 陈煜坤 14 | * @date 2019/7/23 8:46 15 | * @package_name com.monitoring.warn_notice.service 16 | */ 17 | public interface IMailService extends IService { 18 | 19 | 20 | boolean addMailNoticeToMQ(Mail mail); 21 | 22 | void updateStatus(Long msgId, Integer status); 23 | 24 | MsgLog selectByMsgId(Long msgId); 25 | 26 | List selectTimeoutMsg(); 27 | 28 | void updateTryCount(Long msgId); 29 | } 30 | -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/main/java/com/coocaa/notice/util/MessageHelper.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice.util; 2 | 3 | import com.coocaa.core.tool.jackson.JsonUtil; 4 | import org.springframework.amqp.core.Message; 5 | import org.springframework.amqp.core.MessageBuilder; 6 | import org.springframework.amqp.core.MessageDeliveryMode; 7 | import org.springframework.amqp.core.MessageProperties; 8 | 9 | public class MessageHelper { 10 | 11 | public static Message objToMsg(Object obj) { 12 | if (null == obj) { 13 | return null; 14 | } 15 | 16 | Message message = MessageBuilder.withBody(JsonUtil.toJson(obj).getBytes()).build(); 17 | // 消息持久化 18 | message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT); 19 | message.getMessageProperties().setContentType(MessageProperties.CONTENT_TYPE_JSON); 20 | 21 | return message; 22 | } 23 | 24 | public static T msgToObj(Message message, Class clazz) { 25 | if (null == message || null == clazz) { 26 | return null; 27 | } 28 | 29 | String str = new String(message.getBody()); 30 | T obj = JsonUtil.parse(str, clazz); 31 | 32 | return obj; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: aiops-notice 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: 39.108.106.167:8848 8 | config: 9 | server-addr: 39.108.106.167:8848 10 | file-extension: yaml 11 | profiles: 12 | active: dev 13 | 14 | 15 | -------------------------------------------------------------------------------- /aiops-service/aiops-notice/src/test/java/com/coocaa/notice/WarnTestNoticeApplication.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.notice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | /** 10 | * @program: intelligent_maintenance 11 | * @description: 12 | * @author: dongyang_wu 13 | * @create: 2019-07-30 17:31 14 | */ 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest(classes={WarnTestNoticeApplication.class}) 17 | public class WarnTestNoticeApplication { 18 | @Test 19 | public void testLdap(){ 20 | } 21 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:alpine 2 | VOLUME /tmp 3 | ADD aiops-prometheus.jar app.jar 4 | ENTRYPOINT ["java","-jar","/app.jar"] 5 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/docs/asciidoc/generated/overview.adoc: -------------------------------------------------------------------------------- 1 | = 智能运维小组 接口文档系统 2 | 3 | 4 | [[_overview]] 5 | == Overview 6 | 智能运维小组 接口文档系统 7 | 8 | 9 | === Version information 10 | [%hardbreaks] 11 | __Version__ : 2.3.1 12 | 13 | 14 | === Contact information 15 | [%hardbreaks] 16 | __Contact__ : Admin 17 | __Contact Email__ : 13058142866@163.com 18 | 19 | 20 | === URI scheme 21 | [%hardbreaks] 22 | __Host__ : localhost:10003 23 | __BasePath__ : / 24 | 25 | 26 | === Tags 27 | 28 | * Prometheus指标接口 : Metrics Controller 29 | * Prometheus接口 : Prometheus Controller 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/PrometheusApplication.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus; 2 | 3 | import com.coocaa.core.secure.constant.AppConstant; 4 | import org.springframework.amqp.rabbit.annotation.EnableRabbit; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | import org.springframework.cloud.openfeign.EnableFeignClients; 10 | import org.springframework.scheduling.annotation.EnableAsync; 11 | 12 | /** 13 | * @program: intelligent_maintenance 14 | * @description: 15 | * @author: dongyang_wu 16 | * @create: 2019-07-31 22:31 17 | */ 18 | @SpringBootApplication(scanBasePackages = {"com.coocaa"}) 19 | @EnableDiscoveryClient 20 | @EnableCircuitBreaker 21 | @EnableFeignClients(AppConstant.BASE_PACKAGES) 22 | @EnableRabbit 23 | @EnableAsync 24 | public class PrometheusApplication { 25 | public static void main(String[] args) { 26 | SpringApplication.run(PrometheusApplication.class, args); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/config/BeanAutoConfig.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.config; 2 | 3 | import com.coocaa.prometheus.event.TaskErrorListener; 4 | import org.springframework.context.annotation.*; 5 | import org.springframework.scheduling.TaskScheduler; 6 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; 7 | 8 | 9 | /** 10 | * @description: Bean自动注入 11 | * @author: dongyang_wu 12 | * @create: 2019-08-01 20:35 13 | */ 14 | @Configuration 15 | public class BeanAutoConfig { 16 | @Bean 17 | public TaskErrorListener taskErrorListener() { 18 | return new TaskErrorListener(); 19 | } 20 | 21 | // @Bean 22 | // public TaskScheduler taskScheduler() { 23 | // ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); 24 | // // 定时任务执行线程池核心线程数 25 | // taskScheduler.setPoolSize(10); 26 | // taskScheduler.setRemoveOnCancelPolicy(true); 27 | // taskScheduler.setThreadNamePrefix("TaskSchedulerThreadPool-"); 28 | // return taskScheduler; 29 | // } 30 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/config/RabbitConfig.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.config; 2 | 3 | import org.springframework.amqp.core.Queue; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @Auther: wyx 9 | * @Date: 2019-07-25 11:38 10 | * @Description: RabbitMQ 配置 11 | */ 12 | @Configuration 13 | public class RabbitConfig { 14 | 15 | @Bean 16 | public Queue Queue() { 17 | return new Queue("timingData"); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/config/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 5 | import org.springframework.web.socket.config.annotation.*; 6 | 7 | /** 8 | * @Auther: wyx 9 | * @Date: 2019-07-22 15:19 10 | * @Description: 配置 WebSocket 11 | */ 12 | @Configuration 13 | @EnableWebSocketMessageBroker 14 | public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { 15 | 16 | /** 17 | * 注册协议节点 18 | * 映射指定的 URL 19 | */ 20 | @Override 21 | public void registerStompEndpoints(StompEndpointRegistry registry) { 22 | registry.addEndpoint("/fetchData").setAllowedOrigins("*").withSockJS(); 23 | } 24 | 25 | /** 26 | * 配置消息代理 27 | */ 28 | @Override 29 | public void configureMessageBroker(MessageBrokerRegistry registry) { 30 | // 广播消息代理 配置多个 前端等待接收 31 | registry.enableSimpleBroker("/monitoring"); 32 | // 全局使用的订阅前缀 33 | registry.setApplicationDestinationPrefixes("/app/"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/controller/WebSocketController.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.controller; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import org.springframework.messaging.handler.annotation.MessageMapping; 5 | import org.springframework.messaging.handler.annotation.SendTo; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import springfox.documentation.annotations.ApiIgnore; 9 | 10 | /** 11 | * @Auther: wyx 12 | * @Date: 2019-07-22 16:09 13 | * @Description: WebSocket 控制器 14 | */ 15 | @RestController 16 | @RequestMapping("/websocket") 17 | @ApiIgnore 18 | public class WebSocketController { 19 | 20 | /** 21 | * 获得修改后的指标 22 | * 将数据发送给订阅了消息的浏览器 23 | * 收到消息并推送给 所有人 广播消息 24 | * SendToUser一对一消息 25 | * param: 获得的消息 26 | */ 27 | @MessageMapping("/updateMetrics") 28 | @SendTo("/monitoring/getCurrentData") 29 | public void receive(JSONObject param) { 30 | //TODO disposal data and send data to browser 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/event/ErrorTaskPublisher.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.event; 2 | 3 | import com.coocaa.core.tool.utils.*; 4 | import com.coocaa.prometheus.constant.EventConstant; 5 | import com.coocaa.prometheus.entity.TaskError; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | /** 11 | * @program: intelligent_maintenance 12 | * @description: 13 | * @author: dongyang_wu 14 | * @create: 2019-08-01 16:25 15 | */ 16 | public class ErrorTaskPublisher { 17 | 18 | public static void publishEvent(String description, Throwable error) { 19 | TaskError taskError = new TaskError(); 20 | if (Func.isNotEmpty(error)) { 21 | taskError.setStackTrace(Exceptions.getStackTraceAsString(error)); 22 | taskError.setExceptionName(error.getClass().getName()); 23 | taskError.setMessage(error.getMessage()); 24 | StackTraceElement[] elements = error.getStackTrace(); 25 | if (Func.isNotEmpty(elements)) { 26 | StackTraceElement element = elements[0]; 27 | taskError.setFileName(element.getFileName()); 28 | taskError.setLineNumber(element.getLineNumber()); 29 | } 30 | } 31 | taskError.setDescription(description); 32 | Map event = new HashMap<>(16); 33 | event.put(EventConstant.EVENT_TASK, taskError); 34 | SpringUtil.publishEvent(new TaskErrorEvent(event)); 35 | } 36 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/event/TaskErrorEvent.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.event; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | /** 6 | * @program: intelligent_maintenance 7 | * @description: 定时任务异常事件 8 | * @author: dongyang_wu 9 | * @create: 2019-08-01 16:17 10 | */ 11 | public class TaskErrorEvent extends ApplicationEvent { 12 | public TaskErrorEvent(Object source) { 13 | super(source); 14 | } 15 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/event/TaskErrorListener.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.event; 2 | 3 | import com.coocaa.prometheus.constant.EventConstant; 4 | import com.coocaa.prometheus.entity.TaskError; 5 | import com.coocaa.prometheus.util.TaskManager; 6 | import lombok.AllArgsConstructor; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.context.event.EventListener; 9 | import org.springframework.core.annotation.Order; 10 | import org.springframework.scheduling.annotation.Async; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.util.Map; 14 | 15 | /** 16 | * @program: intelligent_maintenance 17 | * @description: 异常事件监听 18 | * @author: dongyang_wu 19 | * @create: 2019-08-01 16:18 20 | */ 21 | @Slf4j 22 | @AllArgsConstructor 23 | public class TaskErrorListener { 24 | 25 | @Async 26 | @Order 27 | @EventListener(TaskErrorEvent.class) 28 | public void saveErrorTask(TaskErrorEvent event) { 29 | Map source = (Map) event.getSource(); 30 | TaskError taskError = (TaskError) source.get(EventConstant.EVENT_TASK); 31 | System.out.println(taskError); 32 | // 发邮件 // 记日志 33 | } 34 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/mapper/KpiMapper.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.coocaa.common.constant.TableConstant; 5 | import com.coocaa.prometheus.entity.Kpi; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.apache.ibatis.annotations.Select; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @description: KpiListing数据接口层 13 | * @author: dongyang_wu 14 | * @create: 2019-08-08 09:32 15 | */ 16 | public interface KpiMapper extends BaseMapper { 17 | String GET_PAGE_ALL = TableConstant.GET_PAGE_ALL + TableConstant.TABLE.TABLE_KPI + TableConstant.GET_PAGE_ALL_CONDITION; 18 | String GET_PAGE_ALL_SIZE = TableConstant.GET_PAGE_ALL_SIZE + TableConstant.TABLE.TABLE_KPI + TableConstant.GET_PAGE_ALL_SIZE_CONDITION; 19 | 20 | // 分页获取数据开始 21 | @Select(value = GET_PAGE_ALL) 22 | List getPageAll(Integer page, Integer count, String conditions, String orderBy, String sortType); 23 | 24 | @Select(value = GET_PAGE_ALL_SIZE) 25 | Integer getPageAllSize(@Param("conditions") String conditions); 26 | // 分页获取数据结束 27 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/mapper/KpiMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/mapper/MetisExceptionMapper.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.coocaa.common.constant.TableConstant; 5 | import com.coocaa.prometheus.entity.MetisException; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.apache.ibatis.annotations.Select; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @description: Metis异常dao层 13 | * @author: dongyang_wu 14 | * @create: 2019-08-07 09:57 15 | */ 16 | public interface MetisExceptionMapper extends BaseMapper { 17 | String GET_PAGE_ALL = TableConstant.GET_PAGE_ALL + TableConstant.TABLE.TABLE_METIS_EXCEPTION + TableConstant.GET_PAGE_ALL_CONDITION; 18 | String GET_PAGE_ALL_SIZE = TableConstant.GET_PAGE_ALL_SIZE + TableConstant.TABLE.TABLE_METIS_EXCEPTION + TableConstant.GET_PAGE_ALL_SIZE_CONDITION; 19 | 20 | // 分页获取数据开始 21 | @Select(value = GET_PAGE_ALL) 22 | List getPageAll(Integer page, Integer count, String conditions, String orderBy, String sortType); 23 | 24 | @Select(value = GET_PAGE_ALL_SIZE) 25 | Integer getPageAllSize(@Param("conditions") String conditions); 26 | // 分页获取数据结束 27 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/mapper/MetisExceptionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/rabbitMQ/TimingDataReceiverAndPusher.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.rabbitMQ; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.messaging.simp.SimpMessagingTemplate; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * @Auther: wyx 11 | * @Date: 2019-07-25 11:42 12 | * @Description: 接收定时数据并将数据推送给前端 13 | */ 14 | @Component 15 | @RabbitListener(queues = "timingData") 16 | public class TimingDataReceiverAndPusher { 17 | 18 | @Autowired 19 | private SimpMessagingTemplate simpMessagingTemplate; 20 | 21 | @RabbitHandler 22 | public void receiveAndPush(String message) { 23 | System.out.println("receiver: "); 24 | System.out.println(message); 25 | simpMessagingTemplate.convertAndSend("/monitoring/timingData", message); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/rabbitMQ/TimingDataSender.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.rabbitMQ; 2 | 3 | import org.springframework.amqp.core.AmqpTemplate; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * @Auther: wyx 9 | * @Date: 2019-07-25 11:40 10 | * @Description: 定时数据发送 11 | */ 12 | @Component("TimingDataSender") 13 | public class TimingDataSender { 14 | 15 | @Autowired 16 | private AmqpTemplate rabbitTemplate; 17 | 18 | public void send(String message) { 19 | this.rabbitTemplate.convertAndSend("timingData", message); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/service/KpiService.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.service; 2 | 3 | import com.coocaa.core.mybatis.base.BaseService; 4 | import com.coocaa.prometheus.entity.Kpi; 5 | 6 | public interface KpiService extends BaseService { 7 | 8 | 9 | Kpi create(Kpi kpi); 10 | } 11 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/service/MetisExceptionService.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.service; 2 | 3 | import com.coocaa.common.request.PageRequestBean; 4 | import com.coocaa.core.log.response.ResultBean; 5 | import com.coocaa.core.mybatis.base.BaseService; 6 | import com.coocaa.prometheus.entity.MetisException; 7 | import com.coocaa.prometheus.input.MetisExceptionInputVo; 8 | import org.springframework.http.ResponseEntity; 9 | 10 | /** 11 | * @description: MetisException服务类 12 | * @author: dongyang_wu 13 | * @create: 2019-08-07 10:02 14 | */ 15 | public interface MetisExceptionService extends BaseService { 16 | 17 | 18 | void update(MetisExceptionInputVo metisExceptionInputVo); 19 | 20 | ResponseEntity listByPage(PageRequestBean pageRequestBean); 21 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/service/impl/KpiServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.service.impl; 2 | 3 | import com.coocaa.core.mybatis.base.BaseServiceImpl; 4 | import com.coocaa.prometheus.entity.Kpi; 5 | import com.coocaa.prometheus.mapper.KpiMapper; 6 | import com.coocaa.prometheus.service.KpiService; 7 | import com.coocaa.prometheus.service.PromQLService; 8 | import com.coocaa.prometheus.util.PromQLUtil; 9 | import lombok.AllArgsConstructor; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.*; 13 | 14 | /** 15 | * @description: KpiListingService指标清单实现类 16 | * @author: dongyang_wu 17 | * @create: 2019-08-08 09:37 18 | */ 19 | @Service 20 | @AllArgsConstructor 21 | public class KpiServiceImpl extends BaseServiceImpl implements KpiService { 22 | private PromQLService promQLService; 23 | 24 | @Override 25 | public Kpi create(Kpi kpi) { 26 | // 检测指标表达式是否可行 27 | HashMap conditions = new HashMap<>(); 28 | conditions.put("instance", "172.16.33.31:9100"); 29 | String realQuery = PromQLUtil.getQueryConditionStr(kpi.getPromExpression(), conditions); 30 | promQLService.instantQuery(realQuery, null, null); 31 | kpi.insertOrUpdate(); 32 | return kpi; 33 | } 34 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/system/SystemExit.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.system; 2 | 3 | import com.coocaa.prometheus.util.TaskManager; 4 | import lombok.AllArgsConstructor; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.context.ApplicationEvent; 7 | import org.springframework.context.ApplicationListener; 8 | import org.springframework.context.event.ContextClosedEvent; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.Map; 12 | import java.util.concurrent.ScheduledFuture; 13 | 14 | /** 15 | * @author: dongyang_wu 16 | * @create: 2019-08-27 16:25 17 | * @description: 应用停止监听 18 | */ 19 | @Component 20 | @AllArgsConstructor 21 | @Slf4j 22 | public class SystemExit implements ApplicationListener { 23 | private TaskManager taskManager; 24 | 25 | @Override 26 | public void onApplicationEvent(ApplicationEvent event) { 27 | if (event instanceof ContextClosedEvent) { 28 | Map> scheduledTasks = taskManager.getScheduledTasks(); 29 | if (scheduledTasks.size() == 0) 30 | return; 31 | scheduledTasks.forEach((key, value) -> taskManager.removeCronTask(key)); 32 | log.info("停止所有定时任务"); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/system/SystemInit.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.system; 2 | 3 | import com.coocaa.prometheus.service.TaskService; 4 | import lombok.AllArgsConstructor; 5 | import org.springframework.boot.ApplicationArguments; 6 | import org.springframework.boot.ApplicationRunner; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * @description: 系统初始化启动定时任务 11 | * @author: dongyang_wu 12 | * @create: 2019-08-01 20:00 13 | */ 14 | @Component 15 | @AllArgsConstructor 16 | public class SystemInit implements ApplicationRunner { 17 | private TaskService taskService; 18 | 19 | @Override 20 | public void run(ApplicationArguments args) { 21 | taskService.bootstrapAllTask(); 22 | } 23 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/util/PromQLUtil.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.util; 2 | 3 | import org.springframework.util.CollectionUtils; 4 | import org.springframework.util.StringUtils; 5 | 6 | import java.util.*; 7 | 8 | /** 9 | * @program: intelligent_maintenance 10 | * @description: 普罗米修斯语法工具类 11 | * @author: dongyang_wu 12 | * @create: 2019-08-02 13:57 13 | */ 14 | public class PromQLUtil { 15 | 16 | public static String getQueryConditionStr(String key, String value) { 17 | StringBuffer sb = new StringBuffer(); 18 | sb.append(key).append("=\"").append(value).append("\""); 19 | return sb.toString(); 20 | } 21 | 22 | public static String getQueryConditionStr(String metricsName, Map conditions) { 23 | if (conditions == null) 24 | return metricsName.replaceAll("%s", ""); 25 | List conditionQuery = new ArrayList<>(); 26 | conditions.forEach((key, value) -> conditionQuery.add(getQueryConditionStr(key, value))); 27 | if (!CollectionUtils.isEmpty(conditionQuery)) { 28 | StringBuffer condition = new StringBuffer(); 29 | condition.append("{").append(StringUtils.collectionToDelimitedString(conditionQuery, ",")).append("}"); 30 | return metricsName.replaceAll("%s", condition.toString()); 31 | } 32 | return metricsName.replaceAll("%s", ""); 33 | } 34 | } -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/java/com/coocaa/prometheus/util/SingletonEnum.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus.util; 2 | 3 | import com.coocaa.core.tool.utils.SpringUtil; 4 | import com.coocaa.prometheus.service.*; 5 | import com.coocaa.prometheus.service.impl.AsyncServiceTask; 6 | import lombok.Getter; 7 | 8 | /** 9 | * @description: 枚举单例 10 | * @author: dongyang_wu 11 | * @create: 2019-08-01 14:12 12 | */ 13 | public enum SingletonEnum { 14 | INSTANCE; 15 | @Getter 16 | private KpiService kpiService; 17 | @Getter 18 | private AsyncServiceTask asyncServiceTask; 19 | @Getter 20 | private PromQLService promQLService; 21 | @Getter 22 | private TaskService taskService; 23 | @Getter 24 | private TaskManager taskManager; 25 | 26 | // 同时每个枚举实例都是static final类型的,也就表明只能被实例化一次 27 | SingletonEnum() { 28 | kpiService = SpringUtil.getBean(KpiService.class); 29 | asyncServiceTask = SpringUtil.getBean(AsyncServiceTask.class); 30 | promQLService = SpringUtil.getBean(PromQLService.class); 31 | taskService = SpringUtil.getBean(TaskService.class); 32 | taskManager = SpringUtil.getBean(TaskManager.class); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: aiops-prometheus 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: 39.108.106.167:8848 8 | config: 9 | server-addr: 39.108.106.167:8848 10 | file-extension: yaml 11 | sentinel: 12 | transport: 13 | dashboard: 47.107.139.6:8858 14 | 15 | profiles: 16 | active: dev -------------------------------------------------------------------------------- /aiops-service/aiops-prometheus/src/test/java/com/coocaa/prometheus/PromtheusApiTest.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.prometheus; 2 | 3 | import com.coocaa.core.log.response.ResultBean; 4 | import com.coocaa.prometheus.common.PromNorm; 5 | import com.coocaa.prometheus.service.PromQLService; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | 13 | 14 | /** 15 | * @program: intelligent-maintenance 16 | * @description: API测试 17 | * @author: dongyang_wu 18 | * @create: 2019-08-05 09:31 19 | */ 20 | @RunWith(SpringRunner.class) 21 | @SpringBootTest 22 | public class PromtheusApiTest { 23 | @Autowired 24 | private PromQLService promQLService; 25 | 26 | @Test 27 | public void testRest() { 28 | // ResponseEntity conditionByMetricsName = promQLService.getConditionByMetricsName(PromNorm.REQUEST_TOTAL.replace("%s", "")); 29 | // System.out.println(conditionByMetricsName.getBody().getData()); 30 | } 31 | } -------------------------------------------------------------------------------- /aiops-service/aiops-user/src/main/java/com/coocaa/user/UserApplication.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.coocaa.user; 17 | 18 | import com.coocaa.core.secure.constant.AppConstant; 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 22 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 23 | import org.springframework.cloud.openfeign.EnableFeignClients; 24 | 25 | /** 26 | * 用户模块启动器 27 | */ 28 | @SpringBootApplication(scanBasePackages = {"com.coocaa"}) 29 | @EnableDiscoveryClient 30 | @EnableCircuitBreaker 31 | @EnableFeignClients(AppConstant.BASE_PACKAGES) 32 | public class UserApplication { 33 | 34 | public static void main(String[] args) { 35 | SpringApplication.run(UserApplication.class, args); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /aiops-service/aiops-user/src/main/java/com/coocaa/user/mapper/TeamMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | id, name,admin_user_id,create_time,update_time 15 | 16 | -------------------------------------------------------------------------------- /aiops-service/aiops-user/src/main/java/com/coocaa/user/service/TeamService.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.user.service; 2 | 3 | import com.coocaa.common.request.PageRequestBean; 4 | import com.coocaa.core.log.response.ResultBean; 5 | import com.coocaa.core.mybatis.base.BaseService; 6 | import com.coocaa.user.entity.Team; 7 | import com.coocaa.user.entity.User; 8 | import com.coocaa.user.input.TeamInputVo; 9 | import com.coocaa.user.output.TeamOutputVo; 10 | import org.springframework.http.ResponseEntity; 11 | 12 | import java.util.List; 13 | import java.util.Set; 14 | 15 | 16 | public interface TeamService extends BaseService { 17 | 18 | ResponseEntity listByPage(PageRequestBean pageRequestBean); 19 | 20 | ResponseEntity listByPageWithUserCondition(PageRequestBean pageRequestBean); 21 | 22 | TeamOutputVo createTeam(TeamInputVo teamInputVo); 23 | 24 | Set getTeamUsers(List teamIds, String connection); 25 | } 26 | -------------------------------------------------------------------------------- /aiops-service/aiops-user/src/main/java/com/coocaa/user/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.user.service; 2 | 3 | import com.coocaa.common.request.RequestBean; 4 | import com.coocaa.user.entity.User; 5 | import com.coocaa.core.mybatis.base.BaseService; 6 | import com.coocaa.user.entity.UserInfo; 7 | import com.coocaa.user.input.UserInputVo; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @program: intelligent_maintenance 13 | * @description: 14 | * @author: dongyang_wu 15 | * @create: 2019-07-29 14:48 16 | */ 17 | public interface UserService extends BaseService { 18 | UserInfo userInfo(String account, String password); 19 | 20 | User getUser(); 21 | 22 | List getByAttr(RequestBean requestBean); 23 | 24 | User insertOrUpdate(UserInputVo userInputVo); 25 | 26 | User fillUserTeams(User user); 27 | 28 | } -------------------------------------------------------------------------------- /aiops-service/aiops-user/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: aiops-user 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: 39.108.106.167:8848 8 | config: 9 | server-addr: 39.108.106.167:8848 10 | file-extension: yaml 11 | profiles: 12 | active: dev 13 | 14 | 15 | -------------------------------------------------------------------------------- /aiops-service/aiops-user/src/test/java/com/coocaa/user/UserTestApplication.java: -------------------------------------------------------------------------------- 1 | package com.coocaa.user; 2 | 3 | /** 4 | * @program: intelligent_maintenance 5 | * @description: 6 | * @author: dongyang_wu 7 | * @create: 2019-07-31 11:05 8 | */ 9 | 10 | import com.coocaa.user.entity.User; 11 | import com.coocaa.user.mapper.UserMapper; 12 | import lombok.AllArgsConstructor; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.boot.test.context.SpringBootTest; 17 | import org.springframework.test.context.junit4.SpringRunner; 18 | 19 | /** 20 | * @program: intelligent_maintenance 21 | * @description: 22 | * @author: dongyang_wu 23 | * @create: 2019-07-30 17:31 24 | */ 25 | @RunWith(SpringRunner.class) 26 | @SpringBootTest(classes={UserApplication.class}) 27 | public class UserTestApplication { 28 | @Autowired 29 | private UserMapper userMapper; 30 | @Test 31 | public void testForeignKey(){ 32 | User user = userMapper.getUser(1L); 33 | System.out.println(user); 34 | } 35 | } -------------------------------------------------------------------------------- /docs/config/aiops-detector-dev.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 10005 3 | swagger: 4 | enable: true 5 | spring: 6 | jackson: 7 | date-format: yyyy-MM-dd HH:mm:ss 8 | time-zone: GMT+8 9 | default-property-inclusion: non_null 10 | datasource: 11 | url: jdbc:mysql://123.56.7.250:3306/metis?allowMultiQueries=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT 12 | username: root 13 | password: metis@123 14 | # 使用druid数据源 15 | type: com.alibaba.druid.pool.DruidDataSource 16 | driver-class-name: com.mysql.cj.jdbc.Driver 17 | filters: stat 18 | maxActive: 20 19 | initialSize: 1 20 | maxWait: 60000 21 | minIdle: 1 22 | timeBetweenEvictionRunsMillis: 60000 23 | minEvictableIdleTimeMillis: 300000 24 | validationQuery: select 'x' 25 | testWhileIdle: true 26 | testOnBorrow: false 27 | testOnReturn: false 28 | poolPreparedStatements: true 29 | maxOpenPreparedStatements: 20 30 | rabbitmq: 31 | port: 5672 32 | host: 123.56.7.250 33 | username: guest 34 | password: guest 35 | management: 36 | endpoints: 37 | web: 38 | exposure: 39 | include: '*' 40 | security: 41 | enabled: false 42 | 43 | aiops: 44 | env: dev 45 | name: aiops-detector 46 | metis: 47 | start: 48 | bootrap: http://123.56.7.250:8080 -------------------------------------------------------------------------------- /docs/config/aiops-log-dev.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 10004 3 | web: 4 | server: 5 | prometheus: 6 | port: 9090 7 | spring: 8 | datasource: 9 | url: jdbc:mysql://47.102.156.24:3306/aiops?useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2b8 10 | username: root 11 | password: 123 12 | # 使用druid数据源 13 | type: com.alibaba.druid.pool.DruidDataSource 14 | driver-class-name: com.mysql.cj.jdbc.Driver 15 | filters: stat 16 | maxActive: 20 17 | initialSize: 1 18 | maxWait: 60000 19 | minIdle: 1 20 | timeBetweenEvictionRunsMillis: 60000 21 | minEvictableIdleTimeMillis: 300000 22 | validationQuery: select 'x' 23 | testWhileIdle: true 24 | testOnBorrow: false 25 | testOnReturn: false 26 | poolPreparedStatements: true 27 | maxOpenPreparedStatements: 20 28 | 29 | management: 30 | endpoints: 31 | web: 32 | exposure: 33 | include: '*' 34 | security: 35 | enabled: false 36 | 37 | aiops: 38 | env: dev 39 | name: aiops-log -------------------------------------------------------------------------------- /docs/config/aiops-prometheus-dev.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 10003 3 | swagger: 4 | enable: true 5 | web: 6 | server: 7 | prometheus: 8 | url: http://123.207.54.158:9090/ 9 | apiUrl: http://123.207.54.158:9090/api/v1/ 10 | prometheus: 11 | metricsPath: /root/devops-project/.docker/prometheus/metricsPath/ 12 | springbootServicePath: /root/devops-project/.docker/prometheus/springbootServicePath/ 13 | spring: 14 | jackson: 15 | date-format: yyyy-MM-dd HH:mm:ss 16 | time-zone: GMT+8 17 | default-property-inclusion: non_null 18 | datasource: 19 | url: jdbc:mysql://47.102.156.24:3306/aiops?useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2b8 20 | username: root 21 | password: 123 22 | # 使用druid数据源 23 | type: com.alibaba.druid.pool.DruidDataSource 24 | driver-class-name: com.mysql.cj.jdbc.Driver 25 | filters: stat 26 | maxActive: 20 27 | initialSize: 1 28 | maxWait: 60000 29 | minIdle: 1 30 | timeBetweenEvictionRunsMillis: 60000 31 | minEvictableIdleTimeMillis: 300000 32 | validationQuery: select 'x' 33 | testWhileIdle: true 34 | testOnBorrow: false 35 | testOnReturn: false 36 | poolPreparedStatements: true 37 | maxOpenPreparedStatements: 20 38 | rabbitmq: 39 | port: 5672 40 | host: 123.56.7.250 41 | username: guest 42 | password: guest 43 | management: 44 | endpoints: 45 | web: 46 | exposure: 47 | include: '*' 48 | security: 49 | enabled: false 50 | 51 | aiops: 52 | env: dev 53 | name: aiops-prometheus -------------------------------------------------------------------------------- /docs/config/aiops-user-dev.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 10001 3 | swagger: 4 | enable: true 5 | spring: 6 | jackson: 7 | date-format: yyyy-MM-dd HH:mm:ss 8 | time-zone: GMT+8 9 | default-property-inclusion: non_null 10 | redis: 11 | database: 2 12 | host: 47.102.156.24 13 | port: 6379 14 | pool: 15 | max-active: 20 16 | datasource: 17 | name: test 18 | url: jdbc:mysql://47.102.156.24:3306/aiops?useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2b8 19 | username: root 20 | password: 123 21 | # 使用druid数据源 22 | type: com.alibaba.druid.pool.DruidDataSource 23 | driver-class-name: com.mysql.cj.jdbc.Driver 24 | filters: stat 25 | maxActive: 20 26 | initialSize: 1 27 | maxWait: 60000 28 | minIdle: 1 29 | timeBetweenEvictionRunsMillis: 60000 30 | minEvictableIdleTimeMillis: 300000 31 | validationQuery: select 'x' 32 | testWhileIdle: true 33 | testOnBorrow: false 34 | testOnReturn: false 35 | poolPreparedStatements: true 36 | maxOpenPreparedStatements: 20 37 | 38 | management: 39 | endpoints: 40 | web: 41 | exposure: 42 | include: '*' 43 | security: 44 | enabled: false 45 | 46 | aiops: 47 | env: dev 48 | name: aiops-user 49 | 50 | -------------------------------------------------------------------------------- /docs/config/env.list: -------------------------------------------------------------------------------- 1 | MODE=standalone 2 | SPRING_DATASOURCE_PLATFORM=mysql 3 | MYSQL_MASTER_SERVICE_DB_NAME=nacos_config 4 | MYSQL_MASTER_SERVICE_HOST=172.17.51.202 5 | MYSQL_MASTER_SERVICE_USER=root 6 | MYSQL_MASTER_SERVICE_PASSWORD=123 7 | MYSQL_SLAVE_SERVICE_HOST=172.17.51.202 8 | MYSQL_MASTER_SERVICE_DB_NAME=nacos_config -------------------------------------------------------------------------------- /docs/接口文档.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vipsql/AIOPS/7acff6391a99f50df71c905753859b2ed5881650/docs/接口文档.pdf --------------------------------------------------------------------------------