Compare commits
19 Commits
fix#cache
...
feature#xg
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e9c00934e | ||
|
|
73d743a078 | ||
|
|
1f52ae4a88 | ||
|
|
a6a5f6abb4 | ||
|
|
56f2e826a9 | ||
|
|
ddb290bba3 | ||
|
|
f710795f0f | ||
|
|
88b03448e3 | ||
|
|
63d03c7ac6 | ||
|
|
223f36c6cb | ||
|
|
bf31faa831 | ||
|
|
792d461844 | ||
|
|
63fe51b597 | ||
|
|
eb65ee4206 | ||
|
|
b5bc5d2975 | ||
|
|
4db3e04dd6 | ||
|
|
540f4bcbf4 | ||
|
|
9eb3b9842d | ||
|
|
790bcc6f16 |
25
README.md
25
README.md
@@ -14,15 +14,16 @@
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
**官网: [hertzbeat.com](https://hertzBeat.com) | [tancloud.cn](https://tancloud.cn)**
|
||||
**官网: [hertzbeat.com](https://hertzbeat.com) | [tancloud.cn](https://tancloud.cn)**
|
||||
|
||||
## 🎡 <font color="green">介绍</font>
|
||||
|
||||
> [HertzBeat赫兹跳动](https://github.com/dromara/hertzbeat) 是由[Dromara](https://dromara.org)孵化,[TanCloud](https://tancloud.cn)开源的一个支持网站,API,PING,端口,数据库等监控类型,拥有易用友好的可视化操作界面的开源监控告警项目。
|
||||
> [HertzBeat赫兹跳动](https://github.com/dromara/hertzbeat) 是由[Dromara](https://dromara.org)孵化,[TanCloud](https://tancloud.cn)开源的一个支持网站,API,PING,端口,数据库,操作系统等监控类型,拥有易用友好的可视化操作界面的开源监控告警项目。
|
||||
> 我们也提供了对应的 **[SAAS版本监控云](https://console.tancloud.cn)**,中小团队和个人无需再为了监控自己的网站资源,而去部署一套繁琐的监控系统,**[登录即可免费开始](https://console.tancloud.cn)**。
|
||||
> HertzBeat 支持[自定义监控](https://hertzbeat.com/docs/advanced/extend-point) ,只用通过配置YML文件我们就可以自定义需要的监控类型和指标,来满足常见的个性化需求。
|
||||
> HertzBeat 模块化,`manager, collector, scheduler, warehouse, alerter` 各个模块解耦合,方便理解与定制开发。
|
||||
@@ -59,7 +60,7 @@
|
||||
## 🐕 快速开始
|
||||
|
||||
- 如果您不想部署而是直接使用,我们提供SAAS监控云-[TanCloud探云](https://console.tancloud.cn),即刻 **[登录注册](https://console.tancloud.cn)** 免费使用。
|
||||
- 如果您是想将HertzBeat部署到内网环境搭建监控系统,请参考下面的[部署文档](https://hertzbeat.com/docs/start/quickstart)进行操作。
|
||||
- 如果您是想将HertzBeat部署到内网环境搭建监控系统,请参考下面的 [部署文档](https://hertzbeat.com/docs/start/quickstart) 进行操作。
|
||||
|
||||
### 🐵 依赖服务部署
|
||||
|
||||
@@ -67,7 +68,7 @@
|
||||
|
||||
##### 安装MYSQL
|
||||
1. docker安装MYSQl
|
||||
`docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql`
|
||||
`docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7`
|
||||
2. 创建名称为hertzbeat的数据库
|
||||
3. 执行位于项目仓库/script/sql/目录下的数据库脚本 [schema.sql](https://gitee.com/dromara/hertzbeat/raw/master/script/sql/schema.sql)
|
||||
|
||||
@@ -75,7 +76,7 @@
|
||||
|
||||
##### 安装TDengine
|
||||
1. docker安装TDengine
|
||||
`docker run -d -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp --name tdengine tdengine/tdengine`
|
||||
`docker run -d -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp --name tdengine tdengine/tdengine:2.4.0.12`
|
||||
2. 创建名称为hertzbeat的数据库
|
||||
|
||||
详细步骤参考 [依赖服务TDengine安装初始化](https://hertzbeat.com/docs/start/tdengine-init)
|
||||
@@ -83,26 +84,32 @@
|
||||
### 🍞 HertzBeat安装
|
||||
> HertzBeat支持通过源码安装启动,Docker容器运行和安装包方式安装部署。
|
||||
|
||||
##### Docker方式快速安装
|
||||
##### 方式一:Docker方式快速安装
|
||||
`docker run -d -p 1157:1157 -v /opt/application.yml:/opt/hertzbeat/config/application.yml --name hertzbeat tancloud/hertzbeat:[版本tag]`
|
||||
|
||||
详细步骤参考 [通过Docker方式安装HertzBeat](https://hertzbeat.com/docs/start/docker-deploy)
|
||||
|
||||
##### 通过安装包安装
|
||||
##### 方式二:通过安装包安装
|
||||
1. 下载您系统环境对应的安装包 [GITEE Release](https://gitee.com/dromara/hertzbeat/releases) [GITHUB Release](https://github.com/dromara/hertzbeat/releases)
|
||||
2. 配置HertzBeat的配置文件 hertzbeat/config/application.yml
|
||||
3. 部署启动 `$ ./startup.sh `
|
||||
|
||||
详细步骤参考 [通过安装包安装HertzBeat](https://hertzbeat.com/docs/start/package-deploy)
|
||||
|
||||
##### 本地代码启动
|
||||
##### 方式三:本地代码启动
|
||||
1. 此为前后端分离项目,本地代码调试需要分别启动后端工程manager和前端工程web-app
|
||||
2. 后端:需要`maven3+`和`java8+`环境,修改YML配置信息并启动manager服务
|
||||
3. 前端:需要`nodejs npm angular-cli`环境,待本地后端启动后,在web-app目录下启动 `ng serve --open`
|
||||
4. 浏览器访问 localhost:4200 即可开始
|
||||
4. 浏览器访问 localhost:4200 即可开始,默认账号密码 admin/admin
|
||||
|
||||
详细步骤参考 [参与贡献之本地代码启动](CONTRIBUTING.md)
|
||||
|
||||
##### 方式四:Docker-compose统一安装hertzbeat及其依赖服务
|
||||
|
||||
通过 [docker-compose部署脚本](script/docker-compose) 一次性把mysql数据库,tdengine数据库和hertzbeat安装部署。
|
||||
|
||||
详细步骤参考 [docker-compose安装](script/docker-compose/README.md)
|
||||
|
||||
**HAVE FUN**
|
||||
|
||||
## 💬 社区交流
|
||||
|
||||
@@ -103,6 +103,12 @@
|
||||
<artifactId>sshd-core</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
<!-- sql server -->
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<version>10.2.0.jre8</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -2,6 +2,7 @@ package com.usthe.collector.collect.common.cache;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 缓存key唯一标识符
|
||||
@@ -10,6 +11,7 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@ToString
|
||||
public class CacheIdentifier {
|
||||
|
||||
private String ip;
|
||||
|
||||
@@ -21,9 +21,9 @@ import java.util.concurrent.TimeUnit;
|
||||
public class CommonCache {
|
||||
|
||||
/**
|
||||
* 默认缓存时间 10minute
|
||||
* 默认缓存时间 800s
|
||||
*/
|
||||
private static final long DEFAULT_CACHE_TIMEOUT = 10 * 60 * 1000L;
|
||||
private static final long DEFAULT_CACHE_TIMEOUT = 800 * 1000L;
|
||||
|
||||
/**
|
||||
* 默认最大缓存数量
|
||||
@@ -121,15 +121,17 @@ public class CommonCache {
|
||||
timeoutMap.put(key, new Long[]{currentTime, DEFAULT_CACHE_TIMEOUT});
|
||||
} else if (cacheTime[0] + cacheTime[1] < currentTime) {
|
||||
// 过期了 discard 关闭这个cache的资源
|
||||
log.warn("[cache] clean the timeout cache, key {}", key);
|
||||
timeoutMap.remove(key);
|
||||
cacheMap.remove(key);
|
||||
if (value instanceof CacheCloseable) {
|
||||
log.warn("[cache] close the timeout cache, key {}", key);
|
||||
((CacheCloseable)value).close();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("clean timeout cache error: {}.", e.getMessage(), e);
|
||||
log.error("[cache] clean timeout cache error: {}.", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,15 +175,18 @@ public class CommonCache {
|
||||
public Optional<Object> getCache(Object key, boolean refreshCache) {
|
||||
Long[] cacheTime = timeoutMap.get(key);
|
||||
if (cacheTime == null || cacheTime.length != CACHE_TIME_LENGTH) {
|
||||
log.warn("[cache] not hit the cache, key {}.", key);
|
||||
return Optional.empty();
|
||||
}
|
||||
if (cacheTime[0] + cacheTime[1] < System.currentTimeMillis()) {
|
||||
log.warn("[cache] is timeout, remove it, key {}.", key);
|
||||
timeoutMap.remove(key);
|
||||
cacheMap.remove(key);
|
||||
return Optional.empty();
|
||||
}
|
||||
Object value = cacheMap.get(key);
|
||||
if (value == null) {
|
||||
log.error("[cache] value is null, remove it, key {}.", key);
|
||||
cacheMap.remove(key);
|
||||
timeoutMap.remove(key);
|
||||
} else if (refreshCache) {
|
||||
|
||||
@@ -52,9 +52,19 @@ public class JdbcCommonCollect extends AbstractCollect {
|
||||
}
|
||||
JdbcProtocol jdbcProtocol = metrics.getJdbc();
|
||||
String databaseUrl = constructDatabaseUrl(jdbcProtocol);
|
||||
// 查询超时时间默认3000毫秒
|
||||
int timeout = 3000;
|
||||
try {
|
||||
// 获取查询语句超时时间
|
||||
if (jdbcProtocol.getTimeout() != null) {
|
||||
timeout = Integer.parseInt(jdbcProtocol.getTimeout());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn(e.getMessage());
|
||||
}
|
||||
try {
|
||||
Statement statement = getConnection(jdbcProtocol.getUsername(),
|
||||
jdbcProtocol.getPassword(), databaseUrl);
|
||||
jdbcProtocol.getPassword(), databaseUrl, timeout);
|
||||
switch (jdbcProtocol.getQueryType()) {
|
||||
case QUERY_TYPE_ONE_ROW:
|
||||
queryOneRow(statement, jdbcProtocol.getSql(), metrics.getAliasFields(), builder, startTime);
|
||||
@@ -95,7 +105,7 @@ public class JdbcCommonCollect extends AbstractCollect {
|
||||
}
|
||||
|
||||
|
||||
private Statement getConnection(String username, String password, String url) throws Exception {
|
||||
private Statement getConnection(String username, String password, String url,Integer timeout) throws Exception {
|
||||
CacheIdentifier identifier = CacheIdentifier.builder()
|
||||
.ip(url)
|
||||
.username(username).password(password).build();
|
||||
@@ -106,7 +116,9 @@ public class JdbcCommonCollect extends AbstractCollect {
|
||||
try {
|
||||
statement = jdbcConnect.getConnection().createStatement();
|
||||
// 设置查询超时时间10秒
|
||||
statement.setQueryTimeout(10);
|
||||
int timeoutSecond = timeout / 1000;
|
||||
timeoutSecond = timeoutSecond <= 0 ? 1 : timeoutSecond;
|
||||
statement.setQueryTimeout(timeoutSecond);
|
||||
// 设置查询最大行数1000行
|
||||
statement.setMaxRows(1000);
|
||||
} catch (Exception e) {
|
||||
@@ -130,11 +142,13 @@ public class JdbcCommonCollect extends AbstractCollect {
|
||||
Connection connection = DriverManager.getConnection(url, username, password);
|
||||
statement = connection.createStatement();
|
||||
// 设置查询超时时间10秒
|
||||
statement.setQueryTimeout(10);
|
||||
int timeoutSecond = timeout / 1000;
|
||||
timeoutSecond = timeoutSecond <= 0 ? 1 : timeoutSecond;
|
||||
statement.setQueryTimeout(timeoutSecond);
|
||||
// 设置查询最大行数1000行
|
||||
statement.setMaxRows(1000);
|
||||
JdbcConnect jdbcConnect = new JdbcConnect(connection);
|
||||
CommonCache.getInstance().addCache(identifier, jdbcConnect, 10000L);
|
||||
CommonCache.getInstance().addCache(identifier, jdbcConnect);
|
||||
return statement;
|
||||
}
|
||||
|
||||
@@ -190,7 +204,7 @@ public class JdbcCommonCollect extends AbstractCollect {
|
||||
HashMap<String, String> values = new HashMap<>(columns.size());
|
||||
while (resultSet.next()) {
|
||||
if (resultSet.getString(1) != null) {
|
||||
values.put(resultSet.getString(1).toLowerCase(), resultSet.getString(2));
|
||||
values.put(resultSet.getString(1).toLowerCase().trim(), resultSet.getString(2));
|
||||
}
|
||||
}
|
||||
CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
|
||||
@@ -267,6 +281,10 @@ public class JdbcCommonCollect extends AbstractCollect {
|
||||
url = "jdbc:postgresql://" + jdbcProtocol.getHost() + ":" + jdbcProtocol.getPort()
|
||||
+ "/" + (jdbcProtocol.getDatabase() == null ? "" : jdbcProtocol.getDatabase());
|
||||
break;
|
||||
case "sqlserver":
|
||||
url = "jdbc:sqlserver://" + jdbcProtocol.getHost() + ":" + jdbcProtocol.getPort()
|
||||
+ ";" + (jdbcProtocol.getDatabase() == null ? "" : "DatabaseName=" + jdbcProtocol.getDatabase());
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Not support database platform: " + jdbcProtocol.getPlatform());
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -172,14 +173,23 @@ public class MetricsCollect implements Runnable, Comparable<MetricsCollect> {
|
||||
if (metrics.getCalculates() == null) {
|
||||
metrics.setCalculates(Collections.emptyList());
|
||||
}
|
||||
// eg: database_pages=Database pages 非常规映射
|
||||
Map<String, String> fieldAliasMap = new HashMap<>(8);
|
||||
Map<String, Expression> fieldExpressionMap = metrics.getCalculates()
|
||||
.stream()
|
||||
.map(cal -> {
|
||||
int splitIndex = cal.indexOf("=");
|
||||
String field = cal.substring(0, splitIndex);
|
||||
String expressionStr = cal.substring(splitIndex + 1);
|
||||
Expression expression = AviatorEvaluator.compile(expressionStr, true);
|
||||
Expression expression = null;
|
||||
try {
|
||||
expression = AviatorEvaluator.compile(expressionStr, true);
|
||||
} catch (Exception e) {
|
||||
fieldAliasMap.put(field, expressionStr);
|
||||
return null;
|
||||
}
|
||||
return new Object[]{field, expression}; })
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toMap(arr -> (String)arr[0], arr -> (Expression) arr[1]));
|
||||
|
||||
List<Metrics.Field> fields = metrics.getFields();
|
||||
@@ -226,7 +236,12 @@ public class MetricsCollect implements Runnable, Comparable<MetricsCollect> {
|
||||
}
|
||||
} else {
|
||||
// 不存在 则映射别名值
|
||||
value = aliasFieldValueMap.get(realField);
|
||||
String aliasField = fieldAliasMap.get(realField);
|
||||
if (aliasField != null) {
|
||||
value = aliasFieldValueMap.get(aliasField);
|
||||
} else {
|
||||
value = aliasFieldValueMap.get(realField);
|
||||
}
|
||||
}
|
||||
if (value == null) {
|
||||
value = CommonConstants.NULL_VALUE;
|
||||
|
||||
@@ -35,6 +35,10 @@ public class JdbcProtocol {
|
||||
* 数据库
|
||||
*/
|
||||
private String database;
|
||||
/**
|
||||
* 超时时间
|
||||
*/
|
||||
private String timeout;
|
||||
/**
|
||||
* 数据库类型 mysql oracle ...
|
||||
*/
|
||||
|
||||
@@ -15,7 +15,6 @@ public class JsonOptionListAttributeConverter implements AttributeConverter<List
|
||||
@Override
|
||||
public String convertToDatabaseColumn(List<ParamDefine.Option> attribute) {
|
||||
return GsonUtil.toJson(attribute);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,9 @@ import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_WRITE;
|
||||
@ApiModel(description = "监控实体")
|
||||
public class Monitor {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Id
|
||||
@ApiModelProperty(value = "监控ID", example = "87584674384", accessMode = READ_ONLY, position = 0)
|
||||
private Long id;
|
||||
|
||||
@@ -29,14 +29,14 @@ HTTP协议支持我们自定义HTTP请求路径,请求header,请求参数,
|
||||
|
||||
> 监控配置定义文件用于定义 *监控类型的名称(国际化), 请求参数映射, 指标信息, 采集协议配置信息*等。
|
||||
|
||||
样例:自定义一个名称为example的自定义监控类型,其使用HTTP协议采集指标数据。
|
||||
文件名称: example.yml 位于 /define/app/example.yml
|
||||
样例:自定义一个名称为example_http的自定义监控类型,其使用HTTP协议采集指标数据。
|
||||
文件名称: example_http.yml 位于 /define/app/example_http.yml
|
||||
|
||||
```yaml
|
||||
# 此监控类型所属类别:service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
|
||||
category: custom
|
||||
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||
app: example
|
||||
app: example_http
|
||||
name:
|
||||
zh-CN: 模拟应用类型
|
||||
en-US: EXAMPLE APP
|
||||
@@ -157,12 +157,12 @@ metrics:
|
||||
|
||||
> 监控参数定义文件用于定义 *需要的输入参数字段结构定义(前端页面根据结构渲染输入参数框)*。
|
||||
|
||||
样例:自定义一个名称为example的自定义监控类型,其使用HTTP协议采集指标数据。
|
||||
文件名称: example.yml 位于 //define/param/example.yml
|
||||
样例:自定义一个名称为example_http的自定义监控类型,其使用HTTP协议采集指标数据。
|
||||
文件名称: example_http.yml 位于 //define/param/example_http.yml
|
||||
|
||||
```yaml
|
||||
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||
app: example
|
||||
app: example_http
|
||||
# 强制固定必须参数 - host(ipv4,ipv6,域名)
|
||||
param:
|
||||
# field-字段名称标识符
|
||||
|
||||
@@ -50,8 +50,8 @@ SQL响应数据:
|
||||
### 自定义步骤
|
||||
|
||||
配置自定义监控类型需新增配置两个YML文件
|
||||
1. 用监控类型命名的监控配置定义文件 - 例如:example.yml 需位于安装目录 /hertzbeat/define/app/ 下
|
||||
2. 用监控类型命名的监控参数定义文件 - 例如:example.yml 需位于安装目录 /hertzbeat/define/param/ 下
|
||||
1. 用监控类型命名的监控配置定义文件 - 例如:example_sql.yml 需位于安装目录 /hertzbeat/define/app/ 下
|
||||
2. 用监控类型命名的监控参数定义文件 - 例如:example_sql.yml 需位于安装目录 /hertzbeat/define/param/ 下
|
||||
3. 重启hertzbeat系统,我们就适配好了一个新的自定义监控类型。
|
||||
|
||||
-------
|
||||
@@ -61,14 +61,14 @@ SQL响应数据:
|
||||
|
||||
> 监控配置定义文件用于定义 *监控类型的名称(国际化), 请求参数映射, 指标信息, 采集协议配置信息*等。
|
||||
|
||||
样例:自定义一个名称为example的自定义监控类型,其使用HTTP协议采集指标数据。
|
||||
文件名称: example.yml 位于 /define/app/example.yml
|
||||
样例:自定义一个名称为example_sql的自定义监控类型,其使用JDBC协议采集指标数据。
|
||||
文件名称: example_sql.yml 位于 /define/app/example_sql.yml
|
||||
|
||||
```yaml
|
||||
# 此监控类型所属类别:service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
|
||||
category: db
|
||||
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||
app: example
|
||||
app: example_sql
|
||||
name:
|
||||
zh-CN: 模拟MYSQL应用类型
|
||||
en-US: MYSQL EXAMPLE APP
|
||||
@@ -215,11 +215,11 @@ metrics:
|
||||
|
||||
> 监控参数定义文件用于定义 *需要的输入参数字段结构定义(前端页面根据结构渲染输入参数框)*。
|
||||
|
||||
样例:自定义一个名称为example的自定义监控类型,其使用HTTP协议采集指标数据。
|
||||
文件名称: example.yml 位于 /define/param/example.yml
|
||||
样例:自定义一个名称为example_sql的自定义监控类型,其使用JDBC协议采集指标数据。
|
||||
文件名称: example_sql.yml 位于 /define/param/example_sql.yml
|
||||
|
||||
```yaml
|
||||
app: example
|
||||
app: example_sql
|
||||
param:
|
||||
- field: host
|
||||
name: 主机Host
|
||||
|
||||
@@ -4,7 +4,7 @@ title: 自定义监控
|
||||
sidebar_label: 自定义监控
|
||||
---
|
||||
> HertzBeat拥有自定义监控能力,您只需配置两个YML文件就能适配一款自定义的监控类型。
|
||||
> 目前自定义监控支持[HTTP协议](extend-http),[JDBC](extend-jdbc)(mysql,mariadb,postgresql..)协议,后续会支持更多通用协议(ssh telnet wmi snmp)。
|
||||
> 目前自定义监控支持[HTTP协议](extend-http),[JDBC协议](extend-jdbc)(mysql,mariadb,postgresql..),[SSH协议](extend-ssh),后续会支持更多通用协议(ssh telnet wmi snmp)。
|
||||
|
||||
### 自定义步骤
|
||||
|
||||
|
||||
220
home/docs/advanced/extend-ssh.md
Normal file
220
home/docs/advanced/extend-ssh.md
Normal file
@@ -0,0 +1,220 @@
|
||||
---
|
||||
id: extend-ssh
|
||||
title: SSH协议自定义监控
|
||||
sidebar_label: SSH协议自定义监控
|
||||
---
|
||||
> 从[自定义监控](extend-point)了解熟悉了怎么自定义类型,指标,协议等,这里我们来详细介绍下用SSH协议自定义指标监控。
|
||||
> SSH协议自定义监控可以让我们很方便的通过写sh命令脚本就能监控采集到我们想监控的Linux指标
|
||||
|
||||
### SSH协议采集流程
|
||||
【**系统直连Linux**】->【**运行SHELL命令脚本语句**】->【**响应数据解析:oneRow, multiRow**】->【**指标数据提取**】
|
||||
|
||||
由流程可见,我们自定义一个SSH协议的监控类型,需要配置SSH请求参数,配置获取哪些指标,配置查询脚本语句。
|
||||
|
||||
### 数据解析方式
|
||||
SHELL脚本查询回来的数据字段和我们需要的指标映射,就能获取对应的指标数据,目前映射解析方式有两种:oneRow, multiRow,能满足绝大部分指标需求。
|
||||
|
||||
#### **oneRow**
|
||||
> 查询出一列数据, 通过查询返回结果集的字段值(一行一个值)与字段映射
|
||||
|
||||
例如:
|
||||
需要查询Linux的指标 hostname-主机名称,uptime-启动时间
|
||||
主机名称原始查询命令:`hostname`
|
||||
启动时间原始查询命令:`uptime | awk -F "," '{print $1}'`
|
||||
则在hertzbeat对应的这两个指标的查询脚本为(用`;`将其连接到一起):
|
||||
`hostname; uptime | awk -F "," '{print $1}'`
|
||||
终端响应的数据为:
|
||||
```
|
||||
tombook
|
||||
14:00:15 up 72 days
|
||||
```
|
||||
则最后采集到的指标数据一一映射为:
|
||||
hostname值为 `tombook`
|
||||
uptime值为 `14:00:15 up 72 days`
|
||||
|
||||
这里指标字段就能和响应数据一一映射为一行采集数据。
|
||||
|
||||
#### **multiRow**
|
||||
> 查询多行数据, 通过查询返回结果集的列名称,和查询的指标字段映射
|
||||
|
||||
例如:
|
||||
查询的Linux内存相关指标字段:total-内存总量 used-已使用内存 free-空闲内存 buff-cache-缓存大小 available-可用内存
|
||||
内存指标原始查询命令为:`free -m`, 控制台响应:
|
||||
```shell
|
||||
total used free shared buff/cache available
|
||||
Mem: 7962 4065 333 1 3562 3593
|
||||
Swap: 8191 33 8158
|
||||
```
|
||||
在heartbeat中multiRow格式解析需要响应数据列名称和指标值一一映射,则对应的查询SHELL脚本为:
|
||||
`free -m | grep Mem | awk 'BEGIN{print "total used free buff_cache available"} {print $2,$3,$4,$6,$7}'`
|
||||
控制台响应为:
|
||||
```shell
|
||||
total used free buff_cache available
|
||||
7962 4066 331 3564 3592
|
||||
```
|
||||
|
||||
这里指标字段就能和响应数据一一映射为采集数据。
|
||||
|
||||
### 自定义步骤
|
||||
|
||||
配置自定义监控类型需新增配置两个YML文件
|
||||
1. 用监控类型命名的监控配置定义文件 - 例如:example_linux.yml 需位于安装目录 /hertzbeat/define/app/ 下
|
||||
2. 用监控类型命名的监控参数定义文件 - 例如:example_linux.yml 需位于安装目录 /hertzbeat/define/param/ 下
|
||||
3. 重启hertzbeat系统,我们就适配好了一个新的自定义监控类型。
|
||||
|
||||
-------
|
||||
下面详细介绍下这俩文件的配置用法,请注意看使用注释。
|
||||
|
||||
### 监控配置定义文件
|
||||
|
||||
> 监控配置定义文件用于定义 *监控类型的名称(国际化), 请求参数映射, 指标信息, 采集协议配置信息*等。
|
||||
|
||||
样例:自定义一个名称为example_linux的自定义监控类型,其使用SSH协议采集指标数据。
|
||||
文件名称: example_linux.yml 位于 /define/app/example_linux.yml
|
||||
|
||||
```yaml
|
||||
# 此监控类型所属类别:service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
|
||||
category: os
|
||||
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||
app: example_linux
|
||||
name:
|
||||
zh-CN: 模拟LINUX应用类型
|
||||
en-US: LINUX EXAMPLE APP
|
||||
# 参数映射map. 这些为输入参数变量,即可以用^_^host^_^的形式写到后面的配置中,系统自动变量值替换
|
||||
# type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
|
||||
# 强制固定必须参数 - host
|
||||
configmap:
|
||||
- key: host
|
||||
type: 1
|
||||
- key: port
|
||||
type: 0
|
||||
- key: username
|
||||
type: 1
|
||||
- key: password
|
||||
type: 2
|
||||
# 指标组列表
|
||||
metrics:
|
||||
# 第一个监控指标组 basic
|
||||
# 注意:内置监控指标有 (responseTime - 响应时间)
|
||||
- name: basic
|
||||
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
|
||||
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
|
||||
priority: 0
|
||||
# 指标组中的具体监控指标
|
||||
fields:
|
||||
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
|
||||
- field: hostname
|
||||
type: 1
|
||||
instance: true
|
||||
- field: version
|
||||
type: 1
|
||||
- field: uptime
|
||||
type: 1
|
||||
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
|
||||
protocol: ssh
|
||||
# 当protocol为http协议时具体的采集配置
|
||||
ssh:
|
||||
# 主机host: ipv4 ipv6 域名
|
||||
host: ^_^host^_^
|
||||
# 端口
|
||||
port: ^_^port^_^
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
script: (uname -r ; hostname ; uptime | awk -F "," '{print $1}' | sed "s/ //g") | sed ":a;N;s/\n/^/g;ta" | awk -F '^' 'BEGIN{print "version hostname uptime"} {print $1, $2, $3}'
|
||||
# 响应数据解析方式:oneRow, multiRow
|
||||
parseType: multiRow
|
||||
|
||||
- name: cpu
|
||||
priority: 1
|
||||
fields:
|
||||
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
|
||||
- field: info
|
||||
type: 1
|
||||
- field: cores
|
||||
type: 0
|
||||
unit: 核数
|
||||
- field: interrupt
|
||||
type: 0
|
||||
unit: 个数
|
||||
- field: load
|
||||
type: 1
|
||||
- field: context_switch
|
||||
type: 0
|
||||
unit: 个数
|
||||
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
|
||||
protocol: ssh
|
||||
# 当protocol为http协议时具体的采集配置
|
||||
ssh:
|
||||
# 主机host: ipv4 ipv6 域名
|
||||
host: ^_^host^_^
|
||||
# 端口
|
||||
port: ^_^port^_^
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
script: "LANG=C lscpu | awk -F: '/Model name/ {print $2}';awk '/processor/{core++} END{print core}' /proc/cpuinfo;uptime | sed 's/,/ /g' | awk '{for(i=NF-2;i<=NF;i++)print $i }' | xargs;vmstat 1 1 | awk 'NR==3{print $11}';vmstat 1 1 | awk 'NR==3{print $12}'"
|
||||
parseType: oneRow
|
||||
|
||||
- name: memory
|
||||
priority: 2
|
||||
fields:
|
||||
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
|
||||
- field: total
|
||||
type: 0
|
||||
unit: Mb
|
||||
- field: used
|
||||
type: 0
|
||||
unit: Mb
|
||||
- field: free
|
||||
type: 0
|
||||
unit: Mb
|
||||
- field: buff_cache
|
||||
type: 0
|
||||
unit: Mb
|
||||
- field: available
|
||||
type: 0
|
||||
unit: Mb
|
||||
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
|
||||
protocol: ssh
|
||||
# 当protocol为http协议时具体的采集配置
|
||||
ssh:
|
||||
# 主机host: ipv4 ipv6 域名
|
||||
host: ^_^host^_^
|
||||
# 端口
|
||||
port: ^_^port^_^
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
script: free -m | grep Mem | awk 'BEGIN{print "total used free buff_cache available"} {print $2,$3,$4,$6,$7}'
|
||||
parseType: multiRow
|
||||
```
|
||||
|
||||
### 监控参数定义文件
|
||||
|
||||
> 监控参数定义文件用于定义 *需要的输入参数字段结构定义(前端页面根据结构渲染输入参数框)*。
|
||||
|
||||
样例:自定义一个名称为example_linux的自定义监控类型,其使用SSH协议采集指标数据。
|
||||
文件名称: example_linux.yml 位于 /define/param/example_linux.yml
|
||||
|
||||
```yaml
|
||||
app: example_linux
|
||||
param:
|
||||
- field: host
|
||||
name: 主机Host
|
||||
type: host
|
||||
required: true
|
||||
- field: port
|
||||
name: 端口
|
||||
type: number
|
||||
range: '[0,65535]'
|
||||
required: true
|
||||
defaultValue: 22
|
||||
placeholder: '请输入端口'
|
||||
- field: username
|
||||
name: 用户名
|
||||
type: text
|
||||
limit: 20
|
||||
required: true
|
||||
- field: password
|
||||
name: 密码
|
||||
type: password
|
||||
required: true
|
||||
```
|
||||
@@ -1,65 +0,0 @@
|
||||
---
|
||||
id: contributing
|
||||
title: 参与贡献
|
||||
sidebar_label: 参与贡献
|
||||
---
|
||||
|
||||
Contributing to Sureness
|
||||
=======================================
|
||||
Very welcome to Contribute this project, go further and better with sureness.
|
||||
Firstly, thanks for your interest in contributing! I hope that this will be a pleasant first experience for you, and that you will return to continue contributing.
|
||||
|
||||
Components of Repository:
|
||||
- [sureness's kernel code--sureness-core](https://github.com/usthe/sureness/tree/master/core)
|
||||
- [sureness integration springboot sample(configuration file scheme)--sample-bootstrap](https://github.com/usthe/sureness/tree/master/sample-bootstrap)
|
||||
- [sureness integration springboot sample(database scheme)-sample-tom](https://github.com/usthe/sureness/tree/master/sample-tom)
|
||||
- [sample projects using sureness in each framework(javalin,ktor,quarkus)--samples](https://github.com/usthe/sureness/tree/master/samples)
|
||||
|
||||
## How to contribute?
|
||||
|
||||
Most of the contributions that we receive are code contributions, but you can
|
||||
also contribute to the documentation or simply report solid bugs
|
||||
for us to fix.
|
||||
|
||||
For new contributors, please take a look at issues or pull requests with a tag called below.
|
||||
|
||||
[Good first issue](https://github.com/usthe/sureness/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
|
||||
[Help wanted](https://github.com/usthe/sureness/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)
|
||||
[Good first pull request](https://github.com/usthe/sureness/issues?q=label%3A%22good+first+pull+request%22+)
|
||||
|
||||
## Join discussion
|
||||
|
||||
[Github Discussion](https://github.com/usthe/sureness/discussions)
|
||||
[Gitter Channel](https://gitter.im/usthe/sureness)
|
||||
|
||||
----
|
||||
----
|
||||
|
||||
参与贡献
|
||||
=======================================
|
||||
|
||||
非常欢迎参与项目贡献,我们致力于维护一个互相帮助的快乐社区。
|
||||
|
||||
仓库的组成部分:
|
||||
- [sureness的核心代码--sureness-core](https://github.com/usthe/sureness/tree/master/core)
|
||||
- [使用sureness集成springboot搭建权限项目(配置文件方案)--sample-bootstrap](https://github.com/usthe/sureness/tree/master/sample-bootstrap)
|
||||
- [使用sureness集成springboot搭建权限项目(数据库方案)--sample-tom](https://github.com/usthe/sureness/tree/master/sample-tom)
|
||||
- [各个框架使用sureness的样例项目(javalin,ktor,quarkus)--samples](https://github.com/usthe/sureness/tree/master/samples)
|
||||
|
||||
|
||||
## 如何贡献?
|
||||
|
||||
我们不仅仅接收代码的贡献提交,您也可以通过提交文档的更新或者BUG的报告来参与社区贡献。
|
||||
|
||||
如果是新的贡献者,请首先了解参考如下样例的提交Issues,提交Pull Requests如果工作。
|
||||
|
||||
[Good first issue](https://github.com/usthe/sureness/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
|
||||
[Help wanted](https://github.com/usthe/sureness/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)
|
||||
[Good first pull request](https://github.com/usthe/sureness/issues?q=label%3A%22good+first+pull+request%22+)
|
||||
|
||||
## 加入交流
|
||||
|
||||
[Github Discussion](https://github.com/usthe/sureness/discussions)
|
||||
[Gitter Channel](https://gitter.im/usthe/sureness)
|
||||
QQ交流群:390083213
|
||||
微信公众号:sureness
|
||||
@@ -10,7 +10,12 @@ sidebar_label: 常见问题
|
||||
> 如信息所示,输入的监控Host须是ipv4,ipv6或域名,不能携带协议头,例如协议头http
|
||||
|
||||
2. ** 网站API等监控反馈statusCode:403或401,但对端服务本身无需认证,浏览器直接访问是OK **
|
||||
> 请排查是否是被防火墙拦截,如宝塔等默认设置了对请求header中`User-Agent=Apache-HttpClient`的拦截,若被拦截请删除此拦截规则。(v1.0.beat5版本已将user-agent模拟成浏览器此问题不存在)
|
||||
> 请排查是否是被防火墙拦截,如宝塔等默认设置了对请求header中`User-Agent=Apache-HttpClient`的拦截,若被拦截请删除此拦截规则。(v1.0.beat5版本已将user-agent模拟成浏览器此问题不存在)
|
||||
|
||||
3. 安装包部署的hertzbeat下ping连通性监控异常
|
||||
安装包安装部署的hertzbeat,对ping连通性监控不可用,但本地直接ping是可用的。
|
||||
> 安装包部署需要配置java虚拟机root权限启动hertzbeat从而使用ICMP,若未启用root权限则是判断telnet对端7号端口是否开通
|
||||
> docker安装默认启用无此问题
|
||||
|
||||
### Docker部署常见问题
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ slug: /
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
@@ -26,7 +27,7 @@ slug: /
|
||||
|
||||
## 🎡 <font color="green">介绍</font>
|
||||
|
||||
> [HertzBeat赫兹跳动](https://github.com/dromara/hertzbeat) 是由[Dromara](https://dromara.org)孵化,[TanCloud](https://tancloud.cn)开源的一个支持网站,API,PING,端口,数据库等监控类型,拥有易用友好的可视化操作界面的开源监控告警项目。
|
||||
> [HertzBeat赫兹跳动](https://github.com/dromara/hertzbeat) 是由[Dromara](https://dromara.org)孵化,[TanCloud](https://tancloud.cn)开源的一个支持网站,API,PING,端口,数据库,操作系统等监控类型,拥有易用友好的可视化操作界面的开源监控告警项目。
|
||||
> 当然,我们也提供了对应的[SAAS云监控版本](https://console.tancloud.cn),中小团队和个人无需再为了监控自己的网站资源,而去部署一套繁琐的监控系统,[登录即可免费开始](https://console.tancloud.cn)监控之旅。
|
||||
> HertzBeat 支持自定义监控,只用通过配置YML文件我们就可以自定义需要的监控类型和指标,来满足常见的个性化需求。
|
||||
> HertzBeat 模块化,`manager, collector, scheduler, warehouse, alerter` 各个模块解耦合,方便理解与定制开发。
|
||||
|
||||
68
home/docs/others/contributing.md
Normal file
68
home/docs/others/contributing.md
Normal file
@@ -0,0 +1,68 @@
|
||||
---
|
||||
id: contributing
|
||||
title: 参与贡献
|
||||
sidebar_label: 参与贡献
|
||||
---
|
||||
|
||||
参与贡献
|
||||
=======================================
|
||||
|
||||
非常欢迎参与项目贡献,我们致力于维护一个互相帮助的快乐社区。
|
||||
|
||||
### 模块
|
||||
|
||||
- **[manager](https://github.com/dromara/hertzbeat/tree/master/manager)** 提供监控管理,系统管理基础服务
|
||||
> 提供对监控的管理,监控应用配置的管理,系统用户租户后台管理等。
|
||||
- **[collector](https://github.com/dromara/hertzbeat/tree/master/collector)** 提供监控数据采集服务
|
||||
> 使用通用协议远程采集获取对端指标数据。
|
||||
- **[scheduler](https://github.com/dromara/hertzbeat/tree/master/scheduler)** 提供监控任务调度服务
|
||||
> 采集任务管理,一次性任务和周期性任务的调度分发。
|
||||
- **[warehouse](https://github.com/dromara/hertzbeat/tree/master/warehouse)** 提供监控数据仓储服务
|
||||
> 采集指标结果数据管理,数据落盘,查询,计算统计。
|
||||
- **[alerter](https://github.com/dromara/hertzbeat/tree/master/alerter)** 提供告警服务
|
||||
> 告警计算触发,监控状态联动,告警配置,告警通知。
|
||||
- **[web-app](https://github.com/dromara/hertzbeat/tree/master/web-app)** 提供可视化控制台页面
|
||||
> 监控告警系统可视化控制台前端
|
||||
|
||||

|
||||
|
||||
## 如何贡献?
|
||||
|
||||
我们不仅仅接收代码的贡献提交,您也可以通过提交文档的更新或者BUG的报告来参与社区贡献。
|
||||
|
||||
如果是新的贡献者,请首先了解参考仓库提交Issues,提交Pull Requests如何工作。
|
||||
|
||||
https://github.com/dromara/hertzbeat/issues
|
||||
https://github.com/dromara/hertzbeat/pulls
|
||||
https://gitee.com/dromara/hertzbeat/issues
|
||||
https://gitee.com/dromara/hertzbeat/pulls
|
||||
|
||||
## 本地代码工程启动
|
||||
|
||||
此为前后端分离项目,本地代码启动需将后端 [manager](https://github.com/dromara/hertzbeat/tree/master/manager) 和前端 [web-app](https://github.com/dromara/hertzbeat/tree/master/web-app) 分别启动生效。
|
||||
|
||||
### 后端启动
|
||||
|
||||
1. 部署启动依赖服务`MYSQL`和`TDengine`数据库
|
||||
2. 需要`maven3+`和`java8+`环境
|
||||
3. 修改配置文件的依赖服务地址等信息-`manager/src/main/resources/application.yml`
|
||||
4. 启动`manager`服务 `manager/src/main/java/com/usthe/manager/Manager.java`
|
||||
|
||||
### 前端启动
|
||||
|
||||
1. 需要nodejs npm环境
|
||||
下载地址:https://nodejs.org/en/download
|
||||
2. 安装yarn `npm install -g yarn`
|
||||
3. 在前端工程目录web-app下执行 `yarn install`
|
||||
4. 全局安装angular-cli `npm install -g @angular/cli@12 --registry=https://registry.npm.taobao.org`
|
||||
5. 待本地后端启动后,在web-app目录下启动本地前端 `ng serve --open`
|
||||
6. 浏览器访问 localhost:4200 即可开始
|
||||
|
||||
## 加入交流
|
||||
|
||||
[Github Discussion](https://github.com/dromara/hertzbeat/discussions)
|
||||
加微信号 tan-cloud 拉您进微信交流群
|
||||
加QQ群号 718618151 进QQ交流群, 验证信息: tancloud
|
||||
微信公众号:tancloudtech
|
||||
[Dromara社区网站](https://dromara.org/)
|
||||
[HertzBeat用户网站](https://support.qq.com/products/379369)
|
||||
@@ -17,14 +17,18 @@ MYSQL是一款值得信赖的关系型数据库,HertzBeat使用其存储监控
|
||||
```
|
||||
2. Docker安装MYSQl
|
||||
```
|
||||
$ docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:latest
|
||||
$ docker run -d --name mysql -p 3306:3306 -v /opt/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
|
||||
526aa188da767ae94b244226a2b2eec2b5f17dd8eff594533d9ec0cd0f3a1ccd
|
||||
```
|
||||
`-v /opt/data:/var/lib/mysql` 为mysql数据目录本地持久化挂载,需将`/opt/data`替换为实际本地存在的目录
|
||||
使用```$ docker ps```查看数据库是否启动成功
|
||||
|
||||
### SQL脚本执行
|
||||
1. 进入MYSQL或使用客户端连接MYSQL服务
|
||||
2. 创建名称为hertzbeat的数据库
|
||||
1. 进入MYSQL或使用客户端连接MYSQL服务
|
||||
`mysql -uroot -p123456`
|
||||
2. 创建名称为hertzbeat的数据库
|
||||
`create database hertzbeat;`
|
||||
3. 执行位于项目仓库/script/sql/目录下的数据库建表初始化脚本 [schema.sql](https://gitee.com/dromara/hertzbeat/raw/master/script/sql/schema.sql)
|
||||
`mysql -uroot -p123456 < schema.sql`
|
||||
4. 查看hertzbeat数据库是否成功建表
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ sidebar_label: 快速开始
|
||||
|
||||
##### 安装MYSQL
|
||||
1. docker安装MYSQl
|
||||
`docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql`
|
||||
`docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7`
|
||||
2. 创建名称为hertzbeat的数据库
|
||||
3. 执行位于项目仓库/script/sql/目录下的数据库脚本 [schema.sql](https://gitee.com/dromara/hertzbeat/raw/master/script/sql/schema.sql)
|
||||
|
||||
@@ -23,7 +23,7 @@ sidebar_label: 快速开始
|
||||
|
||||
##### 安装TDengine
|
||||
1. docker安装TDengine
|
||||
`docker run -d -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp --name tdengine tdengine/tdengine`
|
||||
`docker run -d -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp --name tdengine tdengine/tdengine:2.4.0.12`
|
||||
2. 创建名称为hertzbeat的数据库
|
||||
|
||||
详细步骤参考 [依赖服务TDengine安装初始化](tdengine-init.md)
|
||||
@@ -31,16 +31,30 @@ sidebar_label: 快速开始
|
||||
### 🍞 HertzBeat安装
|
||||
> HertzBeat支持通过源码安装启动,Docker容器运行和安装包方式安装部署。
|
||||
|
||||
#### Docker方式快速安装
|
||||
#### 方式一:Docker方式快速安装
|
||||
`docker run -d -p 1157:1157 -v /opt/application.yml:/opt/hertzbeat/config/application.yml --name hertzbeat tancloud/hertzbeat:[版本tag]`
|
||||
|
||||
详细步骤参考 [通过Docker方式安装HertzBeat](docker-deploy.md)
|
||||
|
||||
#### 通过安装包安装
|
||||
#### 方式二:通过安装包安装
|
||||
1. 下载您系统环境对应的安装包 [GITEE Release](https://gitee.com/dromara/hertzbeat/releases) [GITHUB Release](https://github.com/dromara/hertzbeat/releases)
|
||||
2. 配置HertzBeat的配置文件 hertzbeat/config/application.yml
|
||||
3. 部署启动 `$ ./startup.sh `
|
||||
|
||||
详细步骤参考 [通过安装包安装HertzBeat](package-deploy.md)
|
||||
|
||||
#### 方式三:本地代码启动
|
||||
1. 此为前后端分离项目,本地代码调试需要分别启动后端工程manager和前端工程web-app
|
||||
2. 后端:需要`maven3+`和`java8+`环境,修改YML配置信息并启动manager服务
|
||||
3. 前端:需要`nodejs npm angular-cli`环境,待本地后端启动后,在web-app目录下启动 `ng serve --open`
|
||||
4. 浏览器访问 localhost:4200 即可开始
|
||||
|
||||
详细步骤参考 [参与贡献之本地代码启动](../others/contributing)
|
||||
|
||||
#### 方式四:Docker-Compose统一安装hertzbeat及其依赖服务
|
||||
|
||||
通过 [docker-compose部署脚本](https://gitee.com/dromara/hertzbeat/tree/master/script/docker-compose) 一次性把mysql数据库,tdengine数据库和hertzbeat安装部署。
|
||||
|
||||
详细步骤参考 [docker-compose安装](https://gitee.com/dromara/hertzbeat/tree/master/script/docker-compose/README.md)
|
||||
|
||||
**HAVE FUN**
|
||||
|
||||
@@ -18,9 +18,10 @@ TDengine是一款国产的开源物联网时序型数据库,我们使用其替
|
||||
```
|
||||
2. Docker安装TDengine
|
||||
```
|
||||
$ docker run -d -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp --name tdengine tdengine/tdengine
|
||||
$ docker run -d -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp -v /opt/taosdata:/var/lib/taos --name tdengine tdengine/tdengine:2.4.0.12
|
||||
526aa188da767ae94b244226a2b2eec2b5f17dd8eff594533d9ec0cd0f3a1ccd
|
||||
```
|
||||
`-v /opt/taosdata:/var/lib/taos` 为tdengine数据目录本地持久化挂载,需将`/opt/taosdata`替换为实际本地存在的目录
|
||||
使用```$ docker ps```查看数据库是否启动成功
|
||||
|
||||
### 创建数据库实例
|
||||
@@ -50,4 +51,4 @@ TDengine是一款国产的开源物联网时序型数据库,我们使用其替
|
||||
```
|
||||
|
||||
**注意⚠️若是安装包安装的TDengine2.3+版本**
|
||||
> 除了启动server外,还需执行 `systemctl start taosadapter` 启动 adapter
|
||||
> 除了启动server外,还需执行 `systemctl start taosadapter` 启动 adapter
|
||||
|
||||
@@ -32,6 +32,13 @@
|
||||
"items": [
|
||||
"advanced/extend-jdbc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "category",
|
||||
"label": "SSH协议",
|
||||
"items": [
|
||||
"advanced/extend-ssh"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -97,7 +104,8 @@
|
||||
"others/design",
|
||||
"others/sponsor",
|
||||
"others/private",
|
||||
"others/resource"
|
||||
"others/resource",
|
||||
"others/contributing"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
1
home/static/img/badge/os-monitor.svg
Normal file
1
home/static/img/badge/os-monitor.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="55" height="20" role="img" aria-label="操作系统"><title>操作系统</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="55" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="0" height="20" fill="#4c1"/><rect x="0" width="55" height="20" fill="#4c1"/><rect width="55" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="275" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="450">操作系统</text><text x="275" y="140" transform="scale(.1)" fill="#fff" textLength="450">操作系统</text></g></svg>
|
||||
|
After Width: | Height: | Size: 929 B |
@@ -38,6 +38,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
@RequestMapping(path = "/monitors", produces = {APPLICATION_JSON_VALUE})
|
||||
public class MonitorsController {
|
||||
|
||||
private static final byte ALL_MONITOR_STATUS = 9;
|
||||
|
||||
@Autowired
|
||||
private MonitorService monitorService;
|
||||
|
||||
@@ -48,6 +50,7 @@ public class MonitorsController {
|
||||
@ApiParam(value = "监控类型", example = "linux") @RequestParam(required = false) final String app,
|
||||
@ApiParam(value = "监控名称,模糊查询", example = "linux-127.0.0.1") @RequestParam(required = false) final String name,
|
||||
@ApiParam(value = "监控Host,模糊查询", example = "127.0.0.1") @RequestParam(required = false) final String host,
|
||||
@ApiParam(value = "监控状态 0:未监控,1:可用,2:不可用,3:不可达,4:挂起,9:全部状态", example = "1") @RequestParam(required = false) final Byte status,
|
||||
@ApiParam(value = "排序字段,默认id", example = "name") @RequestParam(defaultValue = "id") final String sort,
|
||||
@ApiParam(value = "排序方式,asc:升序,desc:降序", example = "desc") @RequestParam(defaultValue = "desc") final String order,
|
||||
@ApiParam(value = "列表当前分页", example = "0") @RequestParam(defaultValue = "0") int pageIndex,
|
||||
@@ -66,6 +69,10 @@ public class MonitorsController {
|
||||
Predicate predicateApp = criteriaBuilder.equal(root.get("app"), app);
|
||||
andList.add(predicateApp);
|
||||
}
|
||||
if (status != null && status >= 0 && status < ALL_MONITOR_STATUS) {
|
||||
Predicate predicateStatus = criteriaBuilder.equal(root.get("status"), status);
|
||||
andList.add(predicateStatus);
|
||||
}
|
||||
Predicate[] andPredicates = new Predicate[andList.size()];
|
||||
Predicate andPredicate = criteriaBuilder.and(andList.toArray(andPredicates));
|
||||
|
||||
@@ -79,9 +86,17 @@ public class MonitorsController {
|
||||
orList.add(predicateName);
|
||||
}
|
||||
Predicate[] orPredicates = new Predicate[orList.size()];
|
||||
Predicate orPredicate = criteriaBuilder.and(orList.toArray(orPredicates));
|
||||
Predicate orPredicate = criteriaBuilder.or(orList.toArray(orPredicates));
|
||||
|
||||
return query.where(andPredicate,orPredicate).getRestriction();
|
||||
if (andPredicate.getExpressions().isEmpty() && orPredicate.getExpressions().isEmpty()) {
|
||||
return query.where().getRestriction();
|
||||
} else if (andPredicate.getExpressions().isEmpty()) {
|
||||
return query.where(orPredicate).getRestriction();
|
||||
} else if (orPredicate.getExpressions().isEmpty()) {
|
||||
return query.where(andPredicate).getRestriction();
|
||||
} else {
|
||||
return query.where(andPredicate,orPredicate).getRestriction();
|
||||
}
|
||||
};
|
||||
// 分页是必须的
|
||||
Sort sortExp = Sort.by(new Sort.Order(Sort.Direction.fromString(order), sort));
|
||||
|
||||
@@ -16,6 +16,8 @@ configmap:
|
||||
type: 2
|
||||
- key: database
|
||||
type: 1
|
||||
- key: timeout
|
||||
type: 0
|
||||
- key: url
|
||||
type: 1
|
||||
# 指标组列表
|
||||
@@ -61,6 +63,7 @@ metrics:
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
database: ^_^database^_^
|
||||
timeout: ^_^timeout^_^
|
||||
# SQL查询方式: oneRow, multiRow, columns
|
||||
queryType: columns
|
||||
# sql
|
||||
@@ -102,6 +105,7 @@ metrics:
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
database: ^_^database^_^
|
||||
timeout: ^_^timeout^_^
|
||||
# SQL查询方式: oneRow, multiRow, columns
|
||||
queryType: columns
|
||||
# sql
|
||||
@@ -134,6 +138,7 @@ metrics:
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
database: ^_^database^_^
|
||||
timeout: ^_^timeout^_^
|
||||
# SQL查询方式: oneRow, multiRow, columns
|
||||
queryType: columns
|
||||
# sql
|
||||
|
||||
@@ -16,6 +16,8 @@ configmap:
|
||||
type: 2
|
||||
- key: database
|
||||
type: 1
|
||||
- key: timeout
|
||||
type: 0
|
||||
- key: url
|
||||
type: 1
|
||||
# 指标组列表
|
||||
@@ -61,6 +63,7 @@ metrics:
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
database: ^_^database^_^
|
||||
timeout: ^_^timeout^_^
|
||||
# SQL查询方式: oneRow, multiRow, columns
|
||||
queryType: columns
|
||||
# sql
|
||||
@@ -102,6 +105,7 @@ metrics:
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
database: ^_^database^_^
|
||||
timeout: ^_^timeout^_^
|
||||
# SQL查询方式: oneRow, multiRow, columns
|
||||
queryType: columns
|
||||
# sql
|
||||
@@ -134,6 +138,7 @@ metrics:
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
database: ^_^database^_^
|
||||
timeout: ^_^timeout^_^
|
||||
# SQL查询方式: oneRow, multiRow, columns
|
||||
queryType: columns
|
||||
# sql
|
||||
|
||||
@@ -18,6 +18,8 @@ configmap:
|
||||
type: 1
|
||||
- key: url
|
||||
type: 1
|
||||
- key: timeout
|
||||
type: 0
|
||||
# 指标组列表
|
||||
metrics:
|
||||
- name: basic
|
||||
@@ -45,6 +47,7 @@ metrics:
|
||||
host: ^_^host^_^
|
||||
# 端口
|
||||
port: ^_^port^_^
|
||||
timeout: ^_^timeout^_^
|
||||
platform: postgresql
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
@@ -87,6 +90,7 @@ metrics:
|
||||
host: ^_^host^_^
|
||||
# 端口
|
||||
port: ^_^port^_^
|
||||
timeout: ^_^timeout^_^
|
||||
platform: postgresql
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
@@ -110,6 +114,7 @@ metrics:
|
||||
host: ^_^host^_^
|
||||
# 端口
|
||||
port: ^_^port^_^
|
||||
timeout: ^_^timeout^_^
|
||||
platform: postgresql
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
|
||||
136
manager/src/main/resources/define/app/sqlserver.yml
Normal file
136
manager/src/main/resources/define/app/sqlserver.yml
Normal file
@@ -0,0 +1,136 @@
|
||||
category: db
|
||||
app: sqlserver
|
||||
name:
|
||||
zh-CN: SqlServer数据库
|
||||
en-US: SqlServer DB
|
||||
# 参数映射map. type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
|
||||
# 强制固定必须参数 - host
|
||||
configmap:
|
||||
- key: host
|
||||
type: 1
|
||||
- key: port
|
||||
type: 0
|
||||
- key: username
|
||||
type: 1
|
||||
- key: password
|
||||
type: 2
|
||||
- key: database
|
||||
type: 1
|
||||
- key: timeout
|
||||
type: 0
|
||||
- key: url
|
||||
type: 1
|
||||
# 指标组列表
|
||||
metrics:
|
||||
- name: basic
|
||||
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
|
||||
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
|
||||
priority: 0
|
||||
# 指标组中的具体监控指标
|
||||
fields:
|
||||
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
|
||||
- field: machine_name
|
||||
type: 1
|
||||
instance: true
|
||||
- field: server_name
|
||||
type: 1
|
||||
- field: version
|
||||
type: 1
|
||||
- field: edition
|
||||
type: 1
|
||||
- field: start_time
|
||||
type: 1
|
||||
protocol: jdbc
|
||||
jdbc:
|
||||
# 主机host: ipv4 ipv6 域名
|
||||
host: ^_^host^_^
|
||||
# 端口
|
||||
port: ^_^port^_^
|
||||
platform: sqlserver
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
database: ^_^database^_^
|
||||
timeout: ^_^timeout^_^
|
||||
# SQL查询方式: oneRow, multiRow, columns
|
||||
queryType: oneRow
|
||||
# sql
|
||||
sql: SELECT SERVERPROPERTY('MachineName') AS machine_name, SERVERPROPERTY('ServerName') AS server_name, SERVERPROPERTY('ProductVersion') AS version, SERVERPROPERTY('Edition') AS edition, sqlserver_start_time AS start_time FROM sys.dm_os_sys_info;
|
||||
url: ^_^url^_^
|
||||
|
||||
- name: performance_counters
|
||||
priority: 1
|
||||
fields:
|
||||
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
|
||||
- field: database_pages
|
||||
type: 0
|
||||
- field: target_pages
|
||||
type: 0
|
||||
- field: page_life_expectancy
|
||||
type: 0
|
||||
- field: buffer_cache_hit_ratio
|
||||
type: 0
|
||||
- field: checkpoint_pages_sec
|
||||
type: 0
|
||||
- field: page_reads_sec
|
||||
type: 0
|
||||
- field: page_writes_sec
|
||||
type: 0
|
||||
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
|
||||
aliasFields:
|
||||
- Database pages
|
||||
- Target pages
|
||||
- Page life expectancy
|
||||
- Buffer cache hit ratio
|
||||
- Checkpoint pages/sec
|
||||
- Page reads/sec
|
||||
- Page writes/sec
|
||||
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
|
||||
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
|
||||
calculates:
|
||||
- database_pages=Database pages
|
||||
- target_pages=Target pages
|
||||
- page_life_expectancy=Page life expectancy
|
||||
- buffer_cache_hit_ratio=Buffer cache hit ratio
|
||||
- checkpoint_pages_sec=Checkpoint pages/sec
|
||||
- page_reads_sec=Page reads/sec
|
||||
- page_writes_sec=Page writes/sec
|
||||
protocol: jdbc
|
||||
jdbc:
|
||||
# 主机host: ipv4 ipv6 域名
|
||||
host: ^_^host^_^
|
||||
# 端口
|
||||
port: ^_^port^_^
|
||||
platform: sqlserver
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
database: ^_^database^_^
|
||||
timeout: ^_^timeout^_^
|
||||
# SQL查询方式: oneRow, multiRow, columns
|
||||
queryType: columns
|
||||
# sql
|
||||
sql: select counter_name, cntr_value from sys.dm_os_performance_counters where object_name = 'SQLServer:Buffer Manager';
|
||||
url: ^_^url^_^
|
||||
|
||||
- name: connection
|
||||
priority: 1
|
||||
fields:
|
||||
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
|
||||
- field: connection
|
||||
type: 0
|
||||
unit: 连接数
|
||||
protocol: jdbc
|
||||
jdbc:
|
||||
# 主机host: ipv4 ipv6 域名
|
||||
host: ^_^host^_^
|
||||
# 端口
|
||||
port: ^_^port^_^
|
||||
platform: sqlserver
|
||||
username: ^_^username^_^
|
||||
password: ^_^password^_^
|
||||
database: ^_^database^_^
|
||||
timeout: ^_^timeout^_^
|
||||
# SQL查询方式: oneRow, multiRow, columns
|
||||
queryType: oneRow
|
||||
# sql
|
||||
sql: SELECT cntr_value as connection FROM sys.dm_os_performance_counters WHERE object_name = 'SQLServer:General Statistics' AND counter_name = 'User Connections';
|
||||
url: ^_^url^_^
|
||||
@@ -9,8 +9,14 @@ param:
|
||||
type: number
|
||||
range: '[0,65535]'
|
||||
required: true
|
||||
defaultValue: 80
|
||||
defaultValue: 3306
|
||||
placeholder: '请输入端口'
|
||||
- field: timeout
|
||||
name: 查询超时时间
|
||||
type: number
|
||||
required: false
|
||||
defaultValue: 3000
|
||||
placeholder: '查询超时时间'
|
||||
- field: database
|
||||
name: 数据库名称
|
||||
type: text
|
||||
|
||||
@@ -9,8 +9,14 @@ param:
|
||||
type: number
|
||||
range: '[0,65535]'
|
||||
required: true
|
||||
defaultValue: 80
|
||||
defaultValue: 3306
|
||||
placeholder: '请输入端口'
|
||||
- field: timeout
|
||||
name: 查询超时时间
|
||||
type: number
|
||||
required: false
|
||||
defaultValue: 3000
|
||||
placeholder: '查询超时时间'
|
||||
- field: database
|
||||
name: 数据库名称
|
||||
type: text
|
||||
|
||||
@@ -11,6 +11,12 @@ param:
|
||||
required: true
|
||||
defaultValue: 5432
|
||||
placeholder: '请输入端口'
|
||||
- field: timeout
|
||||
name: 查询超时时间
|
||||
type: number
|
||||
required: false
|
||||
defaultValue: 3000
|
||||
placeholder: '查询超时时间'
|
||||
- field: database
|
||||
name: 数据库名称
|
||||
type: text
|
||||
|
||||
36
manager/src/main/resources/define/param/sqlserver.yml
Normal file
36
manager/src/main/resources/define/param/sqlserver.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
app: sqlserver
|
||||
param:
|
||||
- field: host
|
||||
name: 主机Host
|
||||
type: host
|
||||
required: true
|
||||
- field: port
|
||||
name: 端口
|
||||
type: number
|
||||
range: '[0,65535]'
|
||||
required: true
|
||||
defaultValue: 1433
|
||||
placeholder: '请输入端口'
|
||||
- field: timeout
|
||||
name: 查询超时时间
|
||||
type: number
|
||||
required: false
|
||||
defaultValue: 3000
|
||||
placeholder: '查询超时时间'
|
||||
- field: database
|
||||
name: 数据库名称
|
||||
type: text
|
||||
required: false
|
||||
- field: username
|
||||
name: 用户名
|
||||
type: text
|
||||
limit: 20
|
||||
required: false
|
||||
- field: password
|
||||
name: 密码
|
||||
type: password
|
||||
required: false
|
||||
- field: url
|
||||
name: URL
|
||||
type: text
|
||||
required: false
|
||||
@@ -7,7 +7,7 @@ APPLICATION="${project.artifactId}"
|
||||
APPLICATION_JAR="${project.build.finalName}.jar"
|
||||
|
||||
# 通过项目名称查找到PI,然后kill -9 pid
|
||||
PID=$(ps -ef | grep "${APPLICATION_JAR}" | grep -v grep | awk '{ print $2 }')
|
||||
PID=$(ps -ef | grep java | grep "${APPLICATION_JAR}" | grep -v grep | awk '{ print $2 }')
|
||||
if [[ -z "$PID" ]]
|
||||
then
|
||||
echo ${APPLICATION} is already stopped
|
||||
|
||||
@@ -22,7 +22,7 @@ CONF_DIR=$DEPLOY_DIR/config
|
||||
# 应用的端口号
|
||||
SERVER_PORT=1157
|
||||
|
||||
PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk '{print $2}'`
|
||||
PIDS=`ps -ef | grep java | grep "$CONF_DIR" | awk '{print $2}'`
|
||||
if [ "$1" = "status" ]; then
|
||||
if [ -n "$PIDS" ]; then
|
||||
echo "The $SERVER_NAME is running...!"
|
||||
@@ -41,11 +41,21 @@ if [ -n "$PIDS" ]; then
|
||||
fi
|
||||
|
||||
if [ -n "$SERVER_PORT" ]; then
|
||||
SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`
|
||||
# linux 下查询端口是否占用
|
||||
SERVER_PORT_COUNT=`netstat -tln | grep :$SERVER_PORT | wc -l`
|
||||
if [ $SERVER_PORT_COUNT -gt 0 ]; then
|
||||
echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"
|
||||
echo "ERROR: netstat the $SERVER_NAME port $SERVER_PORT already used!"
|
||||
exit 1
|
||||
fi
|
||||
# mac 下查询端口是否占用
|
||||
LSOF_AVA=`command -v lsof | wc -l`
|
||||
if [ $LSOF_AVA -gt 0 ]; then
|
||||
SERVER_PORT_COUNT=`lsof -i:$SERVER_PORT | wc -l`
|
||||
if [ $SERVER_PORT_COUNT -gt 0 ]; then
|
||||
echo "ERROR: lsof the $SERVER_NAME port $SERVER_PORT already used!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# 项目日志输出绝对路径
|
||||
@@ -56,11 +66,10 @@ if [ ! -d $LOGS_DIR ]; then
|
||||
fi
|
||||
|
||||
# JVM Configuration
|
||||
JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "
|
||||
JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Shanghai"
|
||||
|
||||
JAVA_MEM_OPTS=" -server -Xms256m -Xmx1024m -XX:SurvivorRatio=2 -XX:+UseParallelGC "
|
||||
|
||||
|
||||
# 加载外部log文件的配置
|
||||
LOG_IMPL_FILE=logback-spring.xml
|
||||
LOGGING_CONFIG=""
|
||||
|
||||
52
script/docker-compose/README.md
Normal file
52
script/docker-compose/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
## docker-compose部署方案
|
||||
|
||||
- 如果不想部署而是直接使用,我们提供SAAS监控云-[TanCloud探云](https://console.tancloud.cn),即刻 **[登录注册](https://console.tancloud.cn)** 免费使用。
|
||||
- 如果想自己本地快速部署的话,可以参考下面进行操作。
|
||||
|
||||
##### 安装Docker & Docker-compose
|
||||
|
||||
1. 下载安装 docker 环境 & docker-compose 环境
|
||||
请参考 [Docker官网文档](https://docs.docker.com/get-docker/), [Compose安装](https://docs.docker.com/compose/install/)
|
||||
```
|
||||
$ docker -v
|
||||
Docker version 20.10.12, build e91ed57
|
||||
```
|
||||
|
||||
##### docker compose部署heartbeat及其依赖服务
|
||||
|
||||
1. 下载hertzbeat-docker-compose安装部署脚本文件
|
||||
脚本文件位于代码仓库下`script/docker-compose` 链接 [script/docker-compose](https://gitee.com/dromara/hertzbeat/tree/master/script/docker-compose)
|
||||
|
||||
|
||||
2. 进入部署脚本 docker-compose 目录, 执行
|
||||
|
||||
`docker-compose up -d`
|
||||
|
||||
3. 进入tdengine创建hertzbeat数据库
|
||||
|
||||
`$ docker exec -it tdengine /bin/bash
|
||||
root@tdengine-server:~/TDengine-server-2.4.0.4#`
|
||||
|
||||
创建名称为hertzbeat的数据库 进入容器后,执行 taos shell 客户端程序。
|
||||
|
||||
`root@tdengine-server:~/TDengine-server-2.4.0.4# taos
|
||||
Welcome to the TDengine shell from Linux, Client Version:2.4.0.4
|
||||
Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.
|
||||
taos>`
|
||||
|
||||
执行创建数据库命令
|
||||
|
||||
`taos> show databases;`
|
||||
|
||||
`taos> CREATE DATABASE hertzbeat KEEP 90 DAYS 10 BLOCKS 6 UPDATE 1;`
|
||||
|
||||
##### 重启应用
|
||||
|
||||
`docker-compose restart hertzbeat`
|
||||
|
||||
##### 开始探索HertzBeat
|
||||
浏览器访问 http://ip:1157/console 开始使用HertzBeat进行监控告警。
|
||||
|
||||
---
|
||||
|
||||
怎么样是不是很简单,只要几分钟就可以部署完成,赶紧试试吧!
|
||||
70
script/docker-compose/conf/application.yml
Normal file
70
script/docker-compose/conf/application.yml
Normal file
@@ -0,0 +1,70 @@
|
||||
server:
|
||||
port: 1157
|
||||
spring:
|
||||
application:
|
||||
name: ${HOSTNAME:@hertzbeat@}${PID}
|
||||
profiles:
|
||||
active: prod
|
||||
mvc:
|
||||
static-path-pattern: /console/**
|
||||
resources:
|
||||
static-locations:
|
||||
- classpath:/dist/
|
||||
- classpath:../dist/
|
||||
jackson:
|
||||
default-property-inclusion: NON_EMPTY
|
||||
|
||||
sureness:
|
||||
auths:
|
||||
- digest
|
||||
- basic
|
||||
- jwt
|
||||
|
||||
---
|
||||
spring:
|
||||
config:
|
||||
activate:
|
||||
on-profile: prod
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
username: root
|
||||
password: 1234
|
||||
url: jdbc:mysql://mysql:3306/hertzbeat?useUnicode=true&characterEncoding=utf-8&useSSL=false
|
||||
platform: mysql
|
||||
hikari:
|
||||
max-lifetime: 120000
|
||||
jpa:
|
||||
database: mysql
|
||||
|
||||
mail:
|
||||
# 请注意邮件服务器地址:qq邮箱为 smtp.qq.com qq企业邮箱为 smtp.exmail.qq.com
|
||||
host: smtp.qq.com
|
||||
username: example@qq.com
|
||||
# 请注意此非邮箱账户密码 此需填写邮箱授权码
|
||||
password: xxqzvuqbnqvbbdac
|
||||
port: 465
|
||||
default-encoding: UTF-8
|
||||
properties:
|
||||
mail:
|
||||
smtp:
|
||||
socketFactoryClass: javax.net.ssl.SSLSocketFactory
|
||||
ssl:
|
||||
enable: true
|
||||
|
||||
thymeleaf:
|
||||
prefix: classpath:/templates/
|
||||
check-template-location: true
|
||||
cache: true
|
||||
suffix: .html
|
||||
#encoding: UTF-8
|
||||
#content-type: text/html
|
||||
mode: LEGACYHTML5
|
||||
|
||||
warehouse:
|
||||
store:
|
||||
td-engine:
|
||||
enabled: true
|
||||
driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
|
||||
url: jdbc:TAOS-RS://tdengine:6041/hertzbeat
|
||||
username: root
|
||||
password: taosdata
|
||||
167
script/docker-compose/conf/sql/schema.sql
Normal file
167
script/docker-compose/conf/sql/schema.sql
Normal file
@@ -0,0 +1,167 @@
|
||||
set names utf8mb4;
|
||||
drop database if exists hertzbeat;
|
||||
create database hertzbeat;
|
||||
use hertzbeat;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for monitor
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS monitor ;
|
||||
CREATE TABLE monitor
|
||||
(
|
||||
id bigint not null auto_increment comment '监控ID',
|
||||
job_id bigint not null comment '监控对应下发的任务ID',
|
||||
name varchar(100) not null comment '监控的名称',
|
||||
app varchar(100) not null comment '监控的类型:linux,mysql,jvm...',
|
||||
host varchar(100) not null comment '监控的对端host:ipv4,ipv6,域名',
|
||||
intervals int not null default 600 comment '监控的采集间隔时间,单位秒',
|
||||
status tinyint not null default 1 comment '监控状态 0:未监控,1:可用,2:不可用,3:不可达',
|
||||
description varchar(255) comment '描述备注信息',
|
||||
creator varchar(100) comment '创建者',
|
||||
modifier varchar(100) comment '最新修改者',
|
||||
gmt_create timestamp default current_timestamp comment 'create time',
|
||||
gmt_update datetime default current_timestamp on update current_timestamp comment 'update time',
|
||||
primary key (id),
|
||||
index query_index (app, host, name)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for param
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS param ;
|
||||
CREATE TABLE param
|
||||
(
|
||||
id bigint not null auto_increment comment '参数ID',
|
||||
monitor_id bigint not null comment '监控ID',
|
||||
field varchar(100) not null comment '参数标识符',
|
||||
value varchar(255) comment '参数值,最大字符长度255',
|
||||
type tinyint not null default 0 comment '参数类型 0:数字 1:字符串 2:加密串',
|
||||
gmt_create timestamp default current_timestamp comment 'create time',
|
||||
gmt_update datetime default current_timestamp on update current_timestamp comment 'update time',
|
||||
primary key (id),
|
||||
index monitor_id (monitor_id),
|
||||
unique key unique_param (monitor_id, field)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for param
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS param_define ;
|
||||
CREATE TABLE param_define
|
||||
(
|
||||
id bigint not null auto_increment comment '参数ID',
|
||||
app varchar(100) not null comment '监控的类型:linux,mysql,jvm...',
|
||||
name varchar(100) not null comment '参数字段对外显示名称',
|
||||
field varchar(100) not null comment '参数字段标识符',
|
||||
type varchar(20) not null default 'text' comment '字段类型,样式(大部分映射input标签type属性)',
|
||||
required boolean not null default false comment '是否是必输项 true-必填 false-可选',
|
||||
param_range varchar(100) not null comment '当type为number时,用range表示范围 eg: 0-233',
|
||||
param_limit tinyint unsigned not null comment '当type为text时,用limit表示字符串限制大小.最大255',
|
||||
param_option varchar(255) not null comment '当type为radio单选框,checkbox复选框时,option表示可选项值列表',
|
||||
creator varchar(100) comment '创建者',
|
||||
modifier varchar(100) comment '最新修改者',
|
||||
gmt_create timestamp default current_timestamp comment 'create time',
|
||||
gmt_update datetime default current_timestamp on update current_timestamp comment 'update time',
|
||||
primary key (id),
|
||||
unique key unique_param_define (app, field)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for alert_define
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS alert_define ;
|
||||
CREATE TABLE alert_define
|
||||
(
|
||||
id bigint not null auto_increment comment '告警定义ID',
|
||||
app varchar(100) not null comment '配置告警的监控类型:linux,mysql,jvm...',
|
||||
metric varchar(100) not null comment '配置告警的指标集合:cpu,memory,info...',
|
||||
field varchar(100) not null comment '配置告警的指标:usage,cores...',
|
||||
preset boolean not null default false comment '是否是全局默认告警,是则所有此类型监控默认关联此告警',
|
||||
expr varchar(255) not null comment '告警触发条件表达式',
|
||||
priority tinyint not null default 0 comment '告警级别 0:高-emergency-紧急告警-红色 1:中-critical-严重告警-橙色 2:低-warning-警告告警-黄色',
|
||||
times int not null default 1 comment '触发次数,即达到触发阈值次数要求后才算触发告警',
|
||||
enable boolean not null default true comment '告警阈值开关',
|
||||
template varchar(255) not null comment '告警通知模板内容',
|
||||
creator varchar(100) comment '创建者',
|
||||
modifier varchar(100) comment '最新修改者',
|
||||
gmt_create timestamp default current_timestamp comment 'create time',
|
||||
gmt_update datetime default current_timestamp on update current_timestamp comment 'update time',
|
||||
primary key (id)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for alert_define_monitor_bind
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS alert_define_monitor_bind ;
|
||||
CREATE TABLE alert_define_monitor_bind
|
||||
(
|
||||
id bigint not null auto_increment comment '告警定义与监控关联ID',
|
||||
alert_define_id bigint not null comment '告警定义ID',
|
||||
monitor_id bigint not null comment '监控ID',
|
||||
gmt_create timestamp default current_timestamp comment 'create time',
|
||||
gmt_update datetime default current_timestamp on update current_timestamp comment 'update time',
|
||||
primary key (id),
|
||||
index index_bind (alert_define_id, monitor_id)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for alert
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS alert ;
|
||||
CREATE TABLE alert
|
||||
(
|
||||
id bigint not null auto_increment comment '告警ID',
|
||||
target varchar(255) not null comment '告警目标对象: 监控可用性-available 指标-app.metrics.field',
|
||||
monitor_id bigint not null comment '告警对象关联的监控ID',
|
||||
monitor_name varchar(100) comment '告警对象关联的监控名称',
|
||||
alert_define_id bigint comment '告警关联的告警定义ID',
|
||||
priority tinyint not null default 0 comment '告警级别 0:高-emergency-紧急告警-红色 1:中-critical-严重告警-橙色 2:低-warning-警告告警-黄色',
|
||||
content varchar(255) not null comment '告警通知实际内容',
|
||||
status tinyint not null default 0 comment '告警状态: 0-正常告警(待处理) 1-阈值触发但未达到告警次数 2-恢复告警 3-已处理',
|
||||
times int not null comment '触发次数,即达到告警定义的触发阈值次数要求后才会发告警',
|
||||
gmt_create timestamp default current_timestamp comment 'create time',
|
||||
primary key (id)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for notice_rule
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS notice_rule ;
|
||||
CREATE TABLE notice_rule
|
||||
(
|
||||
id bigint not null auto_increment comment '通知策略主键索引ID',
|
||||
name varchar(100) not null comment '策略名称',
|
||||
receiver_id bigint not null comment '消息接收人ID',
|
||||
receiver_name varchar(100) not null comment '消息接收人标识',
|
||||
enable boolean not null default true comment '是否启用此策略',
|
||||
filter_all boolean not null default true comment '是否转发所有',
|
||||
creator varchar(100) comment '创建者',
|
||||
modifier varchar(100) comment '最新修改者',
|
||||
gmt_create timestamp default current_timestamp comment 'create time',
|
||||
gmt_update datetime default current_timestamp on update current_timestamp comment 'update time',
|
||||
primary key (id)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for notice_receiver
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS notice_receiver ;
|
||||
CREATE TABLE notice_receiver
|
||||
(
|
||||
id bigint not null auto_increment comment '消息接收人ID',
|
||||
name varchar(100) not null comment '消息接收人姓名',
|
||||
type tinyint not null comment '通知信息方式: 0-手机短信 1-邮箱 2-webhook 3-微信公众号 4-企业微信机器人 5-钉钉机器人',
|
||||
phone varchar(100) comment '手机号, 通知方式为手机短信时有效',
|
||||
email varchar(100) comment '邮箱账号, 通知方式为邮箱时有效',
|
||||
hook_url varchar(255) comment 'URL地址, 通知方式为webhook有效',
|
||||
wechat_id varchar(255) comment 'openId, 通知方式为微信公众号或企业微信机器人有效',
|
||||
access_token varchar(255) comment '访问token, 通知方式为钉钉机器人有效',
|
||||
creator varchar(100) comment '创建者',
|
||||
modifier varchar(100) comment '最新修改者',
|
||||
gmt_create timestamp default current_timestamp comment 'create time',
|
||||
gmt_update datetime default current_timestamp on update current_timestamp comment 'update time',
|
||||
primary key (id)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
COMMIT;
|
||||
50
script/docker-compose/conf/sureness.yml
Normal file
50
script/docker-compose/conf/sureness.yml
Normal file
@@ -0,0 +1,50 @@
|
||||
## -- sureness.yml文本数据源 -- ##
|
||||
|
||||
# 加载到匹配字典的资源,也就是需要被保护的,设置了所支持角色访问的资源
|
||||
# 没有配置的资源也默认被认证保护,但不鉴权
|
||||
# eg: /api/v1/source1===get===[role2] 表示 /api/v2/host===post 这条资源支持 role2 这一种角色访问
|
||||
# eg: /api/v1/source2===get===[] 表示 /api/v1/source2===get 这条资源不支持任何角色访问
|
||||
resourceRole:
|
||||
- /account/auth/refresh===post===[role1,role2,role3,role4]
|
||||
|
||||
# 需要被过滤保护的资源,不认证鉴权直接访问
|
||||
# /api/v1/source3===get 表示 /api/v1/source3===get 可以被任何人访问 无需登录认证鉴权
|
||||
excludedResource:
|
||||
- /account/auth/**===*
|
||||
- /===get
|
||||
- /i18n/**===get
|
||||
- /apps/hierarchy===get
|
||||
# web ui 静态资源
|
||||
- /console/**===get
|
||||
- /**/*.html===get
|
||||
- /**/*.js===get
|
||||
- /**/*.css===get
|
||||
- /**/*.ico===get
|
||||
- /**/*.ttf===get
|
||||
- /**/*.png===get
|
||||
- /**/*.gif===get
|
||||
- /**/*.png===*
|
||||
# swagger ui 资源
|
||||
- /swagger-resources/**===get
|
||||
- /v2/api-docs===get
|
||||
- /v3/api-docs===get
|
||||
|
||||
# 用户账户信息
|
||||
# 下面有 admin tom lili 三个账户
|
||||
# eg: admin 拥有[role1,role2]角色,密码为admin
|
||||
# eg: tom 拥有[role1,role2,role3],密码为tom@123
|
||||
# eg: lili 拥有[role1,role2],明文密码为lili, 加盐密码为1A676730B0C7F54654B0E09184448289
|
||||
account:
|
||||
- appId: admin
|
||||
credential: admin@123.
|
||||
role: [role1,role2]
|
||||
- appId: tom
|
||||
credential: tom@123.
|
||||
role: [role1,role2,role3]
|
||||
- appId: lili
|
||||
# 注意 Digest认证不支持加盐加密的密码账户
|
||||
# 加盐加密的密码,通过 MD5(password+salt)计算
|
||||
# 此账户的原始密码为 lili
|
||||
credential: 1A676730B0C7F54654B0E09194448289
|
||||
salt: 123
|
||||
role: [role1,role2]
|
||||
2
script/docker-compose/dbdata/mysqldata/.gitignore
vendored
Normal file
2
script/docker-compose/dbdata/mysqldata/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.gitignore
|
||||
!.gitignore
|
||||
2
script/docker-compose/dbdata/taosdata/.gitignore
vendored
Normal file
2
script/docker-compose/dbdata/taosdata/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.gitignore
|
||||
!.gitignore
|
||||
50
script/docker-compose/docker-compose.yaml
Normal file
50
script/docker-compose/docker-compose.yaml
Normal file
@@ -0,0 +1,50 @@
|
||||
version: "3.7"
|
||||
|
||||
networks:
|
||||
heartzbeat:
|
||||
driver: bridge
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: "mysql:5.7"
|
||||
container_name: mysql
|
||||
hostname: mysql
|
||||
restart: always
|
||||
ports:
|
||||
- "3306:3306"
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
MYSQL_ROOT_PASSWORD: 1234
|
||||
volumes:
|
||||
- ./dbdata/mysqldata:/var/lib/mysql/
|
||||
- ./conf/sql:/docker-entrypoint-initdb.d/
|
||||
networks:
|
||||
- heartzbeat
|
||||
|
||||
TDengine:
|
||||
image: "tdengine/tdengine:2.4.0.12"
|
||||
container_name: tdengine
|
||||
hostname: tdengine
|
||||
restart: always
|
||||
ports:
|
||||
- "6030-6049:6030-6049"
|
||||
- "6030-6049:6030-6049/udp"
|
||||
volumes:
|
||||
- ./dbdata/taosdata:/var/lib/taos/
|
||||
networks:
|
||||
- heartzbeat
|
||||
|
||||
hertzbeat:
|
||||
image: "tancloud/hertzbeat:1.0-beta.5"
|
||||
container_name: hertzbeat
|
||||
hostname: hertzbeat
|
||||
restart: always
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
volumes:
|
||||
- ./conf/application.yml:/opt/hertzbeat/config/application.yml
|
||||
- ./conf/sureness.yml:/opt/hertzbeat/config/sureness.yml
|
||||
ports:
|
||||
- "1157:1157"
|
||||
networks:
|
||||
- heartzbeat
|
||||
@@ -4,6 +4,10 @@ MAINTAINER tomsun28 "tomsun28@outlook.com"
|
||||
|
||||
ADD hertzbeat-1.0-beta.5.tar /opt/
|
||||
|
||||
RUN apk add --no-cache tzdata
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
EXPOSE 1157
|
||||
|
||||
WORKDIR /opt/hertzbeat/
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
set names utf8mb4;
|
||||
drop database if exists hertzbeat;
|
||||
create database hertzbeat;
|
||||
use hertzbeat;
|
||||
|
||||
-- ----------------------------
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* influxdb存储采集数据
|
||||
@@ -39,6 +40,7 @@ public class TdEngineDataStorage implements DisposableBean {
|
||||
private HikariDataSource hikariDataSource;
|
||||
private WarehouseWorkerPool workerPool;
|
||||
private MetricsDataExporter dataExporter;
|
||||
private static final Pattern SQL_SPECIAL_STRING_PATTERN = Pattern.compile("(\\\\)|(')");
|
||||
private static final String INSERT_TABLE_DATA_SQL = "INSERT INTO %s USING %s TAGS (%s) VALUES %s";
|
||||
private static final String CREATE_SUPER_TABLE_SQL = "CREATE STABLE IF NOT EXISTS %s %s TAGS (monitor BIGINT)";
|
||||
private static final String NO_SUPER_TABLE_ERROR = "Table does not exist";
|
||||
@@ -200,8 +202,9 @@ public class TdEngineDataStorage implements DisposableBean {
|
||||
}
|
||||
|
||||
private String formatStringValue(String value){
|
||||
return value.replaceAll("(\\\\)|(')","\\\\$0");
|
||||
return SQL_SPECIAL_STRING_PATTERN.matcher(value).replaceAll("\\\\$0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
if (hikariDataSource != null) {
|
||||
|
||||
@@ -90,13 +90,17 @@ export class HeaderSearchComponent implements AfterViewInit, OnDestroy {
|
||||
)
|
||||
.subscribe(value => {
|
||||
// 远程加载搜索数据
|
||||
let searchMonitors$ = this.monitorSvc.searchMonitors(value, value, 0, 10).subscribe(
|
||||
let searchMonitors$ = this.monitorSvc.searchMonitors(null, value, 9, 0, 10).subscribe(
|
||||
message => {
|
||||
this.loading = false;
|
||||
searchMonitors$.unsubscribe();
|
||||
if (message.code === 0) {
|
||||
let page = message.data;
|
||||
this.options = page.content;
|
||||
if (page.content != undefined) {
|
||||
this.options = page.content;
|
||||
} else {
|
||||
this.options = [];
|
||||
}
|
||||
this.cdr.detectChanges();
|
||||
} else {
|
||||
console.warn(message.msg);
|
||||
@@ -118,7 +122,7 @@ export class HeaderSearchComponent implements AfterViewInit, OnDestroy {
|
||||
qBlur(): void {
|
||||
this.focus = false;
|
||||
this.searchToggled = false;
|
||||
this.options.length = 0;
|
||||
this.options = [];
|
||||
this.toggleChangeChange.emit(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
type="text"
|
||||
placeholder="搜索告警内容"
|
||||
nzSize="default"
|
||||
(keyup.enter)="onFilterSearchAlerts()"
|
||||
[(ngModel)]="filterContent"
|
||||
/>
|
||||
<nz-select
|
||||
@@ -116,7 +117,7 @@
|
||||
<td nzAlign="center">
|
||||
{{ data.status === 0 ? '未处理' : '已处理' }}
|
||||
</td>
|
||||
<td nzAlign="center">{{ data.gmtCreate }}</td>
|
||||
<td nzAlign="center">{{ data.gmtCreate | date: 'YYYY-MM-dd HH:mm:ss' }}</td>
|
||||
<td nzAlign="center">
|
||||
<button nz-button nzType="primary" (click)="onDeleteOneAlert(data.id)" nz-tooltip nzTooltipTitle="删除告警">
|
||||
<i nz-icon nzType="delete" nzTheme="outline"></i>
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
<span *ngIf="data.type == 5">{{ data.accessToken }}</span>
|
||||
<span *ngIf="data.type == 6">{{ data.wechatId }}</span>
|
||||
</td>
|
||||
<td nzAlign="center">{{ data.gmtUpdate ? data.gmtUpdate : data.gmtCreate }}</td>
|
||||
<td nzAlign="center">{{ (data.gmtUpdate ? data.gmtUpdate : data.gmtCreate) | date: 'YYYY-MM-dd HH:mm:ss' }}</td>
|
||||
<td nzAlign="center">
|
||||
<button nz-button nzType="primary" (click)="onEditOneNoticeReceiver(data)" nz-tooltip nzTooltipTitle="修改接收人">
|
||||
<i nz-icon nzType="edit" nzTheme="outline"></i>
|
||||
@@ -148,7 +148,7 @@
|
||||
<span>关闭</span>
|
||||
</nz-tag>
|
||||
</td>
|
||||
<td nzAlign="center">{{ data.gmtUpdate ? data.gmtUpdate : data.gmtCreate }}</td>
|
||||
<td nzAlign="center">{{ (data.gmtUpdate ? data.gmtUpdate : data.gmtCreate) | date: 'YYYY-MM-dd HH:mm:ss' }}</td>
|
||||
<td nzAlign="center">
|
||||
<button nz-button nzType="primary" (click)="onEditOneNoticeRule(data)" nz-tooltip nzTooltipTitle="修改告警策略">
|
||||
<i nz-icon nzType="edit" nzTheme="outline"></i>
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
<span>否</span>
|
||||
</nz-tag>
|
||||
</td>
|
||||
<td nzAlign="center">{{ data.gmtUpdate ? data.gmtUpdate : data.gmtCreate }}</td>
|
||||
<td nzAlign="center">{{ (data.gmtUpdate ? data.gmtUpdate : data.gmtCreate) | date: 'YYYY-MM-dd HH:mm:ss' }}</td>
|
||||
<td nzAlign="center">
|
||||
<button nz-button nzType="primary" (click)="onOpenConnectModal(data.id, data.app)" nz-tooltip nzTooltipTitle="配置关联监控">
|
||||
<i nz-icon nzType="link" nzTheme="outline"></i>
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
<div nz-col nzXs="24" nzSm="24" nzMd="12" class="mb-md">
|
||||
<nz-card nzHoverable nzTitle="最近告警列表" [nzExtra]="extraTemplate">
|
||||
<nz-timeline nzMode="left">
|
||||
<nz-timeline-item *ngFor="let alert of alerts; let i = index" [nzLabel]="alert.gmtCreate.toString()">
|
||||
<nz-timeline-item *ngFor="let alert of alerts; let i = index" [nzLabel]="(alert.gmtCreate | date: 'YYYY-MM-dd HH:mm:ss')?.trim()">
|
||||
<p style="font-weight: 400">
|
||||
<nz-tag *ngIf="alert.priority == 0" nzColor="red">
|
||||
<i nz-icon nzType="bell" nzTheme="outline"></i>
|
||||
|
||||
@@ -90,13 +90,13 @@
|
||||
<div nz-row nzGutter="16">
|
||||
<div nz-col nzSpan="8"><p style="text-align: right">创建时间</p></div>
|
||||
<div nz-col nzSpan="16"
|
||||
><p style="text-align: left">{{ monitor?.gmtCreate }}</p></div
|
||||
><p style="text-align: left">{{ monitor?.gmtCreate | date: 'YYYY-MM-dd HH:mm:ss' }}</p></div
|
||||
>
|
||||
</div>
|
||||
<div nz-row nzGutter="16">
|
||||
<div nz-col nzSpan="8"><p style="text-align: right">最近更新时间</p></div>
|
||||
<div nz-col nzSpan="16"
|
||||
><p style="text-align: left">{{ monitor?.gmtUpdate }}</p></div
|
||||
><p style="text-align: left">{{ monitor?.gmtUpdate | date: 'YYYY-MM-dd HH:mm:ss' }}</p></div
|
||||
>
|
||||
</div>
|
||||
</nz-card>
|
||||
|
||||
@@ -12,31 +12,57 @@
|
||||
</nz-breadcrumb-item>
|
||||
</nz-breadcrumb>
|
||||
<nz-divider></nz-divider>
|
||||
<button nz-button nzType="primary">
|
||||
<a routerLink="/monitors/new" [queryParams]="{ app: app }">
|
||||
<i nz-icon nzType="appstore-add" nzTheme="outline"></i>
|
||||
新增 {{ 'monitor.app.' + app | i18n }}
|
||||
</a>
|
||||
</button>
|
||||
<button nz-button nzType="primary" (click)="onEditMonitor()">
|
||||
<i nz-icon nzType="edit" nzTheme="outline"></i>
|
||||
编辑
|
||||
</button>
|
||||
<button nz-button nzType="primary" (click)="onDeleteMonitors()">
|
||||
<i nz-icon nzType="delete" nzTheme="outline"></i>
|
||||
删除
|
||||
</button>
|
||||
<button nz-button nzType="primary" (click)="onEnableManageMonitors()">
|
||||
<i nz-icon nzType="up-circle" nzTheme="outline"></i>
|
||||
启用监控
|
||||
</button>
|
||||
<button nz-button nzType="primary" (click)="onCancelManageMonitors()">
|
||||
<i nz-icon nzType="down-circle" nzTheme="outline"></i>
|
||||
取消监控
|
||||
</button>
|
||||
<button nz-button nzType="primary" (click)="sync()" nz-tooltip nzTooltipTitle="刷新">
|
||||
<i nz-icon nzType="sync" nzTheme="outline"></i>
|
||||
</button>
|
||||
|
||||
<div>
|
||||
<button nz-button nzType="primary">
|
||||
<a routerLink="/monitors/new" [queryParams]="{ app: app }">
|
||||
<i nz-icon nzType="appstore-add" nzTheme="outline"></i>
|
||||
新增 {{ 'monitor.app.' + app | i18n }}
|
||||
</a>
|
||||
</button>
|
||||
<button nz-button nzType="primary" (click)="onEditMonitor()">
|
||||
<i nz-icon nzType="edit" nzTheme="outline"></i>
|
||||
编辑
|
||||
</button>
|
||||
<button nz-button nzType="primary" (click)="onDeleteMonitors()">
|
||||
<i nz-icon nzType="delete" nzTheme="outline"></i>
|
||||
删除
|
||||
</button>
|
||||
<button nz-button nzType="primary" (click)="onEnableManageMonitors()">
|
||||
<i nz-icon nzType="up-circle" nzTheme="outline"></i>
|
||||
启用监控
|
||||
</button>
|
||||
<button nz-button nzType="primary" (click)="onCancelManageMonitors()">
|
||||
<i nz-icon nzType="down-circle" nzTheme="outline"></i>
|
||||
取消监控
|
||||
</button>
|
||||
<button nz-button nzType="primary" (click)="sync()" nz-tooltip nzTooltipTitle="刷新">
|
||||
<i nz-icon nzType="sync" nzTheme="outline"></i>
|
||||
</button>
|
||||
|
||||
<button style="margin-right: 25px; float: right" nz-button nzType="primary" (click)="onFilterSearchMonitors()"> 搜索 </button>
|
||||
<input
|
||||
style="margin-right: 5px; float: right; width: 150px; border-radius: 9px; text-align: center"
|
||||
nz-input
|
||||
type="text"
|
||||
placeholder="搜索监控"
|
||||
nzSize="default"
|
||||
(keyup.enter)="onFilterSearchMonitors()"
|
||||
[(ngModel)]="filterContent"
|
||||
/>
|
||||
<nz-select
|
||||
style="margin-right: 10px; float: right; width: 120px"
|
||||
nzAllowClear
|
||||
[nzPlaceHolder]="'监控状态过滤'"
|
||||
[(ngModel)]="filterStatus"
|
||||
>
|
||||
<nz-option nzLabel="全部状态" nzValue="9"></nz-option>
|
||||
<nz-option nzLabel="监控正常" nzValue="1"></nz-option>
|
||||
<nz-option nzLabel="不可用" nzValue="2"></nz-option>
|
||||
<nz-option nzLabel="不可达" nzValue="3"></nz-option>
|
||||
<nz-option nzLabel="未监控" nzValue="0"></nz-option>
|
||||
</nz-select>
|
||||
</div>
|
||||
|
||||
<nz-table
|
||||
#fixedTable
|
||||
@@ -101,7 +127,7 @@
|
||||
<span>{{ 'monitor.app.' + data.app | i18n }}</span>
|
||||
</nz-tag>
|
||||
</td>
|
||||
<td nzAlign="center">{{ data.gmtUpdate ? data.gmtUpdate : data.gmtCreate }}</td>
|
||||
<td nzAlign="center">{{ (data.gmtUpdate ? data.gmtUpdate : data.gmtCreate) | date: 'YYYY-MM-dd HH:mm:ss' }}</td>
|
||||
<td nzAlign="center">
|
||||
<button nz-button nzType="primary" (click)="onEditOneMonitor(data.id)" nz-tooltip nzTooltipTitle="修改监控">
|
||||
<i nz-icon nzType="edit" nzTheme="outline"></i>
|
||||
|
||||
@@ -30,6 +30,9 @@ export class MonitorListComponent implements OnInit {
|
||||
monitors!: Monitor[];
|
||||
tableLoading: boolean = true;
|
||||
checkedMonitorIds = new Set<number>();
|
||||
// 过滤搜索
|
||||
filterContent!: string;
|
||||
filterStatus: number = 9;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.queryParamMap.subscribe(paramMap => {
|
||||
@@ -42,6 +45,33 @@ export class MonitorListComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
onFilterSearchMonitors() {
|
||||
this.tableLoading = true;
|
||||
let filter$ = this.monitorSvc
|
||||
.searchMonitors(this.app, this.filterContent, this.filterStatus, this.pageIndex - 1, this.pageSize)
|
||||
.subscribe(
|
||||
message => {
|
||||
filter$.unsubscribe();
|
||||
this.tableLoading = false;
|
||||
this.checkedAll = false;
|
||||
this.checkedMonitorIds.clear();
|
||||
if (message.code === 0) {
|
||||
let page = message.data;
|
||||
this.monitors = page.content;
|
||||
this.pageIndex = page.number + 1;
|
||||
this.total = page.totalElements;
|
||||
} else {
|
||||
console.warn(message.msg);
|
||||
}
|
||||
},
|
||||
error => {
|
||||
this.tableLoading = false;
|
||||
filter$.unsubscribe();
|
||||
console.error(error.msg);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
sync() {
|
||||
this.loadMonitorTable();
|
||||
}
|
||||
|
||||
@@ -88,17 +88,31 @@ export class MonitorService {
|
||||
return this.http.get<Message<Page<Monitor>>>(monitors_uri, options);
|
||||
}
|
||||
|
||||
public searchMonitors(monitorName: string, monitorHost: string, pageIndex: number, pageSize: number): Observable<Message<Page<Monitor>>> {
|
||||
public searchMonitors(
|
||||
app: string | null,
|
||||
searchValue: string,
|
||||
status: number,
|
||||
pageIndex: number,
|
||||
pageSize: number
|
||||
): Observable<Message<Page<Monitor>>> {
|
||||
pageIndex = pageIndex ? pageIndex : 0;
|
||||
pageSize = pageSize ? pageSize : 8;
|
||||
// 注意HttpParams是不可变对象 需要保存set后返回的对象为最新对象
|
||||
let httpParams = new HttpParams();
|
||||
httpParams = httpParams.appendAll({
|
||||
name: monitorName,
|
||||
host: monitorHost,
|
||||
pageIndex: pageIndex,
|
||||
pageSize: pageSize
|
||||
});
|
||||
if (status != undefined && status != 9) {
|
||||
httpParams = httpParams.append('status', status);
|
||||
}
|
||||
if (app != undefined) {
|
||||
httpParams = httpParams.append('app', app);
|
||||
}
|
||||
if (searchValue != undefined && searchValue != '' && searchValue.trim() != '') {
|
||||
httpParams = httpParams.append('name', searchValue);
|
||||
httpParams = httpParams.append('host', searchValue);
|
||||
}
|
||||
const options = { params: httpParams };
|
||||
return this.http.get<Message<Page<Monitor>>>(monitors_uri, options);
|
||||
}
|
||||
|
||||
8
web-app/src/app/shared/pipe/timezone.pipe.spec.ts
Normal file
8
web-app/src/app/shared/pipe/timezone.pipe.spec.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { TimezonePipe } from './timezone.pipe';
|
||||
|
||||
describe('TimezonePipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new TimezonePipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
||||
20
web-app/src/app/shared/pipe/timezone.pipe.ts
Normal file
20
web-app/src/app/shared/pipe/timezone.pipe.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { formatDate, Location } from '@angular/common';
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'timezone'
|
||||
})
|
||||
export class TimezonePipe implements PipeTransform {
|
||||
timeZone: string = 'Asia/Shanghai';
|
||||
|
||||
constructor() {
|
||||
this.timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
if (this.timeZone == undefined) {
|
||||
this.timeZone = 'Asia/Shanghai';
|
||||
}
|
||||
}
|
||||
|
||||
transform(value: any): string {
|
||||
return formatDate(value, 'YYYY-MM-DD HH:mm:ss', 'zh-cn');
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { DelonACLModule } from '@delon/acl';
|
||||
import { DelonFormModule } from '@delon/form';
|
||||
import { AlainThemeModule } from '@delon/theme';
|
||||
|
||||
import { TimezonePipe } from './pipe/timezone.pipe';
|
||||
import { SHARED_DELON_MODULES } from './shared-delon.module';
|
||||
import { SHARED_ZORRO_MODULES } from './shared-zorro.module';
|
||||
|
||||
@@ -18,7 +19,7 @@ const THIRDMODULES: Array<Type<void>> = [];
|
||||
// #region your components & directives
|
||||
|
||||
const COMPONENTS: Array<Type<void>> = [];
|
||||
const DIRECTIVES: Array<Type<void>> = [];
|
||||
const DIRECTIVES: Array<Type<void>> = [TimezonePipe];
|
||||
|
||||
// #endregion
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* 转化成RMB元字符串
|
||||
*
|
||||
* @param value 值
|
||||
* @param digits 当数字类型时,允许指定小数点后数字的个数,默认2位小数
|
||||
*/
|
||||
export function yuan(value: number | string, digits: number = 2): string {
|
||||
|
||||
Reference in New Issue
Block a user