From d7b1d619a567dd48eee912c2f262d3b2bda78725 Mon Sep 17 00:00:00 2001 From: Li Haoyu Date: Tue, 3 Dec 2019 19:33:02 +0800 Subject: [PATCH] Linux服务器监控模块创建 --- .mvn/wrapper/MavenWrapperDownloader.java | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .mvn/wrapper/maven-wrapper.jar | Bin 0 -> 48337 bytes .mvn/wrapper/maven-wrapper.properties | 1 + pom.xml | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/VehicleApplication.java | 31 +++++++++++++++++++++++++++++++ src/main/java/com/objecteye/common/CommonPage.java | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/common/CommonResult.java | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/common/GeneralContent.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/common/IErrorCode.java | 11 +++++++++++ src/main/java/com/objecteye/common/ResultCode.java | 29 +++++++++++++++++++++++++++++ src/main/java/com/objecteye/config/ExecutorConfig.java | 37 +++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/config/MyBatisConfig.java | 10 ++++++++++ src/main/java/com/objecteye/config/RabbitmqConfig.java | 41 +++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/config/RestTemplateConfig.java | 30 ++++++++++++++++++++++++++++++ src/main/java/com/objecteye/config/Swagger2Config.java | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/controller/LogFileListenerController.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/controller/OccupationOfBasicResourcesController.java | 31 +++++++++++++++++++++++++++++++ src/main/java/com/objecteye/exception/CustomXException.java | 36 ++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/exception/GeneralExceptionHandler.java | 22 ++++++++++++++++++++++ src/main/java/com/objecteye/service/ILogFileListenerService.java | 41 +++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/service/IOccupationOfBasicResourcesService.java | 19 +++++++++++++++++++ src/main/java/com/objecteye/service/impl/LogFileListenerServiceImpl.java | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/service/impl/OccupationOfBasicResourcesServiceImpl.java | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/shell_files/arp_cache.sh | 17 +++++++++++++++++ src/main/java/com/objecteye/shell_files/bandwidth.sh | 6 ++++++ src/main/java/com/objecteye/shell_files/common_applications.sh | 11 +++++++++++ src/main/java/com/objecteye/shell_files/cpu_info.sh | 7 +++++++ src/main/java/com/objecteye/shell_files/cpu_intensive_processes.sh | 13 +++++++++++++ src/main/java/com/objecteye/shell_files/cpu_temp.sh | 15 +++++++++++++++ src/main/java/com/objecteye/shell_files/cpu_utilization.sh | 33 +++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/shell_files/cron_history.sh | 18 ++++++++++++++++++ src/main/java/com/objecteye/shell_files/current_ram.sh | 14 ++++++++++++++ src/main/java/com/objecteye/shell_files/disk_partitions.sh | 4 ++++ src/main/java/com/objecteye/shell_files/docker_processes.sh | 17 +++++++++++++++++ src/main/java/com/objecteye/shell_files/download_transfer_rate.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/shell_files/general_info.sh | 28 ++++++++++++++++++++++++++++ src/main/java/com/objecteye/shell_files/internet_speed.sh | 9 +++++++++ src/main/java/com/objecteye/shell_files/io_stats.sh | 7 +++++++ src/main/java/com/objecteye/shell_files/ip_addresses.sh | 18 ++++++++++++++++++ src/main/java/com/objecteye/shell_files/load_avg.sh | 15 +++++++++++++++ src/main/java/com/objecteye/shell_files/logged_in_users.sh | 4 ++++ src/main/java/com/objecteye/shell_files/memcached.sh | 7 +++++++ src/main/java/com/objecteye/shell_files/memory_info.sh | 4 ++++ src/main/java/com/objecteye/shell_files/network_connections.sh | 13 +++++++++++++ src/main/java/com/objecteye/shell_files/number_of_cpu_cores.sh | 7 +++++++ src/main/java/com/objecteye/shell_files/ping.sh | 28 ++++++++++++++++++++++++++++ src/main/java/com/objecteye/shell_files/pm2.sh | 32 ++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/shell_files/raid_status.sh | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/shell_files/ram_intensive_processes.sh | 12 ++++++++++++ src/main/java/com/objecteye/shell_files/recent_account_logins.sh | 10 ++++++++++ src/main/java/com/objecteye/shell_files/redis.sh | 18 ++++++++++++++++++ src/main/java/com/objecteye/shell_files/scheduled_crons.sh | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/shell_files/swap.sh | 19 +++++++++++++++++++ src/main/java/com/objecteye/shell_files/upload_transfer_rate.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/shell_files/user_accounts.sh | 14 ++++++++++++++ src/main/java/com/objecteye/utils/ApplicationContextUtil.java | 29 +++++++++++++++++++++++++++++ src/main/java/com/objecteye/utils/FileUtils.java | 35 +++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/utils/RabbbitmqConsumer.java | 20 ++++++++++++++++++++ src/main/java/com/objecteye/websocket/MyHandshakeInterceptor.java | 32 ++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/websocket/MyWebSocketHandler.java | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/objecteye/websocket/WebSocketConfigClass.java | 33 +++++++++++++++++++++++++++++++++ src/main/resources/META-INF/additional-spring-configuration-metadata.json | 13 +++++++++++++ src/main/resources/application-dev.yml | 23 +++++++++++++++++++++++ src/main/resources/application-prop.yml | 0 src/main/resources/application.yml | 31 +++++++++++++++++++++++++++++++ 65 files changed, 2251 insertions(+), 0 deletions(-) create mode 100644 .mvn/wrapper/MavenWrapperDownloader.java create mode 100644 .mvn/wrapper/maven-wrapper.jar create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 pom.xml create mode 100644 src/main/java/com/objecteye/VehicleApplication.java create mode 100644 src/main/java/com/objecteye/common/CommonPage.java create mode 100644 src/main/java/com/objecteye/common/CommonResult.java create mode 100644 src/main/java/com/objecteye/common/GeneralContent.java create mode 100644 src/main/java/com/objecteye/common/IErrorCode.java create mode 100644 src/main/java/com/objecteye/common/ResultCode.java create mode 100644 src/main/java/com/objecteye/config/ExecutorConfig.java create mode 100644 src/main/java/com/objecteye/config/MyBatisConfig.java create mode 100644 src/main/java/com/objecteye/config/RabbitmqConfig.java create mode 100644 src/main/java/com/objecteye/config/RestTemplateConfig.java create mode 100644 src/main/java/com/objecteye/config/Swagger2Config.java create mode 100644 src/main/java/com/objecteye/controller/LogFileListenerController.java create mode 100644 src/main/java/com/objecteye/controller/OccupationOfBasicResourcesController.java create mode 100644 src/main/java/com/objecteye/exception/CustomXException.java create mode 100644 src/main/java/com/objecteye/exception/GeneralExceptionHandler.java create mode 100644 src/main/java/com/objecteye/service/ILogFileListenerService.java create mode 100644 src/main/java/com/objecteye/service/IOccupationOfBasicResourcesService.java create mode 100644 src/main/java/com/objecteye/service/impl/LogFileListenerServiceImpl.java create mode 100644 src/main/java/com/objecteye/service/impl/OccupationOfBasicResourcesServiceImpl.java create mode 100644 src/main/java/com/objecteye/shell_files/arp_cache.sh create mode 100644 src/main/java/com/objecteye/shell_files/bandwidth.sh create mode 100644 src/main/java/com/objecteye/shell_files/common_applications.sh create mode 100644 src/main/java/com/objecteye/shell_files/cpu_info.sh create mode 100644 src/main/java/com/objecteye/shell_files/cpu_intensive_processes.sh create mode 100644 src/main/java/com/objecteye/shell_files/cpu_temp.sh create mode 100644 src/main/java/com/objecteye/shell_files/cpu_utilization.sh create mode 100644 src/main/java/com/objecteye/shell_files/cron_history.sh create mode 100644 src/main/java/com/objecteye/shell_files/current_ram.sh create mode 100644 src/main/java/com/objecteye/shell_files/disk_partitions.sh create mode 100644 src/main/java/com/objecteye/shell_files/docker_processes.sh create mode 100644 src/main/java/com/objecteye/shell_files/download_transfer_rate.sh create mode 100644 src/main/java/com/objecteye/shell_files/general_info.sh create mode 100644 src/main/java/com/objecteye/shell_files/internet_speed.sh create mode 100644 src/main/java/com/objecteye/shell_files/io_stats.sh create mode 100644 src/main/java/com/objecteye/shell_files/ip_addresses.sh create mode 100644 src/main/java/com/objecteye/shell_files/load_avg.sh create mode 100644 src/main/java/com/objecteye/shell_files/logged_in_users.sh create mode 100644 src/main/java/com/objecteye/shell_files/memcached.sh create mode 100644 src/main/java/com/objecteye/shell_files/memory_info.sh create mode 100644 src/main/java/com/objecteye/shell_files/network_connections.sh create mode 100644 src/main/java/com/objecteye/shell_files/number_of_cpu_cores.sh create mode 100644 src/main/java/com/objecteye/shell_files/ping.sh create mode 100644 src/main/java/com/objecteye/shell_files/pm2.sh create mode 100644 src/main/java/com/objecteye/shell_files/raid_status.sh create mode 100644 src/main/java/com/objecteye/shell_files/ram_intensive_processes.sh create mode 100644 src/main/java/com/objecteye/shell_files/recent_account_logins.sh create mode 100644 src/main/java/com/objecteye/shell_files/redis.sh create mode 100644 src/main/java/com/objecteye/shell_files/scheduled_crons.sh create mode 100644 src/main/java/com/objecteye/shell_files/swap.sh create mode 100644 src/main/java/com/objecteye/shell_files/upload_transfer_rate.sh create mode 100644 src/main/java/com/objecteye/shell_files/user_accounts.sh create mode 100644 src/main/java/com/objecteye/utils/ApplicationContextUtil.java create mode 100644 src/main/java/com/objecteye/utils/FileUtils.java create mode 100644 src/main/java/com/objecteye/utils/RabbbitmqConsumer.java create mode 100644 src/main/java/com/objecteye/websocket/MyHandshakeInterceptor.java create mode 100644 src/main/java/com/objecteye/websocket/MyWebSocketHandler.java create mode 100644 src/main/java/com/objecteye/websocket/WebSocketConfigClass.java create mode 100644 src/main/resources/META-INF/additional-spring-configuration-metadata.json create mode 100644 src/main/resources/application-dev.yml create mode 100644 src/main/resources/application-prop.yml create mode 100644 src/main/resources/application.yml diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000..7f91a56 --- /dev/null +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..01e6799 Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..cd0d451 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fcae28e --- /dev/null +++ b/pom.xml @@ -0,0 +1,204 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.6.RELEASE + + + com.objecteye.listener + linuxListener + 0.0.1-SNAPSHOT + linuxListener + Project for Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + mysql + mysql-connector-java + 8.0.15 + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-websocket + 1.5.6.RELEASE + + + org.apache.commons + commons-pool2 + 2.4.2 + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + + com.alibaba + druid-spring-boot-starter + 1.1.10 + + + + io.jsonwebtoken + jjwt + 0.9.0 + + + + net.logstash.logback + logstash-logback-encoder + 4.8 + + + io.springfox + springfox-swagger2 + 2.7.0 + + + io.springfox + springfox-swagger-ui + 2.7.0 + + + cn.hutool + hutool-all + 4.5.7 + + + com.github.pagehelper + pagehelper-spring-boot-autoconfigure + 1.2.9 + + + com.github.pagehelper + pagehelper + 5.0.0 + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + + org.springframework.data + spring-data-commons + 2.1.5.RELEASE + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.2.0 + + + commons-net + commons-net + 3.6 + + + + org.mybatis + mybatis + 3.4.6 + + + org.apache.commons + commons-lang3 + 3.8.1 + + + org.apache.poi + poi-ooxml + 3.9 + + + com.alibaba + fastjson + 1.2.54 + + + org.apache.httpcomponents + httpclient + 4.5.7 + + + org.apache.httpcomponents + httpmime + 4.5.5 + + + org.junit.jupiter + junit-jupiter-api + 5.2.0 + compile + + + org.projectlombok + lombok + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + + + org.springframework.boot + spring-boot-starter-amqp + + + net.sourceforge.owlapi + benchmarks + 4.1.0-RC2 + test + + + + + + + src/main/java + + **/*.xml + + true + + + src/main/resources + true + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/src/main/java/com/objecteye/VehicleApplication.java b/src/main/java/com/objecteye/VehicleApplication.java new file mode 100644 index 0000000..0cd601d --- /dev/null +++ b/src/main/java/com/objecteye/VehicleApplication.java @@ -0,0 +1,31 @@ +package com.objecteye; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.TaskScheduler; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@SpringBootApplication +@EnableTransactionManagement +@EnableScheduling +@EnableAsync +public class VehicleApplication { + + public static void main(String[] args) { + ConfigurableApplicationContext run = SpringApplication.run(VehicleApplication.class, args); + } + + @Bean + public TaskScheduler taskScheduler(){ + + ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); + threadPoolTaskScheduler.setPoolSize(3); + threadPoolTaskScheduler.initialize(); + return threadPoolTaskScheduler; + } +} diff --git a/src/main/java/com/objecteye/common/CommonPage.java b/src/main/java/com/objecteye/common/CommonPage.java new file mode 100644 index 0000000..074d31d --- /dev/null +++ b/src/main/java/com/objecteye/common/CommonPage.java @@ -0,0 +1,84 @@ +package com.objecteye.common; + +import com.github.pagehelper.PageInfo; +import org.springframework.data.domain.Page; + +import java.util.List; + +/** + * 分页数据封装类 + */ +public class CommonPage { + private Integer pageNum; + private Integer pageSize; + private Integer totalPage; + private Long total; + private List list; + + /** + * 将PageHelper分页后的list转为分页信息 + */ + public static CommonPage restPage(List list) { + CommonPage result = new CommonPage(); + PageInfo pageInfo = new PageInfo(list); + result.setTotalPage(pageInfo.getPages()); + result.setPageNum(pageInfo.getPageNum()); + result.setPageSize(pageInfo.getPageSize()); + result.setTotal(pageInfo.getTotal()); + result.setList(pageInfo.getList()); + return result; + } + + /** + * 将SpringData分页后的list转为分页信息 + */ + public static CommonPage restPage(Page pageInfo) { + CommonPage result = new CommonPage(); + result.setTotalPage(pageInfo.getTotalPages()); + result.setPageNum(pageInfo.getNumber()); + result.setPageSize(pageInfo.getSize()); + result.setTotal(pageInfo.getTotalElements()); + result.setList(pageInfo.getContent()); + return result; + } + + public Integer getPageNum() { + return pageNum; + } + + public void setPageNum(Integer pageNum) { + this.pageNum = pageNum; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public Integer getTotalPage() { + return totalPage; + } + + public void setTotalPage(Integer totalPage) { + this.totalPage = totalPage; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public Long getTotal() { + return total; + } + + public void setTotal(Long total) { + this.total = total; + } +} diff --git a/src/main/java/com/objecteye/common/CommonResult.java b/src/main/java/com/objecteye/common/CommonResult.java new file mode 100644 index 0000000..aa98738 --- /dev/null +++ b/src/main/java/com/objecteye/common/CommonResult.java @@ -0,0 +1,137 @@ +package com.objecteye.common; + +/** + * 通用返回对象 + */ +public class CommonResult { + private long code; + private String message; + private T data; + + + protected CommonResult() { + } + + protected CommonResult(long code, String message, T data) { + this.code = code; + this.message = message; + this.data = data; + } + protected CommonResult(long code, String message) { + this.code = code; + this.message = message; + } + + /** + * 成功返回结果 + * + * @param data 获取的数据 + */ + public static CommonResult success(T data) { + return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data); + } + + /** + * 成功返回结果 + * + * @param data 获取的数据 + * @param message 提示信息 + */ + public static CommonResult success(T data, String message) { + return new CommonResult(ResultCode.SUCCESS.getCode(), message, data); + } + + /** + * 成功返回结果 + * + * @param data 获取的数据 + * @param message 提示信息 + */ + public static CommonResult success(int code, String message, T data) { + return new CommonResult(code, message, data); + } + + /** + * 失败返回结果 + * @param errorCode 错误码 + */ + public static CommonResult failed(IErrorCode errorCode) { + return new CommonResult(errorCode.getCode(), errorCode.getMessage(), null); + } + + /** + * 失败返回结果 + * @param message 提示信息 + */ + public static CommonResult failed(String message) { + return new CommonResult(ResultCode.FAILED.getCode(), message, null); + } + + /** + * 失败返回结果 + * @param message 提示信息 + */ + public static CommonResult failed(T data,String message) { + return new CommonResult(ResultCode.FAILED.getCode(), message,data); + } + + /** + * 失败返回结果 + */ + public static CommonResult failed() { + return failed(ResultCode.FAILED); + } + + /** + * 参数验证失败返回结果 + */ + public static CommonResult validateFailed() { + return failed(ResultCode.VALIDATE_FAILED); + } + + /** + * 参数验证失败返回结果 + * @param message 提示信息 + */ + public static CommonResult validateFailed(String message) { + return new CommonResult(ResultCode.VALIDATE_FAILED.getCode(), message, null); + } + + /** + * 未登录返回结果 + */ + public static CommonResult unauthorized(T data) { + return new CommonResult(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data); + } + + /** + * 未授权返回结果 + */ + public static CommonResult forbidden(T data) { + return new CommonResult(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data); + } + + public long getCode() { + return code; + } + + public void setCode(long code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/src/main/java/com/objecteye/common/GeneralContent.java b/src/main/java/com/objecteye/common/GeneralContent.java new file mode 100644 index 0000000..0756876 --- /dev/null +++ b/src/main/java/com/objecteye/common/GeneralContent.java @@ -0,0 +1,50 @@ +package com.objecteye.common; + +import java.util.HashMap; +import java.util.Map; + +public class GeneralContent { + /** + * key: 日志文件的key, value: 日志文件存放位置 + */ + public final static String REDIS_LOG_KEY_PATH = "redisLogKeyPath"; + /** + * sh功能脚本map + */ + public final static Map MODULE_MAP = new HashMap<>(); + + static { + MODULE_MAP.put("arp_cache", "/shell_files/arp_cache.sh"); + MODULE_MAP.put("bandwidth", "/shell_files/bandwidth.sh"); + MODULE_MAP.put("common_applications", "/shell_files/common_applications.sh"); + MODULE_MAP.put("cpu_info", "/shell_files/cpu_info.sh"); + MODULE_MAP.put("cpu_intensive_processes", "/shell_files/cpu_intensive_processes.sh"); + MODULE_MAP.put("cpu_temp", "/shell_files/cpu_temp.sh"); + MODULE_MAP.put("cpu_utilization", "/shell_files/cpu_utilization.sh"); + MODULE_MAP.put("cron_history", "/shell_files/cron_history.sh"); + MODULE_MAP.put("current_ram", "/shell_files/current_ram.sh"); + MODULE_MAP.put("disk_partitions", "/shell_files/disk_partitions.sh"); + MODULE_MAP.put("docker_processes", "/shell_files/docker_processes.sh"); + MODULE_MAP.put("download_transfer_rate", "/shell_files/download_transfer_rate.sh"); + MODULE_MAP.put("general_info", "/shell_files/general_info.sh"); + MODULE_MAP.put("internet_speed", "/shell_files/internet_speed.sh"); + MODULE_MAP.put("io_stats", "/shell_files/io_stats.sh"); + MODULE_MAP.put("ip_addresses", "/shell_files/ip_addresses.sh"); + MODULE_MAP.put("load_avg", "/shell_files/load_avg.sh"); + MODULE_MAP.put("logged_in_users", "/shell_files/logged_in_users.sh"); + MODULE_MAP.put("memcached", "/shell_files/memcached.sh"); + MODULE_MAP.put("memory_info", "/shell_files/memory_info.sh"); + MODULE_MAP.put("network_connections", "/shell_files/network_connections.sh"); + MODULE_MAP.put("number_of_cpu_cores", "/shell_files/number_of_cpu_cores.sh"); + MODULE_MAP.put("ping", "/shell_files/ping.sh"); + MODULE_MAP.put("pm2", "/shell_files/pm2.sh"); + MODULE_MAP.put("raid_status", "/shell_files/raid_status.sh"); + MODULE_MAP.put("ram_intensive_processes", "/shell_files/ram_intensive_processes.sh"); + MODULE_MAP.put("recent_account_logins", "/shell_files/recent_account_logins.sh"); + MODULE_MAP.put("redis", "/shell_files/redis.sh"); + MODULE_MAP.put("scheduled_crons", "/shell_files/scheduled_crons.sh"); + MODULE_MAP.put("swap", "/shell_files/swap.sh"); + MODULE_MAP.put("upload_transfer_rate", "/shell_files/upload_transfer_rate.sh"); + MODULE_MAP.put("user_accounts", "/shell_files/user_accounts.sh"); + } +} diff --git a/src/main/java/com/objecteye/common/IErrorCode.java b/src/main/java/com/objecteye/common/IErrorCode.java new file mode 100644 index 0000000..b8408a8 --- /dev/null +++ b/src/main/java/com/objecteye/common/IErrorCode.java @@ -0,0 +1,11 @@ +package com.objecteye.common; + +/** + * 封装API的错误码 + + */ +public interface IErrorCode { + long getCode(); + + String getMessage(); +} diff --git a/src/main/java/com/objecteye/common/ResultCode.java b/src/main/java/com/objecteye/common/ResultCode.java new file mode 100644 index 0000000..3960161 --- /dev/null +++ b/src/main/java/com/objecteye/common/ResultCode.java @@ -0,0 +1,29 @@ +package com.objecteye.common; + +/** + * 枚举了一些常用API操作码 + */ +public enum ResultCode implements IErrorCode { + SUCCESS(200, "操作成功"), + FAILED(500, "操作失败"), + VALIDATE_FAILED(404, "参数检验失败"), + UNAUTHORIZED(401, "暂未登录或token已经过期"), + FORBIDDEN(403, "没有相关权限"); + private long code; + private String message; + + private ResultCode(long code, String message) { + this.code = code; + this.message = message; + } + + @Override + public long getCode() { + return code; + } + + @Override + public String getMessage() { + return message; + } +} diff --git a/src/main/java/com/objecteye/config/ExecutorConfig.java b/src/main/java/com/objecteye/config/ExecutorConfig.java new file mode 100644 index 0000000..b38e711 --- /dev/null +++ b/src/main/java/com/objecteye/config/ExecutorConfig.java @@ -0,0 +1,37 @@ +package com.objecteye.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.task.TaskExecutor; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.ThreadPoolExecutor; + +/** + * @author yumiu + */ +@Configuration +@EnableAsync +public class ExecutorConfig { + + @Bean + public TaskExecutor taskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + // 设置核心线程数 + executor.setCorePoolSize(5); + // 设置最大线程数 + executor.setMaxPoolSize(20); + // 设置队列容量 + executor.setQueueCapacity(50); + // 设置线程活跃时间(秒) + executor.setKeepAliveSeconds(60); + //executor.setThreadNamePrefix("hello-"); + // 设置拒绝策略 + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + // 等待所有任务结束后再关闭线程池 + executor.setWaitForTasksToCompleteOnShutdown(true); + return executor; + } +} diff --git a/src/main/java/com/objecteye/config/MyBatisConfig.java b/src/main/java/com/objecteye/config/MyBatisConfig.java new file mode 100644 index 0000000..902ff57 --- /dev/null +++ b/src/main/java/com/objecteye/config/MyBatisConfig.java @@ -0,0 +1,10 @@ +package com.objecteye.config; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@MapperScan({"com.objecteye.mapper"}) +public class MyBatisConfig { + +} diff --git a/src/main/java/com/objecteye/config/RabbitmqConfig.java b/src/main/java/com/objecteye/config/RabbitmqConfig.java new file mode 100644 index 0000000..1355bb8 --- /dev/null +++ b/src/main/java/com/objecteye/config/RabbitmqConfig.java @@ -0,0 +1,41 @@ +package com.objecteye.config; + + +import org.springframework.amqp.core.*; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +@Configuration +public class RabbitmqConfig { + public static final String QUEUE_INFORM_LISTENER = "queue_inform_listener"; + + public static final String EXCHANGE_TOPICS_INFORM="exchange_topics_inform"; + + /** + * + * 配置交换机 + * ExchangeBuilder提供了fonout,direct,topic,header的交换机的配置 + * @return + */ + @Bean(EXCHANGE_TOPICS_INFORM) + public Exchange EXCHANGE_TOPICS_INFORM(){ + return ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build(); + } + + /** + * 声明队列 + * @return + */ + @Bean(QUEUE_INFORM_LISTENER) + public Queue QUEUE_INFORM_STORE(){ + return new Queue(QUEUE_INFORM_LISTENER); + } + + //绑定队列到交换机 + @Bean + public Binding BINDING_QUEUE_INFORM_STORE(@Qualifier(QUEUE_INFORM_LISTENER) Queue queue, @Qualifier(EXCHANGE_TOPICS_INFORM)Exchange exchange){ + return BindingBuilder.bind(queue).to(exchange).with("inform.#.listener.#").noargs(); + } +} diff --git a/src/main/java/com/objecteye/config/RestTemplateConfig.java b/src/main/java/com/objecteye/config/RestTemplateConfig.java new file mode 100644 index 0000000..ad62ec9 --- /dev/null +++ b/src/main/java/com/objecteye/config/RestTemplateConfig.java @@ -0,0 +1,30 @@ +package com.objecteye.config; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +/** + * @author yumiu + */ +@Configuration +public class RestTemplateConfig { + + @Bean + public RestTemplate restTemplate(ClientHttpRequestFactory factory) { + return new RestTemplate(factory); + } + + @Bean + public ClientHttpRequestFactory simpleClientHttpRequestFactory() { + SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); + //单位为ms + factory.setReadTimeout(5000); + //单位为ms + factory.setConnectTimeout(5000); + return factory; + } +} diff --git a/src/main/java/com/objecteye/config/Swagger2Config.java b/src/main/java/com/objecteye/config/Swagger2Config.java new file mode 100644 index 0000000..5001260 --- /dev/null +++ b/src/main/java/com/objecteye/config/Swagger2Config.java @@ -0,0 +1,87 @@ +package com.objecteye.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.ApiKey; +import springfox.documentation.service.AuthorizationScope; +import springfox.documentation.service.SecurityReference; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.ArrayList; +import java.util.List; + +/** + * Swagger2API文档的配置 + */ +@Configuration +@EnableSwagger2 +public class Swagger2Config { + @Bean + public Docket createRestApi(){ + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.objecteye.controller")) + .paths(PathSelectors.any()) + .build() + .securitySchemes(securitySchemes()) + .securityContexts(securityContexts()); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("人像平台后台系统") + .description("人像平台后台模块") + .contact("face") + .version("1.0") + .build(); + } + + private List securitySchemes() { + //设置请求头信息 + List result = new ArrayList<>(); + ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header"); + result.add(apiKey); + return result; + } + + private List securityContexts() { + //设置需要登录认证的路径 + List result = new ArrayList<>(); + result.add(getContextByPath("/alarm/.*")); + result.add(getContextByPath("/capture/.*")); + result.add(getContextByPath("/deploy/.*")); + result.add(getContextByPath("/equipment/.*")); + result.add(getContextByPath("/feature/.*")); + result.add(getContextByPath("/location/.*")); + result.add(getContextByPath("/personnel/.*")); + result.add(getContextByPath("/preview/.*")); + result.add(getContextByPath("/record/.*")); + result.add(getContextByPath("/user/.*")); + result.add(getContextByPath("/areaEquipment/.*")); + return result; + } + + private SecurityContext getContextByPath(String pathRegex){ + return SecurityContext.builder() + .securityReferences(defaultAuth()) + .forPaths(PathSelectors.regex(pathRegex)) + .build(); + } + + private List defaultAuth() { + List result = new ArrayList<>(); + AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; + authorizationScopes[0] = authorizationScope; + result.add(new SecurityReference("Authorization", authorizationScopes)); + return result; + } +} diff --git a/src/main/java/com/objecteye/controller/LogFileListenerController.java b/src/main/java/com/objecteye/controller/LogFileListenerController.java new file mode 100644 index 0000000..9c8ccd5 --- /dev/null +++ b/src/main/java/com/objecteye/controller/LogFileListenerController.java @@ -0,0 +1,46 @@ +package com.objecteye.controller; + +import com.objecteye.common.CommonResult; +import com.objecteye.service.ILogFileListenerService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.util.Map; + +@RestController +@Api(tags = "logListener", description = "日志监控") +@RequestMapping("/logListener") +@CrossOrigin +public class LogFileListenerController { + @Autowired + private ILogFileListenerService iLogFileListenerService; + + @ApiOperation("设置log文件所在位置信息") + @RequestMapping(value = "/setLogMsg", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public CommonResult setLogMsg(@RequestBody Map requestMap) { + return CommonResult.success(iLogFileListenerService.setLogMsg(requestMap)); + } + + @ApiOperation("开启日志监控输出") + @RequestMapping(value = "/startLogListener", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public CommonResult startLogListener(@RequestBody Map requestMap) throws IOException, InterruptedException { + iLogFileListenerService.startLogListener(requestMap); + return CommonResult.success(null); + } + + @ApiOperation("停止日志监控输出") + @RequestMapping(value = "/stopLogListener", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public CommonResult stopLogListener(@RequestBody Map requestMap) throws IOException, InterruptedException { + iLogFileListenerService.stopLogListener(requestMap); + return CommonResult.success(null); + } + + @ApiOperation("获取日志的输出内容") + @RequestMapping(value = "/getLogOutput", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public CommonResult getLogOutput(@RequestBody Map requestMap) throws IOException, InterruptedException { + return CommonResult.success(iLogFileListenerService.getLogOutput(requestMap)); + } +} diff --git a/src/main/java/com/objecteye/controller/OccupationOfBasicResourcesController.java b/src/main/java/com/objecteye/controller/OccupationOfBasicResourcesController.java new file mode 100644 index 0000000..6b278a6 --- /dev/null +++ b/src/main/java/com/objecteye/controller/OccupationOfBasicResourcesController.java @@ -0,0 +1,31 @@ +package com.objecteye.controller; + +import com.alibaba.fastjson.JSONArray; +import com.objecteye.common.CommonResult; +import com.objecteye.service.IOccupationOfBasicResourcesService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@RestController +@Api(tags = "occupationOfBasicResources", description = "基础资源占用") +@RequestMapping("/occupationOfBasicResources") +@CrossOrigin +public class OccupationOfBasicResourcesController { + @Autowired + private IOccupationOfBasicResourcesService iOccupationOfBasicResourcesService; + + @ApiOperation("获取指定module的输出") + @RequestMapping(value = "/getInfoByModule", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public CommonResult getInfoByModule(@RequestBody Map requestMap) { + JSONArray jsonArray = iOccupationOfBasicResourcesService.getInfoByModule(requestMap); + if (jsonArray.size() > 0) { + return CommonResult.success(jsonArray); + } else { + return CommonResult.success(201, "未获取输出信息", null); + } + } +} diff --git a/src/main/java/com/objecteye/exception/CustomXException.java b/src/main/java/com/objecteye/exception/CustomXException.java new file mode 100644 index 0000000..ef0f8c1 --- /dev/null +++ b/src/main/java/com/objecteye/exception/CustomXException.java @@ -0,0 +1,36 @@ +package com.objecteye.exception; + +import java.util.Map; + +/** + * custom exception which handles custom request error. + */ +public class CustomXException extends RuntimeException { + private String msg; + private String code; + private Map params = null; + + public CustomXException(String msg, String code, Map params) { + this.code = code; + this.msg = msg; + this.params = params; + } + + public CustomXException(String msg, String code) { + this.code = code; + this.msg = msg; + } + + + public String getCode() { + return code; + } + + public String getMsg() { + return msg; + } + + public Map getParams() { + return params; + } +} diff --git a/src/main/java/com/objecteye/exception/GeneralExceptionHandler.java b/src/main/java/com/objecteye/exception/GeneralExceptionHandler.java new file mode 100644 index 0000000..2cfa827 --- /dev/null +++ b/src/main/java/com/objecteye/exception/GeneralExceptionHandler.java @@ -0,0 +1,22 @@ +package com.objecteye.exception; + +import com.objecteye.common.CommonResult; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +@Slf4j +public class GeneralExceptionHandler { + + /** + * 系统异常捕获处理 + */ + @ExceptionHandler(Exception.class) + @ResponseBody + public CommonResult exception(Exception e) { + log.error(e.getMessage(), e); + return CommonResult.success(504, e.getMessage(), null); + } +} diff --git a/src/main/java/com/objecteye/service/ILogFileListenerService.java b/src/main/java/com/objecteye/service/ILogFileListenerService.java new file mode 100644 index 0000000..d7468bb --- /dev/null +++ b/src/main/java/com/objecteye/service/ILogFileListenerService.java @@ -0,0 +1,41 @@ +package com.objecteye.service; + +import com.alibaba.fastjson.JSONObject; + +import java.io.IOException; +import java.util.Map; + +public interface ILogFileListenerService { + + /** + * 设置log文件所在位置信息 + * + * @param requestMap 文件位置 + * @return + */ + JSONObject setLogMsg(Map requestMap); + + /** + * 开启日志监控输出 + * + * @param requestMap 日志key + */ + void startLogListener(Map requestMap) throws IOException, InterruptedException; + + /** + * 停止日志监控输出 + * + * @param requestMap 日志key + */ + void stopLogListener(Map requestMap); + + /** + * 获取日志的输出内容 + * + * @param requestMap 日志key + * @return 输出内容 + */ + String getLogOutput(Map requestMap); + + +} diff --git a/src/main/java/com/objecteye/service/IOccupationOfBasicResourcesService.java b/src/main/java/com/objecteye/service/IOccupationOfBasicResourcesService.java new file mode 100644 index 0000000..06aeb9a --- /dev/null +++ b/src/main/java/com/objecteye/service/IOccupationOfBasicResourcesService.java @@ -0,0 +1,19 @@ +package com.objecteye.service; + +import com.alibaba.fastjson.JSONArray; + +import java.util.Map; + +/** + * 基础资源占用情况接口 + */ +public interface IOccupationOfBasicResourcesService { + + /** + * 获取指定module的输出 + * + * @param requestMap 请求参数 + * @return 输出结果 + */ + JSONArray getInfoByModule(Map requestMap); +} diff --git a/src/main/java/com/objecteye/service/impl/LogFileListenerServiceImpl.java b/src/main/java/com/objecteye/service/impl/LogFileListenerServiceImpl.java new file mode 100644 index 0000000..1a26396 --- /dev/null +++ b/src/main/java/com/objecteye/service/impl/LogFileListenerServiceImpl.java @@ -0,0 +1,112 @@ +package com.objecteye.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.objecteye.common.GeneralContent; +import com.objecteye.service.ILogFileListenerService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; + +@Component +public class LogFileListenerServiceImpl implements ILogFileListenerService { + + @Autowired + private RedisTemplate redisTemplate; + + /** + * 设置log文件所在位置信息 + * + * @param requestMap 文件位置 + * @return + */ + @Override + public JSONObject setLogMsg(Map requestMap) { + String filePath = (String) requestMap.get("filePath"); + File file = new File(filePath); + if (!file.exists()) { + throw new RuntimeException("file is not exists! Please confirm your path"); + } else if (file.isDirectory()) { + throw new RuntimeException("Can not analysis directory, please insert a file path"); + } + String key = file.getName() + "|" + System.currentTimeMillis(); + redisTemplate.opsForHash().put(GeneralContent.REDIS_LOG_KEY_PATH, key, filePath); + + JSONObject resultObj = new JSONObject(); + resultObj.put("logKey", key); + return resultObj; + } + + /** + * 开启日志监控输出 + * + * @param requestMap 日志key + */ + @Override + @Async("taskExecutor") + public void startLogListener(Map requestMap) throws IOException, InterruptedException { + String logKey = (String) requestMap.get("logKey"); + if (redisTemplate.opsForHash().hasKey(GeneralContent.REDIS_LOG_KEY_PATH, logKey)) { + File file = new File((String) redisTemplate.opsForHash().get(GeneralContent.REDIS_LOG_KEY_PATH, logKey)); + Long lastTimeFileSize = file.length(); + + while (true) { + if (!redisTemplate.opsForHash().hasKey(GeneralContent.REDIS_LOG_KEY_PATH, logKey)) { + if (redisTemplate.hasKey(logKey)) { + redisTemplate.delete(logKey); + } + return; + } + RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); + randomAccessFile.seek(lastTimeFileSize); + String tmp; + while ((tmp = randomAccessFile.readLine()) != null) { + redisTemplate.opsForList().leftPush(logKey, new String(tmp.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8)); + } + lastTimeFileSize = randomAccessFile.length(); + + Thread.sleep(1000L); + } + } + } + + /** + * 停止日志监控输出 + * + * @param requestMap 日志key + */ + @Override + public void stopLogListener(Map requestMap) { + String logKey = (String) requestMap.get("logKey"); + if (redisTemplate.opsForHash().hasKey(GeneralContent.REDIS_LOG_KEY_PATH, logKey)) { + redisTemplate.opsForHash().delete(GeneralContent.REDIS_LOG_KEY_PATH, logKey); + } + } + + /** + * 获取日志的输出内容 + * + * @param requestMap 日志key + * @return 输出内容 + */ + @Override + public String getLogOutput(Map requestMap) { + String logKey = (String) requestMap.get("logKey"); + Long size = redisTemplate.opsForList().size(logKey); + if (size != null) { + List list = redisTemplate.opsForList().range(logKey, 0L, size - 1); + if (list != null && list.size() > 0) { + redisTemplate.delete(logKey); + return String.join("\n", list); + } + } + return null; + } +} diff --git a/src/main/java/com/objecteye/service/impl/OccupationOfBasicResourcesServiceImpl.java b/src/main/java/com/objecteye/service/impl/OccupationOfBasicResourcesServiceImpl.java new file mode 100644 index 0000000..73a1f85 --- /dev/null +++ b/src/main/java/com/objecteye/service/impl/OccupationOfBasicResourcesServiceImpl.java @@ -0,0 +1,75 @@ +package com.objecteye.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.objecteye.common.GeneralContent; +import com.objecteye.service.IOccupationOfBasicResourcesService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Component +@Slf4j +public class OccupationOfBasicResourcesServiceImpl implements IOccupationOfBasicResourcesService { + + /** + * 获取指定module的输出 + * + * @param requestMap 请求参数 + * @return 输出结果 + */ + @Override + public JSONArray getInfoByModule(Map requestMap) { + String module = (String) requestMap.get("module"); + JSONArray resultArr = new JSONArray(); + if (GeneralContent.MODULE_MAP.containsKey(module)) { + String cmd = System.getProperty("user.dir") + GeneralContent.MODULE_MAP.get(module); + List outList = new ArrayList<>(); + executeLinuxCmd(cmd, outList); + if (outList.size() > 0) { + Object object = JSON.parse(outList.get(0)); + if (object instanceof JSONObject) { + resultArr.add(object); + } else if (object instanceof JSONArray) { + resultArr = (JSONArray) object; + } + } + } + return resultArr; + } + + /** + * 执行Linux语句并获取返回值 + * + * @param cmd linux语句 + * @param outList 输出参数 + */ + private void executeLinuxCmd(String cmd, List outList) { + Runtime run = Runtime.getRuntime(); + try { + ProcessBuilder builder = new ProcessBuilder("/bin/chmod", "755", cmd); + Process permission = builder.start(); + permission.waitFor(); + + Process process = run.exec("sh " + cmd); + log.info("OccupationOfBasicResourcesServiceImpl|executeLinuxCmd|cmd: {}", cmd); + String line; + BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + while ((line = stdoutReader.readLine()) != null) { + log.info("OccupationOfBasicResourcesServiceImpl|executeLinuxCmd|line: {}", line); + outList.add(line); + } + process.waitFor(); + process.destroy(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/objecteye/shell_files/arp_cache.sh b/src/main/java/com/objecteye/shell_files/arp_cache.sh new file mode 100644 index 0000000..1555d5b --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/arp_cache.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +arpCommand=$(command -v arp) + +result=$($arpCommand | awk 'BEGIN {print "["} NR>1 \ + {print "{ \"address\": \"" $1 "\", " \ + "\"hw_type\": \"" $2 "\", " \ + "\"hw_address\": \"" $3 "\", " \ + "\"flags\": \"" $4 "\", " \ + "\"mask\": \"" $5 "\" }, " \ + } \ + END {print "]"}' \ + | /bin/sed 'N;$s/},/}/;P;D') + +if [ -z "$result" ]; then echo {} +else echo $result +fi \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/bandwidth.sh b/src/main/java/com/objecteye/shell_files/bandwidth.sh new file mode 100644 index 0000000..51a2cd7 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/bandwidth.sh @@ -0,0 +1,6 @@ +#!/bin/bash +/bin/cat /proc/net/dev \ +| awk 'BEGIN {print "["} NR>2 {print "{ \"interface\": \"" $1 "\"," \ + " \"tx\": " $2 "," \ + " \"rx\": " $10 " }," } END {print "]"}' \ +| /bin/sed 'N;$s/,\n/\n/;P;D' diff --git a/src/main/java/com/objecteye/shell_files/common_applications.sh b/src/main/java/com/objecteye/shell_files/common_applications.sh new file mode 100644 index 0000000..d9e81bd --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/common_applications.sh @@ -0,0 +1,11 @@ +#!/bin/bash +result=$(whereis php node mysql mongo vim python ruby java apache2 nginx openssl vsftpd make \ +| awk -F: '{if(length($2)==0) { installed="false"; } else { installed="true"; } \ + print \ + "{ \ + \"binary\": \""$1"\", \ + \"location\": \""$2"\", \ + \"installed\": "installed" \ + },"}') + +echo "[" ${result%?} "]" \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/cpu_info.sh b/src/main/java/com/objecteye/shell_files/cpu_info.sh new file mode 100644 index 0000000..c00b603 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/cpu_info.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +result=$(/usr/bin/lscpu \ + | /usr/bin/awk -F: '{print "\""$1"\": \""$2"\"," } '\ + ) + +echo "{" ${result%?} "}" \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/cpu_intensive_processes.sh b/src/main/java/com/objecteye/shell_files/cpu_intensive_processes.sh new file mode 100644 index 0000000..a193bb2 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/cpu_intensive_processes.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +result=$(/bin/ps axo pid,user,pcpu,rss,vsz,comm --sort -pcpu,-rss,-vsz \ + | head -n 15 \ + | /usr/bin/awk 'BEGIN{OFS=":"} NR>1 {print "{ \"pid\": " $1 \ + ", \"user\": \"" $2 "\"" \ + ", \"cpu%\": " $3 \ + ", \"rss\": " $4 \ + ", \"vsz\": " $5 \ + ", \"cmd\": \"" $6 "\"" "},"\ + }') + +echo "[" ${result%?} "]" \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/cpu_temp.sh b/src/main/java/com/objecteye/shell_files/cpu_temp.sh new file mode 100644 index 0000000..95d20cb --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/cpu_temp.sh @@ -0,0 +1,15 @@ +#!/bin/bash +if [ `which sensors` ]; then + returnString=`sensors` + #amd + if [[ "${returnString/"k10"}" != "${returnString}" ]] ; then + echo ${returnString##*k10} | cut -d ' ' -f 6 | cut -c 2- | cut -c 1-4 + #intel + elif [[ "${returnString/"core"}" != "${returnString}" ]] ; then + fromcore=${returnString##*"coretemp"} + echo ${fromcore##*Physical} | cut -d ' ' -f 3 | cut -c 2-5 + fi +else + echo "[]" +fi + diff --git a/src/main/java/com/objecteye/shell_files/cpu_utilization.sh b/src/main/java/com/objecteye/shell_files/cpu_utilization.sh new file mode 100644 index 0000000..7d6c361 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/cpu_utilization.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# by Paul Colby (http://colby.id.au), no rights reserved ;) + +PREV_TOTAL=0 +PREV_IDLE=0 +iteration=0 + +while [[ iteration -lt 2 ]]; do + # Get the total CPU statistics, discarding the 'cpu ' prefix. + CPU=(`sed -n 's/^cpu\s//p' /proc/stat`) + IDLE=${CPU[3]} # Just the idle CPU time. + + # Calculate the total CPU time. + TOTAL=0 + for VALUE in "${CPU[@]}"; do + let "TOTAL=$TOTAL+$VALUE" + done + + # Calculate the CPU usage since we last checked. + let "DIFF_IDLE=$IDLE-$PREV_IDLE" + let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL" + let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10" + #echo -en "\rCPU: $DIFF_USAGE% \b\b" + + # Remember the total and idle CPU times for the next check. + PREV_TOTAL="$TOTAL" + PREV_IDLE="$IDLE" + + # Wait before checking again. + sleep 1 + iteration="$iteration+1" +done +echo -en "$DIFF_USAGE" diff --git a/src/main/java/com/objecteye/shell_files/cron_history.sh b/src/main/java/com/objecteye/shell_files/cron_history.sh new file mode 100644 index 0000000..e7cd804 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/cron_history.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +grepCmd=$(which grep) +cronLog='/var/log/syslog' +numberOfLines='50' + +# Month, Day, Time, Hostname, tag, user, + +result=$($grepCmd -m$numberOfLines CRON $cronLog \ + | awk '{ s = ""; for (i = 6; i <= NF; i++) s = s $i " "; \ + print "{\"time\" : \"" $1" "$2" "$3 "\"," \ + "\"user\" : \"" $6 "\"," \ + "\"message\" : \"" $5" "gensub("\"", "\\\\\"", "g", s) "\"" \ + "}," + }' + ) + +echo [${result%?}] diff --git a/src/main/java/com/objecteye/shell_files/current_ram.sh b/src/main/java/com/objecteye/shell_files/current_ram.sh new file mode 100644 index 0000000..1a10920 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/current_ram.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +awkCmd=`which awk` +catCmd=`which cat` +grepCmd=`which grep` +memInfoFile="/proc/meminfo" + +# References: +# Calculations: http://zcentric.com/2012/05/29/mapping-procmeminfo-to-output-of-free-command/ +# Fields: https://www.kernel.org/doc/Documentation/filesystems/proc.txt + +memInfo=`$catCmd $memInfoFile | $grepCmd 'MemTotal\|MemFree\|Buffers\|Cached'` + +echo $memInfo | $awkCmd '{print "{ \"total\": " ($2/1024) ", \"used\": " ( ($2-($5+$8+$11))/1024 ) ", \"free\": " (($5+$8+$11)/1024) " }" }' diff --git a/src/main/java/com/objecteye/shell_files/disk_partitions.sh b/src/main/java/com/objecteye/shell_files/disk_partitions.sh new file mode 100644 index 0000000..d563d19 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/disk_partitions.sh @@ -0,0 +1,4 @@ +#!/bin/bash +result=$(/bin/df -Ph | awk 'NR>1 {print "{\"file_system\": \"" $1 "\", \"size\": \"" $2 "\", \"used\": \"" $3 "\", \"avail\": \"" $4 "\", \"used%\": \"" $5 "\", \"mounted\": \"" $6 "\"},"}') + +echo [ ${result%?} ] \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/docker_processes.sh b/src/main/java/com/objecteye/shell_files/docker_processes.sh new file mode 100644 index 0000000..9ba42cc --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/docker_processes.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +result="" +containers="$(docker ps | awk '{if(NR>1) print $NF}')" +for i in $containers; do +result="$result $(/usr/bin/docker top $i axo pid,user,pcpu,pmem,comm --sort -pcpu,-pmem \ + | head -n 15 \ + | /usr/bin/awk -v cnt="$i" 'BEGIN{OFS=":"} NR>1 {print "{ \"cname\": \"" cnt \ + "\", \"pid\": " $1 \ + ", \"user\": \"" $2 "\"" \ + ", \"cpu%\": " $3 \ + ", \"mem%\": " $4 \ + ", \"cmd\": \"" $5 "\"" "},"\ + }')" +done + +echo "[" ${result%?} "]" diff --git a/src/main/java/com/objecteye/shell_files/download_transfer_rate.sh b/src/main/java/com/objecteye/shell_files/download_transfer_rate.sh new file mode 100644 index 0000000..5762d6d --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/download_transfer_rate.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +files=(/sys/class/net/*) +pos=$(( ${#files[*]} - 1 )) +last=${files[$pos]} +in1=() + +json_output="{" + +for interface in "${files[@]}" +do + basename=$(basename "$interface") + + # find the number of bytes transfered for this interface + in1+=( $(cat /sys/class/net/"$basename"/statistics/rx_bytes) ) +done + +# wait a moment +sleep 0.5 + +for interface in "${files[@]}" +do + basename=$(basename "$interface") + # check same interface again + in2=$(cat /sys/class/net/"$basename"/statistics/rx_bytes) + + # read and remove first element + in=${in1[0]} + unset in1[0] + in1=( "${in1[@]}" ) + + # get the difference (transfer rate) + in_bytes=$((in2 - in)) + + # convert transfer rate to KB + in_kbytes=$((in_bytes / 1024 * 2)) + + # convert transfer rate to KB + json_output="$json_output \"$basename\": $in_kbytes" + + # if it is not the last line + if [[ ! $interface == $last ]] + then + # add a comma to the line (JSON formatting) + json_output="$json_output," + fi +done + +# close the JSON object & print to screen +echo "$json_output}" diff --git a/src/main/java/com/objecteye/shell_files/general_info.sh b/src/main/java/com/objecteye/shell_files/general_info.sh new file mode 100644 index 0000000..a76b20c --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/general_info.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +function displaytime { + local T=$1 + local D=$((T/60/60/24)) + local H=$((T/60/60%24)) + local M=$((T/60%60)) + local S=$((T%60)) + [[ $D > 0 ]] && printf '%d days ' $D + [[ $H > 0 ]] && printf '%d hours ' $H + [[ $M > 0 ]] && printf '%d minutes ' $M + [[ $D > 0 || $H > 0 || $M > 0 ]] && printf 'and ' + printf '%d seconds\n' $S +} + +lsbRelease=$(/usr/bin/lsb_release -ds | sed -e 's/^"//' -e 's/"$//') +uname=$(/bin/uname -r | sed -e 's/^"//' -e 's/"$//') +os=`echo $lsbRelease $uname` +hostname=$(/bin/hostname) +uptime_seconds=$(/bin/cat /proc/uptime | awk '{print $1}') +server_time=$(date) + +echo { \ + \"OS\": \"$os\", \ + \"Hostname\": \"$hostname\", \ + \"Uptime\": \" $(displaytime ${uptime_seconds%.*}) \", \ + \"Server Time\": \"$server_time\" \ + } diff --git a/src/main/java/com/objecteye/shell_files/internet_speed.sh b/src/main/java/com/objecteye/shell_files/internet_speed.sh new file mode 100644 index 0000000..fa2478a --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/internet_speed.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +SCRIPTPATH=`dirname $(readlink -f $0)` +SPEED_TEST_SCRIPT=$SCRIPTPATH"/../python_files/speedtest_cli.py" + +$SPEED_TEST_SCRIPT \ +| grep 'Upload\|Download' \ +| awk 'BEGIN {print "{"} {print "\"" $1 "\": \"" $2 " " $3 "\"," } END {print "}"}' \ +| /bin/sed 'N;$s/",/"/;P;D' \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/io_stats.sh b/src/main/java/com/objecteye/shell_files/io_stats.sh new file mode 100644 index 0000000..0e14d4e --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/io_stats.sh @@ -0,0 +1,7 @@ +#!/bin/bash +result=$(/bin/cat /proc/diskstats | /usr/bin/awk \ + '{ if($4==0 && $8==0 && $12==0 && $13==0) next } \ + {print "{ \"device\": \"" $3 "\", \"reads\": \""$4"\", \"writes\": \"" $8 "\", \"in_progress\": \"" $12 "\", \"time_in_io\": \"" $13 "\"},"}' + ) + +echo [ ${result%?} ] \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/ip_addresses.sh b/src/main/java/com/objecteye/shell_files/ip_addresses.sh new file mode 100644 index 0000000..0018f6f --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/ip_addresses.sh @@ -0,0 +1,18 @@ +#!/bin/bash +awkCmd=`which awk` +grepCmd=`which grep` +sedCmd=`which sed` +ifconfigCmd=`which ifconfig` +trCmd=`which tr` +digCmd=`which dig` + +externalIp=`$digCmd +short myip.opendns.com @resolver1.opendns.com` + +echo -n "[" + +for item in $($ifconfigCmd | $grepCmd -oP "^[a-zA-Z0-9:]*(?=:)") +do + echo -n "{\"interface\" : \""$item"\", \"ip\" : \"$( $ifconfigCmd $item | $grepCmd "inet" | $awkCmd '{match($0,"inet (addr:)?([0-9.]*)",a)}END{ if (NR != 0){print a[2]; exit}{print "none"}}')\"}, " +done + +echo "{ \"interface\": \"external\", \"ip\": \"$externalIp\" } ]" diff --git a/src/main/java/com/objecteye/shell_files/load_avg.sh b/src/main/java/com/objecteye/shell_files/load_avg.sh new file mode 100644 index 0000000..98be035 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/load_avg.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +grepCmd=`which grep` +awkCmd=`which awk` +catCmd=`which cat` + +numberOfCores=$($grepCmd -c 'processor' /proc/cpuinfo) + +if [ $numberOfCores -eq 0 ]; then + numberOfCores=1 +fi + +result=$($catCmd /proc/loadavg | $awkCmd '{print "{ \"1_min_avg\": " ($1*100)/'$numberOfCores' ", \"5_min_avg\": " ($2*100)/'$numberOfCores' ", \"15_min_avg\": " ($3*100)/'$numberOfCores' "}," }') + +echo ${result%?} diff --git a/src/main/java/com/objecteye/shell_files/logged_in_users.sh b/src/main/java/com/objecteye/shell_files/logged_in_users.sh new file mode 100644 index 0000000..635163a --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/logged_in_users.sh @@ -0,0 +1,4 @@ +#!/bin/bash +result=$(COLUMNS=300 /usr/bin/w -h | /usr/bin/awk '{print "{\"user\": \"" $1 "\", \"from\": \"" $3 "\", \"when\": \"" $4 "\"},"}') + +echo [ ${result%?} ] \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/memcached.sh b/src/main/java/com/objecteye/shell_files/memcached.sh new file mode 100644 index 0000000..88f8516 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/memcached.sh @@ -0,0 +1,7 @@ +#!/bin/bash +echo "stats" \ + | /bin/nc -w 1 127.0.0.1 11211 \ + | /bin/grep 'bytes' \ + | /usr/bin/awk 'BEGIN {print "{"} {print "\"" $2 "\": " $3 } END {print "}"}' \ + | /usr/bin/tr '\r' ',' \ + | /bin/sed 'N;$s/,\n/\n/;P;D' \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/memory_info.sh b/src/main/java/com/objecteye/shell_files/memory_info.sh new file mode 100644 index 0000000..9b2ce6c --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/memory_info.sh @@ -0,0 +1,4 @@ +#!/bin/bash +/bin/cat /proc/meminfo \ + | /usr/bin/awk -F: 'BEGIN {print "{"} {print "\"" $1 "\": \"" $2 "\"," } END {print "}"}' \ + | /bin/sed 'N;$s/,\n/\n/;P;D' diff --git a/src/main/java/com/objecteye/shell_files/network_connections.sh b/src/main/java/com/objecteye/shell_files/network_connections.sh new file mode 100644 index 0000000..9f952f8 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/network_connections.sh @@ -0,0 +1,13 @@ +#!/bin/bash +netstatCmd=`which netstat` +awkCmd=`which awk` +sortCmd=`which sort` +uniqCmd=`which uniq` +sedCmd=`which sed` + +$netstatCmd -ntu \ +| $awkCmd 'NR>2 {print $5}' \ +| $sortCmd \ +| $uniqCmd -c \ +| $awkCmd 'BEGIN {print "["} {print "{ \"connections\": " $1 ", \"address\": \"" $2 "\" }," } END {print "]"}' \ +| $sedCmd 'N;$s/},/}/;P;D' diff --git a/src/main/java/com/objecteye/shell_files/number_of_cpu_cores.sh b/src/main/java/com/objecteye/shell_files/number_of_cpu_cores.sh new file mode 100644 index 0000000..42c20e5 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/number_of_cpu_cores.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +numberOfCores=$(/bin/grep -c 'model name' /proc/cpuinfo) + +if [length($numberOfCores)]; then + echo "cannnot be found"; +fi \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/ping.sh b/src/main/java/com/objecteye/shell_files/ping.sh new file mode 100644 index 0000000..32d5e3b --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/ping.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# http://askubuntu.com/questions/413367/ping-multiple-ips-using-bash + +# get absolute path to config file +SCRIPTPATH=`dirname $(readlink -f $0)` +CONFIG_PATH=$SCRIPTPATH"/../config/ping_hosts" + +catCmd=`which cat` +pingCmd=`which ping` +awkCmd=`which awk` +sedCmd=`which sed` +numOfLinesInConfig=`$sedCmd -n '$=' $CONFIG_PATH` +result='[' + +$catCmd $CONFIG_PATH \ +| while read output + do + singlePing=$($pingCmd -qc 2 $output \ + | $awkCmd -F/ 'BEGIN { endLine="}," } /^rtt/ { if ('$numOfLinesInConfig'==1){endLine="}"} print "{" "\"host\": \"'$output'\", \"ping\": " $5 " " endLine }' \ + ) + numOfLinesInConfig=$(($numOfLinesInConfig-1)) + result=$result$singlePing + if [ $numOfLinesInConfig -eq 0 ] + then + echo $result"]" + fi + done \ +| $sedCmd 's/\},]/}]/g' diff --git a/src/main/java/com/objecteye/shell_files/pm2.sh b/src/main/java/com/objecteye/shell_files/pm2.sh new file mode 100644 index 0000000..7815f4e --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/pm2.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +#get data +command="pm2 list" +data="$($command)" + +#only process data if variable has a length +#this should handle cases where pm2 is not installed +if [ -n "$data" ]; then + + #start processing data on line 4 + #don't process last 2 lines + json=$( echo "$data" | tail -n +4 | head -n +2 \ + | awk '{print "{"}\ + {print "\"appName\":\"" $2 "\","} \ + {print "\"id\":\"" $4 "\","} \ + {print "\"mode\":\"" $6 "\","} \ + {print "\"pid\":\"" $8 "\","}\ + {print "\"status\":\"" $10 "\","}\ + {print "\"restart\":\"" $12 "\","}\ + {print "\"uptime\":\"" $14 "\","}\ + {print "\"memory\":\"" $16 $17 "\","}\ + {print "\"watching\":\"" $19 "\""}\ + {print "},"}') + #make sure to remove last comma and print in array + echo "[" ${json%?} "]" +else + #no data found + echo "{}" +fi + + diff --git a/src/main/java/com/objecteye/shell_files/raid_status.sh b/src/main/java/com/objecteye/shell_files/raid_status.sh new file mode 100644 index 0000000..ef0ec2d --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/raid_status.sh @@ -0,0 +1,109 @@ +#!/usr/bin/perl + + +my($devinfo_re, $devstat_re, $action_re) = ( + '(md\d+)\s+:\s+active\s+(\(read-only\)\s+|\(auto-read-only\)\s+|)(\w+)\s+(.*)', + '.*\[(\d+)\/(\d+)]\s+\[(\w+)]', + '.*(reshape|check|resync|recovery)\s*=\s*(\d+\.\d+%|\w+)(.*finish=(.*min))?', +); +# Interestingly, swap is presented as "active (auto-read-only)" +# and mdadm has '--readonly' option to make the array 'active (read-only)' +print "["; + +open(my $mdstat, "/proc/mdstat"); +my(@text) = <$mdstat>; +# contents of <$mdstat> may be changed at next reading, so fetch the contents at a time +close($mdstat); + +my($dev, $ro, $type, $members, $nmem, $nact, $status, $action, $proc, $minute, $idx); +while (@text) { + my $line = shift @text; + if ($line =~ /$devinfo_re/) { + # first line should like "active raid1 sda1[0] sdc1[2] sdb1[1]" + $dev = $1; + $ro = $2 || ''; + $type = $3; + $members = $4; + + $line = shift @text; + if ($line =~ /$devstat_re/) { + # second line should like "123456 blocks super 1.2 [2/2] [UU]" + $nmem = $1; + $nact = $2; + $status = $3; + } + else { + # sencond line did not exist on /proc/mdstat + next; + } + + $line = shift @text; + if ($line =~ /$action_re/) { + # third line should like " [==>..................] check = 10.0% (12345/123456) finish=123min speed=12345/sec" + # this line will appear only when the array is in action + $action = $1; + my $percent = $2; + $minute = $4 || ''; + if ($percent =~ /(\d+\.\d+)%/) { + $proc = $1; + } + else { + # 'resync=DELAYED' or 'resync=PENDING' + $action .= " ($percent)"; + $proc = -1; + } + } + else { + # array is not in action + $action = 'idle'; + $minute = ''; + unshift(@text, $line); + } + } + else { + # skip until first line is found + next; + } + + if ( $ARGV[0] and $ARGV[0] eq "config" ) { + print "$dev.label $dev\n"; + print "$dev.info $type $ro$members\n"; + # 100: means less than 100 + # Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100. + print "$dev.critical 98:\n"; + print $dev, "_rebuild.label $dev reshape/recovery\n"; + print $dev, "_rebuild.info $action $minute\n"; + # Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100. + print $dev, "_rebuild.critical 98:\n"; + print $dev, "_check.label $dev check/resync \n"; + print $dev, "_check.info $action $minute\n"; + } else { + my $pct = 100 * $nact / $nmem; + my $rpct = 100; + my $cpct = 100; + if ($action =~ /reshape|recovery/) { + $rpct = $proc; + $cpct = 0; # check/resync is not done + } + elsif ($action =~ /check|resync/) { + if ($proc < 0) { + # array is on DELAYED or PENDING, further info is unknown + $rpct = 0; + $cpct = 0; + } + else { + # reshape/recovery was done, $rpct => 100 + $cpct = $proc; + } + } + + if($idx > 0) { + print ", \n"; + } + print "{ \"device\": \"$dev\", \"value\": $pct, \"rebuild\": $rpct, \"check\": $cpct }"; + + } + $idx = $idx + 1; + +} +print "]"; diff --git a/src/main/java/com/objecteye/shell_files/ram_intensive_processes.sh b/src/main/java/com/objecteye/shell_files/ram_intensive_processes.sh new file mode 100644 index 0000000..a86e120 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/ram_intensive_processes.sh @@ -0,0 +1,12 @@ +#!/bin/bash +result=$(/bin/ps axo pid,user,pmem,rss,vsz,comm --sort -pmem,-rss,-vsz \ + | head -n 15 \ + | /usr/bin/awk 'NR>1 {print "{ \"pid\": " $1 \ + ", \"user\": \"" $2 \ + "\", \"mem%\": " $3 \ + ", \"rss\": " $4 \ + ", \"vsz\": " $5 \ + ", \"cmd\": \"" $6 \ + "\"},"}') + +echo [ ${result%?} ] \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/recent_account_logins.sh b/src/main/java/com/objecteye/shell_files/recent_account_logins.sh new file mode 100644 index 0000000..de0b080 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/recent_account_logins.sh @@ -0,0 +1,10 @@ +#!/bin/bash +result=$(/usr/bin/lastlog -t 365 \ + | /usr/bin/awk 'NR>1 {\ + print "{ \ + \"user\": \"" $1 "\", \ + \"ip\": \"" $3 "\","" \ + \"date\": \"" $5" "$6" "$7" "$8" "$9 "\"}," + }' + ) +echo [ ${result%?} ] \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/redis.sh b/src/main/java/com/objecteye/shell_files/redis.sh new file mode 100644 index 0000000..38bcaf4 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/redis.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +########### Enter Your Redis Password HERE ######### +redisPassword='' +########### Enter Your Redis Password HERE ######### + +redisCommand=$(which redis-cli); + +if [ -n "$redisPassword" ]; then + redisCommand="$redisCommand -a $redisPassword" +fi + +result=$($redisCommand INFO \ + | grep 'redis_version\|connected_clients\|connected_slaves\|used_memory_human\|total_connections_received\|total_commands_processed' \ + | awk -F: '{print "\"" $1 "\":" "\"" $2 }' \ + | tr '\r' '"' | tr '\n' ',' + ) +echo { ${result%?} } \ No newline at end of file diff --git a/src/main/java/com/objecteye/shell_files/scheduled_crons.sh b/src/main/java/com/objecteye/shell_files/scheduled_crons.sh new file mode 100644 index 0000000..293683f --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/scheduled_crons.sh @@ -0,0 +1,91 @@ +#!/bin/bash +###### +# Credit: http://stackoverflow.com/questions/134906/how-do-i-list-all-cron-jobs-for-all-users#answer-137173 +###### + +catCmd=`which cat` +awkCmd=`which awk` +sedCmd=`which sed` +egrepCmd=`which egrep` +echoCmd=`which echo` +crontabCmd=`which crontab` +trCmd=`which tr` + +# System-wide crontab file and cron job directory. Change these for your system. +CRONTAB='/etc/crontab' +CRONDIR='/etc/cron.d' + +# Single tab character. Annoyingly necessary. +tab=$(echo -en "\t") + +# Given a stream of crontab lines, exclude non-cron job lines, replace +# whitespace characters with a single space, and remove any spaces from the +# beginning of each line. +function clean_cron_lines() { + while read line ; do + $echoCmd "${line}" | + $egrepCmd --invert-match '^($|\s*#|\s*[[:alnum:]_]+=)' | + $sedCmd --regexp-extended "s/\s+/ /g" | + $sedCmd --regexp-extended "s/^ //" + done; +} + +# Given a stream of cleaned crontab lines, $echoCmd any that don't include the +# run-parts command, and for those that do, show each job file in the run-parts +# directory as if it were scheduled explicitly. +function lookup_run_parts() { + while read line ; do + match=$($echoCmd "${line}" | $egrepCmd -o 'run-parts (-{1,2}\S+ )*\S+') + + if [[ -z "${match}" ]] ; then + $echoCmd "${line}" + else + cron_fields=$($echoCmd "${line}" | cut -f1-6 -d' ') + cron_job_dir=$($echoCmd "${match}" | awk '{print $NF}') + + if [[ -d "${cron_job_dir}" ]] ; then + for cron_job_file in "${cron_job_dir}"/* ; do # */ + [[ -f "${cron_job_file}" ]] && $echoCmd "${cron_fields} ${cron_job_file}" + done + fi + fi + done; +} + +# Temporary file for crontab lines. +temp=$(mktemp) || exit 1 + +# Add all of the jobs from the system-wide crontab file. +$catCmd "${CRONTAB}" | clean_cron_lines | lookup_run_parts >"${temp}" + +# Add all of the jobs from the system-wide cron directory. +$catCmd "${CRONDIR}"/* | clean_cron_lines >>"${temp}" # */ + +# Add each user's crontab (if it exists). Insert the user's name between the +# five time fields and the command. +while read user ; do + $crontabCmd -l -u "${user}" 2>/dev/null | + clean_cron_lines | + $sedCmd --regexp-extended "s/^((\S+ +){5})(.+)$/\1${user} \3/" >>"${temp}" +done < <(cut --fields=1 --delimiter=: /etc/passwd) + +# Output the collected crontab lines. + +## Changes: Parses output into JSON + +$catCmd "${temp}" \ + | awk 'BEGIN {print "["} \ + {print "{ \"min(s)\": \"" $1 \ + "\", \"hours(s)\": \"" $2 "\", " \ + " \"day(s)\": \"" $3 "\", " \ + " \"month\": \"" $4 "\", " \ + " \"weekday\": \"" $5 "\", " \ + " \"user\": \"" $6 "\", " \ + " \"command\": \""} \ + {for(i=7;i<=NF;++i) printf("%s ", gensub("\"", "\\\\\"", "g", $i) ) } \ + {print "\" " \ + "}," } \ + END {print "]"}' \ + | $sedCmd 'N;$s/,\n//;P;D' | $trCmd -s '\n' ' ' + +rm --force "${temp}" diff --git a/src/main/java/com/objecteye/shell_files/swap.sh b/src/main/java/com/objecteye/shell_files/swap.sh new file mode 100644 index 0000000..0ba4492 --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/swap.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +catCmd=`which cat`; +wcCmd=`which wc`; +awkCmd=`which awk` + +swapLineCount=$($catCmd /proc/swaps | $wcCmd -l) + +if [ "$swapLineCount" -gt 1 ]; then + + result=$($catCmd /proc/swaps \ + | $awkCmd 'NR>1 {print "{ \"filename\": \"" $1"\", \"type\": \""$2"\", \"size\": \""$3"\", \"used\": \""$4"\", \"priority\": \""$5"\"}," }' + ) + + echo [ ${result%?} ] + +else + echo [] +fi diff --git a/src/main/java/com/objecteye/shell_files/upload_transfer_rate.sh b/src/main/java/com/objecteye/shell_files/upload_transfer_rate.sh new file mode 100644 index 0000000..1cac77c --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/upload_transfer_rate.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +files=(/sys/class/net/*) +pos=$(( ${#files[*]} - 1 )) +last=${files[$pos]} +out1=() + +json_output="{" + +for interface in "${files[@]}" +do + basename=$(basename "$interface") + + # find the number of bytes transfered for this interface + out1+=( $(cat /sys/class/net/"$basename"/statistics/tx_bytes) ) +done + +# wait a moment +sleep 0.5 + +for interface in "${files[@]}" +do + basename=$(basename "$interface") + + # check same interface again + out2=$(cat /sys/class/net/"$basename"/statistics/tx_bytes) + + # read and remove first element + out=${out1[0]} + unset out1[0] + out1=( ${out1[@]} ) + + # get the difference (transfer rate) + out_bytes=$((out2 - out)) + + # convert transfer rate to KB + out_kbytes=$((out_bytes / 1024 * 2)) + + # convert transfer rate to KB + json_output="$json_output \"$basename\": $out_kbytes" + + # if it is not the last line + if [[ ! $interface == $last ]] + then + # add a comma to the line (JSON formatting) + json_output="$json_output," + fi +done + +# close the JSON object & print to screen +echo "$json_output}" diff --git a/src/main/java/com/objecteye/shell_files/user_accounts.sh b/src/main/java/com/objecteye/shell_files/user_accounts.sh new file mode 100644 index 0000000..599d6ba --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/user_accounts.sh @@ -0,0 +1,14 @@ +#!/bin/bash +result=$(/usr/bin/awk -F: '{ \ + if ($3<=499){userType="system";} \ + else {userType="user";} \ + print "{ \"type\": \"" userType "\"" ", \"user\": \"" $1 "\", \"home\": \"" $6 "\" }," }' < /etc/passwd + ) + +length=$(echo ${#result}) + +if [ $length -eq 0 ]; then + result=$(getent passwd | /usr/bin/awk -F: '{ if ($3<=499){userType="system";} else {userType="user";} print "{ \"type\": \"" userType "\"" ", \"user\": \"" $1 "\", \"home\": \"" $6 "\" }," }') +fi + +echo [ ${result%?} ] \ No newline at end of file diff --git a/src/main/java/com/objecteye/utils/ApplicationContextUtil.java b/src/main/java/com/objecteye/utils/ApplicationContextUtil.java new file mode 100644 index 0000000..3e6af6e --- /dev/null +++ b/src/main/java/com/objecteye/utils/ApplicationContextUtil.java @@ -0,0 +1,29 @@ +package com.objecteye.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +/** + * @author 作者 + * @version 创建时间:2018年12月10日 下午3:59:50 类说明 获取context对象 + * + */ +@Component +public class ApplicationContextUtil implements ApplicationContextAware { + private static ApplicationContext applicationContext; + + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + public static Object getBean(String beanName) { + return applicationContext.getBean(beanName); + } + + @Override + public void setApplicationContext(ApplicationContext arg0) throws BeansException { + ApplicationContextUtil.applicationContext = arg0; + } +} diff --git a/src/main/java/com/objecteye/utils/FileUtils.java b/src/main/java/com/objecteye/utils/FileUtils.java new file mode 100644 index 0000000..0f7e1ca --- /dev/null +++ b/src/main/java/com/objecteye/utils/FileUtils.java @@ -0,0 +1,35 @@ +package com.objecteye.utils; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; + +public class FileUtils { + + public static void copyFile(String oldPath,String newPath){ + try { + int bytesum = 0; + int byteread = 0; + File oldfile = new File(oldPath); + if (oldfile.exists()) { + InputStream inStream = new FileInputStream(oldPath); + FileOutputStream fs = new FileOutputStream(newPath); + byte[] buffer = new byte[1444]; + int length; + while ( (byteread = inStream.read(buffer)) != -1) { + bytesum += byteread; + System.out.println(bytesum); + fs.write(buffer, 0, byteread); + } + inStream.close(); + } + } + catch (Exception e) { + System.out.println("复制单个文件操作出错"); + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com/objecteye/utils/RabbbitmqConsumer.java b/src/main/java/com/objecteye/utils/RabbbitmqConsumer.java new file mode 100644 index 0000000..a2b89f7 --- /dev/null +++ b/src/main/java/com/objecteye/utils/RabbbitmqConsumer.java @@ -0,0 +1,20 @@ +package com.objecteye.utils; + +import com.objecteye.config.RabbitmqConfig; +import com.rabbitmq.client.Channel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Component; + +@Component +public class RabbbitmqConsumer { + + private final static Logger logger = LoggerFactory.getLogger(RabbbitmqConsumer.class); + + @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_LISTENER}) + public void receive_store(String msg, Message message, Channel channel) { + logger.info(msg); + } +} diff --git a/src/main/java/com/objecteye/websocket/MyHandshakeInterceptor.java b/src/main/java/com/objecteye/websocket/MyHandshakeInterceptor.java new file mode 100644 index 0000000..74052c6 --- /dev/null +++ b/src/main/java/com/objecteye/websocket/MyHandshakeInterceptor.java @@ -0,0 +1,32 @@ +package com.objecteye.websocket; + +import org.springframework.http.server.ServerHttpRequest; +import org.springframework.http.server.ServerHttpResponse; +import org.springframework.http.server.ServletServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.server.HandshakeInterceptor; + +import java.util.Map; + +/** + * @Author: lr + * @Date: 2019/9/5 14:32 + * @Version 1.0 + * @Message: + */ +@Component +public class MyHandshakeInterceptor implements HandshakeInterceptor { + @Override + public boolean beforeHandshake(ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse, WebSocketHandler webSocketHandler, Map map) throws Exception { + String deviceId=((ServletServerHttpRequest)serverHttpRequest).getServletRequest().getParameter("deviceId"); + if(deviceId!=null){ + map.put("deviceId",deviceId); + } + return true; + } + + @Override + public void afterHandshake(ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse, WebSocketHandler webSocketHandler, Exception e) { + } +} diff --git a/src/main/java/com/objecteye/websocket/MyWebSocketHandler.java b/src/main/java/com/objecteye/websocket/MyWebSocketHandler.java new file mode 100644 index 0000000..7a46462 --- /dev/null +++ b/src/main/java/com/objecteye/websocket/MyWebSocketHandler.java @@ -0,0 +1,86 @@ +package com.objecteye.websocket; + +import net.sf.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + + +/** + * @Author: lr + * @Date: 2019/9/3 10:45 + * @Version 1.0 + * @Message: + */ +@Component +public class MyWebSocketHandler extends TextWebSocketHandler { + + @Autowired + private RedisTemplate redisTemplate; + + + + @Override + public void handleTextMessage(WebSocketSession session, TextMessage message) + throws Exception { + super.handleTextMessage(session, message); + } + + /** + * 抓拍数据和报警数据的json格式 + */ + public String getRealData(Object countMsg, Object captureMsg, Object deployAlarmMsg) { + JSONObject jsonObject = new JSONObject(); + boolean isNull = true; + if (countMsg != null) { + isNull = false; + jsonObject.put("countMsg", countMsg); + jsonObject.put("countCode", 0); + } else { + jsonObject.put("countCode", 1); + } + if (captureMsg != null) { + isNull = false; + jsonObject.put("captureMsg", captureMsg); + jsonObject.put("captureCode", 0); + } else { + jsonObject.put("captureCode", 1); + } + if (deployAlarmMsg != null) { + isNull = false; + jsonObject.put("deployAlarmMsg", deployAlarmMsg); + jsonObject.put("deployAlarmCode", 0); + } else { + jsonObject.put("deployAlarmCode", 1); + } + if (isNull) { + return null; + } + return jsonObject.toString(); + } + + + @Override + public void afterConnectionEstablished(WebSocketSession session) { + + } + + //抛出异常后处理 + @Override + public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { + if (session.isOpen()) { + session.close(); + } + } + + @Override + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { + if(session.isOpen()){ + session.close(); + } + } +} diff --git a/src/main/java/com/objecteye/websocket/WebSocketConfigClass.java b/src/main/java/com/objecteye/websocket/WebSocketConfigClass.java new file mode 100644 index 0000000..04c1c9b --- /dev/null +++ b/src/main/java/com/objecteye/websocket/WebSocketConfigClass.java @@ -0,0 +1,33 @@ +package com.objecteye.websocket; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; + +/** + * @Author: lr + * @Date: 2019/9/3 10:51 + * @Version 1.0 + * @Message: + */ +@Configuration +@EnableWebSocket +public class WebSocketConfigClass implements WebSocketConfigurer { + + @Autowired + private MyHandshakeInterceptor myHandshakeInterceptor; + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(myHandler(),"/ws").setAllowedOrigins("*").addInterceptors(this.myHandshakeInterceptor); + } + + @Bean + public WebSocketHandler myHandler(){ + return new MyWebSocketHandler(); + } +} diff --git a/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 0000000..0ee3a63 --- /dev/null +++ b/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,13 @@ +{ + "properties": [ + { + "name": "jwt.secret", + "type": "java.lang.String", + "description": "Description for jwt.secret." + }, + { + "name": "picture.storePath", + "type": "java.lang.String", + "description": "Description for picture.storePath." + } + ] } \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..fb96cb6 --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,23 @@ +spring: + datasource: + url: jdbc:mysql://192.168.10.153:3306/sy_vehicle?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: 123456 + data: + mongodb: + uri: mongodb://vehicle:shiyu2018@192.168.10.153:27017/vehicle + servlet: + multipart: + max-file-size: 20MB + max-request-size: 20MB + redis: + database: 0 + host: 192.168.10.153 + port: 6381 + jedis: + pool: + max-active: -1 + max-wait: -1ms + max-idle: 8 + min-idle: 0 + timeout: 10000ms \ No newline at end of file diff --git a/src/main/resources/application-prop.yml b/src/main/resources/application-prop.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/main/resources/application-prop.yml diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..6e9cb95 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,31 @@ +spring: + profiles: + active: test #默认开发环境 + rabbitmq: + host: 192.168.10.39 + port: 5672 + username: admin + password: 123456 + virtualHost: / + + +mybatis: + mapper-locations: + - classpath*:com.objecteye.mapper/*.xml + +pagehelper: + helperDialect: mysql + reasonable: true + support-methods-arguments: true + params: count=countSql + +logging: + level: + root: info #日志配置DEBUG,INFO,WARN,ERROR + com.objecteye: info +# file: demo_log.log #配置日志生成路径 +# path: /var/logs #配置日志文件名称 + +server: + port: 8888 + address: 192.168.10.117 \ No newline at end of file -- libgit2 0.21.4