Commit d7b1d619a567dd48eee912c2f262d3b2bda78725

Authored by Liu Haoyu
0 parents

Linux服务器监控模块创建

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