迁移collector,合并到整个工程
This commit is contained in:
37
.gitignore
vendored
Normal file
37
.gitignore
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
Thumbs.db
|
||||
.DS_Store
|
||||
.gradle
|
||||
build/
|
||||
out/
|
||||
micronaut-cli.yml
|
||||
.mvn/
|
||||
mvnw
|
||||
mvnw.bat
|
||||
.log
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
207
LICENSE
Normal file
207
LICENSE
Normal file
@@ -0,0 +1,207 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and
|
||||
distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the
|
||||
copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other
|
||||
entities that control, are controlled by, or are under common control with
|
||||
that entity. For the purposes of this definition, "control" means (i) the
|
||||
power, direct or indirect, to cause the direction or management of such
|
||||
entity, whether by contract or otherwise, or (ii) ownership of
|
||||
fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
|
||||
ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||
permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation source,
|
||||
and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation
|
||||
or translation of a Source form, including but not limited to compiled
|
||||
object code, generated documentation, and conversions to
|
||||
other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object
|
||||
form, made available under the License, as indicated by a copyright notice
|
||||
that is included in or attached to the work (an example is provided in the
|
||||
Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form,
|
||||
that is based on (or derived from) the Work and for which the editorial
|
||||
revisions, annotations, elaborations, or other modifications represent,
|
||||
as a whole, an original work of authorship. For the purposes of this
|
||||
License, Derivative Works shall not include works that remain separable
|
||||
from, or merely link (or bind by name) to the interfaces of, the Work and
|
||||
Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original
|
||||
version of the Work and any modifications or additions to that Work or
|
||||
Derivative Works thereof, that is intentionally submitted to Licensor for
|
||||
inclusion in the Work by the copyright owner or by an individual or
|
||||
Legal Entity authorized to submit on behalf of the copyright owner.
|
||||
For the purposes of this definition, "submitted" means any form of
|
||||
electronic, verbal, or written communication sent to the Licensor or its
|
||||
representatives, including but not limited to communication on electronic
|
||||
mailing lists, source code control systems, and issue tracking systems
|
||||
that are managed by, or on behalf of, the Licensor for the purpose of
|
||||
discussing and improving the Work, but excluding communication that is
|
||||
conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on
|
||||
behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor
|
||||
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
||||
royalty-free, irrevocable copyright license to reproduce, prepare
|
||||
Derivative Works of, publicly display, publicly perform, sublicense,
|
||||
and distribute the Work and such Derivative Works in
|
||||
Source or Object form.
|
||||
|
||||
3. Grant of Patent License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor
|
||||
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
||||
royalty-free, irrevocable (except as stated in this section) patent
|
||||
license to make, have made, use, offer to sell, sell, import, and
|
||||
otherwise transfer the Work, where such license applies only to those
|
||||
patent claims licensable by such Contributor that are necessarily
|
||||
infringed by their Contribution(s) alone or by combination of their
|
||||
Contribution(s) with the Work to which such Contribution(s) was submitted.
|
||||
If You institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||
Contribution incorporated within the Work constitutes direct or
|
||||
contributory patent infringement, then any patent licenses granted to
|
||||
You under this License for that Work shall terminate as of the date such
|
||||
litigation is filed.
|
||||
|
||||
4. Redistribution.
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works
|
||||
thereof in any medium, with or without modifications, and in Source or
|
||||
Object form, provided that You meet the following conditions:
|
||||
|
||||
1. You must give any other recipients of the Work or Derivative Works a
|
||||
copy of this License; and
|
||||
|
||||
2. You must cause any modified files to carry prominent notices stating
|
||||
that You changed the files; and
|
||||
|
||||
3. You must retain, in the Source form of any Derivative Works that You
|
||||
distribute, all copyright, patent, trademark, and attribution notices from
|
||||
the Source form of the Work, excluding those notices that do not pertain
|
||||
to any part of the Derivative Works; and
|
||||
|
||||
4. If the Work includes a "NOTICE" text file as part of its distribution,
|
||||
then any Derivative Works that You distribute must include a readable copy
|
||||
of the attribution notices contained within such NOTICE file, excluding
|
||||
those notices that do not pertain to any part of the Derivative Works,
|
||||
in at least one of the following places: within a NOTICE text file
|
||||
distributed as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or, within a
|
||||
display generated by the Derivative Works, if and wherever such
|
||||
third-party notices normally appear. The contents of the NOTICE file are
|
||||
for informational purposes only and do not modify the License.
|
||||
You may add Your own attribution notices within Derivative Works that You
|
||||
distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||
provided that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may
|
||||
provide additional or different license terms and conditions for use,
|
||||
reproduction, or distribution of Your modifications, or for any such
|
||||
Derivative Works as a whole, provided Your use, reproduction, and
|
||||
distribution of the Work otherwise complies with the conditions
|
||||
stated in this License.
|
||||
|
||||
5. Submission of Contributions.
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally
|
||||
submitted for inclusion in the Work by You to the Licensor shall be under
|
||||
the terms and conditions of this License, without any additional
|
||||
terms or conditions. Notwithstanding the above, nothing herein shall
|
||||
supersede or modify the terms of any separate license agreement you may
|
||||
have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks.
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks,
|
||||
service marks, or product names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor
|
||||
provides the Work (and each Contributor provides its Contributions)
|
||||
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
either express or implied, including, without limitation, any warranties
|
||||
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any risks
|
||||
associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability.
|
||||
|
||||
In no event and under no legal theory, whether in tort
|
||||
(including negligence), contract, or otherwise, unless required by
|
||||
applicable law (such as deliberate and grossly negligent acts) or agreed
|
||||
to in writing, shall any Contributor be liable to You for damages,
|
||||
including any direct, indirect, special, incidental, or consequential
|
||||
damages of any character arising as a result of this License or out of
|
||||
the use or inability to use the Work (including but not limited to damages
|
||||
for loss of goodwill, work stoppage, computer failure or malfunction,
|
||||
or any and all other commercial damages or losses), even if such
|
||||
Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability.
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose
|
||||
to offer, and charge a fee for, acceptance of support, warranty,
|
||||
indemnity, or other liability obligations and/or rights consistent with
|
||||
this License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf of any
|
||||
other Contributor, and only if You agree to indemnify, defend, and hold
|
||||
each Contributor harmless for any liability incurred by, or claims
|
||||
asserted against, such Contributor by reason of your accepting any such
|
||||
warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate
|
||||
notice, with the fields enclosed by brackets "[]" replaced with your own
|
||||
identifying information. (Don't include the brackets!) The text should be
|
||||
enclosed in the appropriate comment syntax for the file format. We also
|
||||
recommend that a file or class name and description of purpose be included
|
||||
on the same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright tomsun28 usthe.com.
|
||||
|
||||
Licensed 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
|
||||
|
||||
http://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.
|
||||
6
README.md
Normal file
6
README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
## monitor
|
||||
|
||||
- 提供监控管理服务
|
||||
- 提供监控任务下发服务
|
||||
- 提供监控数据查询服务
|
||||
- 告警服务
|
||||
18
alerter/pom.xml
Normal file
18
alerter/pom.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>monitor</artifactId>
|
||||
<groupId>com.usthe.tancloud</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>alerter</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
42
collector/README.md
Normal file
42
collector/README.md
Normal file
@@ -0,0 +1,42 @@
|
||||
### TanCloud Collector
|
||||
|
||||
* 操作系统
|
||||
* Linux
|
||||
* Windows
|
||||
* Ubuntu
|
||||
* CentOs
|
||||
* 数据库
|
||||
* Mysql
|
||||
* Oracle
|
||||
* PostgreSQL
|
||||
* 中间件
|
||||
* Kafka
|
||||
* Zookeeper
|
||||
* RocketMq
|
||||
* Etcd
|
||||
* 云原生
|
||||
* Docker
|
||||
* Kubernetes
|
||||
* Istio
|
||||
* 应用服务
|
||||
* Tomcat
|
||||
* Jetty
|
||||
* Http
|
||||
* Ping
|
||||
* 服务端口
|
||||
|
||||
#### HELP
|
||||
|
||||
1. ARK插件类隔离未生效
|
||||
> 注意需构建在jdk1.8环境中运行
|
||||
> 插件是否配置导入并配置正确
|
||||
> 本地DEBUG时需单独IDEA打开运行collector工程,不能将plugin和collector在同一工程打开运行
|
||||
|
||||
2. metaspace元空间内存占用多或溢出
|
||||
> 建议调整JVM参数 ```-Dsun.reflect.inflationThreshold=100000```
|
||||
> 由于使用太多反射,超过参数`inflationThreshold`默认值15阈值导致触发JVM反射优化(加快反射速度),
|
||||
> 反射获取类信息由使用*JNI存取器**膨胀(Inflation)*
|
||||
> 为*反射每个方法生成一个类加载器DelegatingClassLoader和Java类MethodAccessor*.
|
||||
> 动态加载的字节码导致PermGen持续增长.
|
||||
|
||||
|
||||
19
collector/plugins/pom.xml
Normal file
19
collector/plugins/pom.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>collector</artifactId>
|
||||
<groupId>com.usthe.tancloud</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>plugins</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>sample-plugin</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
||||
48
collector/plugins/sample-plugin/pom.xml
Normal file
48
collector/plugins/sample-plugin/pom.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>plugins</artifactId>
|
||||
<groupId>com.usthe.tancloud</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>sample-plugin</artifactId>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!--link https://www.sofastack.tech/projects/sofa-boot/sofa-ark-ark-plugin/ -->
|
||||
<groupId>com.alipay.sofa</groupId>
|
||||
<artifactId>sofa-ark-plugin-maven-plugin</artifactId>
|
||||
<version>1.1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-cli</id>
|
||||
<goals>
|
||||
<goal>ark-plugin</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<!-- 配置优先级,数字越小,优先级越高,优先启动,优先导出类,默认1000 -->
|
||||
<priority>2000</priority>
|
||||
|
||||
<!-- 配置导出类、资源 -->
|
||||
<exported>
|
||||
<!-- 配置类级别导出类 -->
|
||||
<classes>
|
||||
<class>com.com.usthe.plugin.sample.ExportDemo</class>
|
||||
</classes>
|
||||
</exported>
|
||||
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.usthe.collector.plugin;
|
||||
|
||||
/**
|
||||
* @author tomsun28
|
||||
* @date 2021/10/8 15:12
|
||||
*/
|
||||
public class SameClass {
|
||||
|
||||
public static String hello() {
|
||||
return "hello plugin";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.usthe.plugin.sample;
|
||||
|
||||
import com.usthe.collector.plugin.SameClass;
|
||||
|
||||
/**
|
||||
* @author tomsun28
|
||||
* @date 2021/10/8 15:11
|
||||
*/
|
||||
public class ExportDemo {
|
||||
|
||||
public String hello() {
|
||||
return SameClass.hello();
|
||||
}
|
||||
}
|
||||
18
collector/pom.xml
Normal file
18
collector/pom.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>monitor</artifactId>
|
||||
<groupId>com.usthe.tancloud</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>collector</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>server</module>
|
||||
<module>plugins</module>
|
||||
</modules>
|
||||
</project>
|
||||
35
common/pom.xml
Normal file
35
common/pom.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>monitor</artifactId>
|
||||
<groupId>com.usthe.tancloud</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>common</artifactId>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!-- etcd -->
|
||||
<dependency>
|
||||
<groupId>io.etcd</groupId>
|
||||
<artifactId>jetcd-core</artifactId>
|
||||
<version>0.5.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- 工具依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>31.0.1-jre</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.8</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.usthe.common.entity.job;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 监控配置参数属性及值
|
||||
* 过程中需要将协议配置参数里面的标识符为^_^key^_^的内容替换为配置参数里的真实值
|
||||
* @author tomsun28
|
||||
* @date 2021/10/29 22:04
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class Configmap {
|
||||
|
||||
/**
|
||||
* 参数key,将协议配置参数里面的标识符为^^_key_^^的内容替换为配置参数里的真实值
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 参数value
|
||||
*/
|
||||
private Object value;
|
||||
|
||||
/**
|
||||
* number,string,secret
|
||||
* 数字,非加密字符串,加密字符串
|
||||
*/
|
||||
private String type;
|
||||
}
|
||||
162
common/src/main/java/com/usthe/common/entity/job/Job.java
Normal file
162
common/src/main/java/com/usthe/common/entity/job/Job.java
Normal file
@@ -0,0 +1,162 @@
|
||||
package com.usthe.common.entity.job;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 采集任务详情
|
||||
* @author tomsun28
|
||||
* @date 2021/10/17 21:19
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Slf4j
|
||||
public class Job {
|
||||
|
||||
private static final String AVAILABILITY = "availability";
|
||||
|
||||
/**
|
||||
* 任务ID
|
||||
*/
|
||||
private long id;
|
||||
/**
|
||||
* 监控ID 应用ID
|
||||
*/
|
||||
private long appId;
|
||||
/**
|
||||
* 监控的类型 eg: linux | mysql | jvm
|
||||
*/
|
||||
private String app;
|
||||
/**
|
||||
* 任务派发开始时间戳
|
||||
*/
|
||||
private long timestamp;
|
||||
/**
|
||||
* 任务采集时间间隔(单位秒) eg: 30,60,600
|
||||
*/
|
||||
private long interval;
|
||||
/**
|
||||
* 是否是循环周期性任务 true为是,false为否
|
||||
*/
|
||||
private boolean isCyclic;
|
||||
/**
|
||||
* 指标组配置 eg: cpu memory
|
||||
*/
|
||||
private List<Metrics> metrics;
|
||||
/**
|
||||
* 监控配置参数属性及值 eg: username password timeout host
|
||||
*/
|
||||
private List<Configmap> configmap;
|
||||
|
||||
/**
|
||||
* collector使用 - 任务版本,此字段不存储于etcd
|
||||
*/
|
||||
private transient long version;
|
||||
/**
|
||||
* collector使用 - 指标组任务执行优先级视图
|
||||
* 0 - availability
|
||||
* 1 - cpu | memory
|
||||
* 2 - health
|
||||
* 3 - otherMetrics
|
||||
* ....
|
||||
* 126 - otherMetrics
|
||||
* 127 - lastPriorMetrics
|
||||
*/
|
||||
private transient List<Set<Metrics>> priorMetrics;
|
||||
|
||||
/**
|
||||
* collector使用 - 构造初始化标志
|
||||
*/
|
||||
private transient boolean isConstruct = false;
|
||||
|
||||
/**
|
||||
* collector使用 - 构造初始化指标组
|
||||
*/
|
||||
public synchronized void constructMetrics() {
|
||||
if (isConstruct) {
|
||||
return;
|
||||
}
|
||||
Map<Byte, List<Metrics>> map = metrics.stream()
|
||||
.peek(metric -> {
|
||||
// 判断是否配置aliasFields 没有则配置默认
|
||||
if (metric.getAliasFields() == null || metric.getAliasFields().isEmpty()) {
|
||||
metric.setAliasFields(metric.getFields());
|
||||
}
|
||||
// 设置默认的指标组执行优先级
|
||||
if (metric.getPriority() == null) {
|
||||
if (AVAILABILITY.equals(metric.getName())) {
|
||||
metric.setPriority((byte)0);
|
||||
} else {
|
||||
metric.setPriority(Byte.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect(Collectors.groupingBy(Metrics::getPriority));
|
||||
// 构造指标组任务执行顺序链表
|
||||
priorMetrics = new LinkedList<>();
|
||||
map.values().forEach(metric -> {
|
||||
Set<Metrics> metricsSet = new HashSet<>(metric);
|
||||
priorMetrics.add(metricsSet);
|
||||
});
|
||||
priorMetrics.sort(Comparator.comparing(e -> {
|
||||
Optional<Metrics> metric = e.stream().findAny();
|
||||
if (metric.isPresent()) {
|
||||
return metric.get().getPriority();
|
||||
} else {
|
||||
return Byte.MAX_VALUE;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* collector使用 - 获取下一组优先级的指标组任务
|
||||
* @param metrics 当前指标组
|
||||
* @param first 是否是第一次获取
|
||||
* @return 指标组任务
|
||||
* 返回null表示:job已完成,所有指标组采集结束
|
||||
* 返回empty的集合表示:当前级别下还有指标组采集任务未结束,无法进行下一级别的指标组任务采集
|
||||
* 返回有数据集合表示:获取到下一组优先级的指标组任务
|
||||
*/
|
||||
public synchronized Set<Metrics> getNextCollectMetrics(Metrics metrics, boolean first) {
|
||||
if (!isConstruct || priorMetrics == null || priorMetrics.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Set<Metrics> metricsSet = priorMetrics.get(0);
|
||||
if (first) {
|
||||
log.error("metrics must has one [availability] metrics at least.");
|
||||
return metricsSet;
|
||||
}
|
||||
if (metrics == null) {
|
||||
log.error("metrics can not null when not first get");
|
||||
}
|
||||
if (metrics != null && !metricsSet.remove(metrics)) {
|
||||
log.error("Job {} appId {} app {} metrics {} remove empty error in priorMetrics.",
|
||||
id, appId, app, metrics.getName());
|
||||
}
|
||||
if (metricsSet.isEmpty()) {
|
||||
if (priorMetrics.size() == 1) {
|
||||
return null;
|
||||
}
|
||||
priorMetrics.remove(0);
|
||||
return priorMetrics.get(0);
|
||||
} else {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.usthe.common.entity.job;
|
||||
|
||||
import com.usthe.common.entity.job.protocol.HttpProtocol;
|
||||
import com.usthe.common.entity.job.protocol.IcmpProtocol;
|
||||
import com.usthe.common.entity.job.protocol.JdbcProtocol;
|
||||
import com.usthe.common.entity.job.protocol.TcpUdpProtocol;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 监控采集的指标集合详情 eg: cpu | memory | health
|
||||
* @author tomsun28
|
||||
* @date 2021/10/17 21:24
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class Metrics {
|
||||
|
||||
/**
|
||||
* 公共属性-名称 eg: cpu | memory | health
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 公共属性-采集监控协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
|
||||
*/
|
||||
private String protocol;
|
||||
/**
|
||||
* 范围(0-127)指标组调度优先级,数值越小优先级越高
|
||||
* 优先级高的调度采集完成后才会调度下一优先级的指标组采集任务
|
||||
* 可用性指标组(availability)默认优先级为0,其它普通指标组范围为1-127,即需要等availability采集成功后才会调度后面的指标组任务
|
||||
*/
|
||||
private Byte priority;
|
||||
/**
|
||||
* 公共属性-采集监控的最终结果属性集合 eg: speed | times | size
|
||||
*/
|
||||
private List<String> fields;
|
||||
/**
|
||||
* 公共属性-采集监控的前置查询属性集合 eg: size1 | size2 | speedSize
|
||||
*/
|
||||
private List<String> aliasFields;
|
||||
/**
|
||||
* 公共属性-表达式计算,将前置查询属性(preFields)与最终属性(fields)映射,计算出最终属性(fields)值
|
||||
* eg: size = size1 + size2, speed = speedSize
|
||||
* https://www.yuque.com/boyan-avfmj/aviatorscript/ban32m
|
||||
*/
|
||||
private List<String> calculates;
|
||||
|
||||
/**
|
||||
* 使用http协议的监控配置信息
|
||||
*/
|
||||
private HttpProtocol http;
|
||||
/**
|
||||
* 使用icmp协议进行ping的监控配置信息
|
||||
*/
|
||||
private IcmpProtocol icmp;
|
||||
/**
|
||||
* 使用socket实现的tcp或ucp进行服务端口探测配置信息
|
||||
*/
|
||||
private TcpUdpProtocol tcpUdp;
|
||||
/**
|
||||
* 使用公共的jdbc规范实现的数据库配置信息
|
||||
*/
|
||||
private JdbcProtocol jdbc;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.usthe.common.entity.job.protocol;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* http 协议配置
|
||||
* @author tomsun28
|
||||
* @date 2021/10/31 12:41
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class HttpProtocol {
|
||||
/**
|
||||
* 对端主机ip或域名
|
||||
*/
|
||||
private String host;
|
||||
/**
|
||||
* http/https 请求访问的url链接
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* http是否使用链路加密ssl/tls,即是http还是https
|
||||
*/
|
||||
private boolean ssl = false;
|
||||
/**
|
||||
* http请求方法: get, post, put, delete, patch
|
||||
*/
|
||||
private String method;
|
||||
/**
|
||||
* http请求携带头 eg: Content-Type = application/json
|
||||
*/
|
||||
private Map<String, String> headers;
|
||||
/**
|
||||
* http请求携带查询参数 eg: localhost:80/api?paramKey=value
|
||||
*/
|
||||
private Map<String, String> params;
|
||||
/**
|
||||
* 认证信息
|
||||
*/
|
||||
private Authorization authorization;
|
||||
/**
|
||||
* 响应数据解析方式
|
||||
* default - 自有的数据解析规则
|
||||
* json_path 自定义jsonPath脚本 https://www.jsonpath.cn/
|
||||
* xml_path 自定义xmlPath脚本
|
||||
* prometheus Prometheus数据规则
|
||||
*/
|
||||
private String parseType;
|
||||
/**
|
||||
* 数据解析脚本 当解析方式为 jsonPath or xmlPath时存在
|
||||
*/
|
||||
private String parseScript;
|
||||
|
||||
/**
|
||||
* 认证信息
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Authorization {
|
||||
/**
|
||||
* 认证类型:Bearer Token, Basic Auth, Digest Auth
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* Bearer Token's token
|
||||
*/
|
||||
private String bearerTokenToken;
|
||||
/**
|
||||
* Basic Auth's username
|
||||
*/
|
||||
private String basicAuthUsername;
|
||||
/**
|
||||
* Basic Auth's password
|
||||
*/
|
||||
private String basicAuthPassword;
|
||||
/**
|
||||
* Digest Auth's username
|
||||
*/
|
||||
private String digestAuthUsername;
|
||||
/**
|
||||
* Digest Auth's password
|
||||
*/
|
||||
private String digestAuthPassword;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.usthe.common.entity.job.protocol;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* icmp(即ping)协议配置
|
||||
* @author tomsun28
|
||||
* @date 2021/10/31 16:41
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class IcmpProtocol {
|
||||
/**
|
||||
* 对端主机ip或域名
|
||||
*/
|
||||
private String host;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.usthe.common.entity.job.protocol;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 公共的jdbc规范实现的数据库配置信息
|
||||
* @author tomsun28
|
||||
* @date 2021/10/31 17:33
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class JdbcProtocol {
|
||||
/**
|
||||
* 对端主机ip或域名
|
||||
*/
|
||||
private String host;
|
||||
/**
|
||||
* 端口号
|
||||
*/
|
||||
private Integer port;
|
||||
/**
|
||||
* 数据库用户名(可选)
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 数据库密码(可选)
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 数据库链接url eg: jdbc:mysql://localhost:3306
|
||||
*/
|
||||
private String url;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.usthe.common.entity.job.protocol;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 使用socket实现的tcp或ucp进行服务端口可用性探测
|
||||
* @author tomsun28
|
||||
* @date 2021/10/31 17:27
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TcpUdpProtocol {
|
||||
/**
|
||||
* 具体协议类型 tcp, udp
|
||||
*/
|
||||
private String protocol;
|
||||
/**
|
||||
* 对端主机ip或域名
|
||||
*/
|
||||
private String host;
|
||||
/**
|
||||
* 端口号
|
||||
*/
|
||||
private Integer port;
|
||||
}
|
||||
3225
common/src/main/java/com/usthe/common/entity/message/CollectRep.java
Normal file
3225
common/src/main/java/com/usthe/common/entity/message/CollectRep.java
Normal file
File diff suppressed because it is too large
Load Diff
41
common/src/main/java/com/usthe/common/util/GsonUtil.java
Normal file
41
common/src/main/java/com/usthe/common/util/GsonUtil.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.usthe.common.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.etcd.jetcd.ByteSequence;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* gson 工具类
|
||||
* @author tomsun28
|
||||
* @date 2021/10/16 20:49
|
||||
*/
|
||||
@ThreadSafe
|
||||
public class GsonUtil {
|
||||
|
||||
private static Gson gson;
|
||||
|
||||
static {
|
||||
gson = new GsonBuilder().enableComplexMapKeySerialization()
|
||||
.serializeNulls()
|
||||
.create();
|
||||
}
|
||||
|
||||
public static String toJson(Object source) {
|
||||
return gson.toJson(source);
|
||||
}
|
||||
|
||||
public static <T> T fromJson(String jsonStr, Class<T> clazz) {
|
||||
return gson.fromJson(jsonStr, clazz);
|
||||
}
|
||||
|
||||
public static <T> T fromJson(ByteSequence byteSequence, Class<T> clazz) {
|
||||
if (byteSequence == null || byteSequence.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return gson.fromJson(byteSequence.toString(StandardCharsets.UTF_8), clazz);
|
||||
}
|
||||
|
||||
}
|
||||
46
common/src/main/message/collect_rep.proto
Normal file
46
common/src/main/message/collect_rep.proto
Normal file
@@ -0,0 +1,46 @@
|
||||
syntax = "proto3";
|
||||
package com.usthe.common.entity.message;
|
||||
|
||||
message MetricsData
|
||||
{
|
||||
// 监控的ID
|
||||
uint64 id = 1;
|
||||
// 监控的类型 eg: linux | mysql | jvm
|
||||
string app = 2;
|
||||
// 监控采集的指标集合 eg: cpu | memory | health
|
||||
string metrics = 3;
|
||||
// 采集时间
|
||||
uint64 time = 4;
|
||||
// 采集响应码
|
||||
Code code = 5;
|
||||
// 采集响应信息
|
||||
string msg = 6;
|
||||
// 采集指标名
|
||||
repeated string fields = 7;
|
||||
// 采集指标值集合(fields作为字段名称与ValueRow映射)
|
||||
repeated ValueRow values = 8;
|
||||
}
|
||||
|
||||
message ValueRow
|
||||
{
|
||||
// 主键实例,唯一标识这行数据
|
||||
string instance = 1;
|
||||
// 采集指标值
|
||||
repeated string columns = 2;
|
||||
}
|
||||
|
||||
enum Code
|
||||
{
|
||||
// 采集成功
|
||||
SUCCESS = 0;
|
||||
// 采集器不可用
|
||||
UN_AVAILABLE = 1;
|
||||
// 对端不可达(网络层icmp)
|
||||
UN_REACHABLE = 2;
|
||||
// 对端连接失败(传输层tcp,udp)
|
||||
UN_CONNECTABLE = 3;
|
||||
// 数据采集失败(应用层http,ssh,snmp)
|
||||
FAIL = 4;
|
||||
// 采集超时
|
||||
TIMEOUT = 5;
|
||||
}
|
||||
18
manager/pom.xml
Normal file
18
manager/pom.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>monitor</artifactId>
|
||||
<groupId>com.usthe.tancloud</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>manager</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
129
pom.xml
Normal file
129
pom.xml
Normal file
@@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.usthe.tancloud</groupId>
|
||||
<artifactId>monitor</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<modules>
|
||||
<module>scheduler</module>
|
||||
<module>manager</module>
|
||||
<module>alerter</module>
|
||||
<module>common</module>
|
||||
<module>collector</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<slf4j.version>1.7.21</slf4j.version>
|
||||
<xml.bind.version>2.3.0</xml.bind.version>
|
||||
<lombok.version>1.18.20</lombok.version>
|
||||
<!-- Test 3rd-party dependencies: -->
|
||||
<junit.version>5.7.0</junit.version>
|
||||
<easymock.version>4.0.2</easymock.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<!-- Import dependency management from Spring Boot -->
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>2.4.5</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>${xml.bind.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- 工具 -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test 3rd-party dependencies: -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>${easymock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
<!-- java code style check -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-pmd-plugin</artifactId>
|
||||
<version>3.8</version>
|
||||
<configuration>
|
||||
<rulesets>
|
||||
<ruleset>rulesets/java/ali-comment.xml</ruleset>
|
||||
<ruleset>rulesets/java/ali-concurrent.xml</ruleset>
|
||||
<ruleset>rulesets/java/ali-constant.xml</ruleset>
|
||||
<ruleset>rulesets/java/ali-exception.xml</ruleset>
|
||||
<!-- <ruleset>rulesets/java/ali-flowcontrol.xml</ruleset>-->
|
||||
<ruleset>rulesets/java/ali-naming.xml</ruleset>
|
||||
<ruleset>rulesets/java/ali-oop.xml</ruleset>
|
||||
<ruleset>rulesets/java/ali-orm.xml</ruleset>
|
||||
<ruleset>rulesets/java/ali-other.xml</ruleset>
|
||||
<ruleset>rulesets/java/ali-set.xml</ruleset>
|
||||
</rulesets>
|
||||
<printFailingErrors>true</printFailingErrors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>validate</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.p3c</groupId>
|
||||
<artifactId>p3c-pmd</artifactId>
|
||||
<version>1.3.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
Reference in New Issue
Block a user