Skip to content

Commit

Permalink
config default system timezone and fix monitor status auto recover (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Aug 18, 2023
1 parent 0ff1f93 commit e9a19e3
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ HertzBeat is a top project under the [Dromara Open Source Community](https://dro

##### Friends

- [Sa-Token](https://github.com/dromara/Sa-Token) : 一个轻量级 java 权限认证框架,让鉴权变得简单、优雅
- [DynamicTp](https://github.com/dromara/dynamic-tp) : 轻量级动态线程池,内置监控告警功能,集成三方中间件线程池管理,基于主流配置中心
- [Hippo4j](https://github.com/opengoofy/hippo4j/) : 强大的动态线程池框架,附带监控报警功能
- [Jpom](https://gitee.com/dromara/Jpom) : 简而轻的低侵入式在线构建、自动部署、日常运维、项目监控软件
Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ HertzBeat 赫兹跳动是 [Dromara开源社区](https://dromara.org/) 下顶级

##### 友情链接

- [Sa-Token](https://gitee.com/dromara/sa-token) : 一个轻量级 java 权限认证框架,让鉴权变得简单、优雅
- [DynamicTp](https://github.com/dromara/dynamic-tp) : 轻量级动态线程池,内置监控告警功能,集成三方中间件线程池管理,基于主流配置中心
- [Hippo4j](https://github.com/opengoofy/hippo4j/) : 强大的动态线程池框架,附带监控报警功能
- [Jpom](https://gitee.com/dromara/Jpom) : 简而轻的低侵入式在线构建、自动部署、日常运维、项目监控软件
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ private void handleRecoveredAlert(long currentTimeMilli, long monitorId, String
if (notResolvedAlert != null) {
// Sending an alarm Restore
Map<String, String> tags = notResolvedAlert.getTags();
tags.put(CommonConstants.TAG_ALARM_TYPE, "recover");
String content = this.bundle.getString("alerter.alarm.recover") + " : " + expr;
Alert resumeAlert = Alert.builder()
.tags(tags)
Expand Down Expand Up @@ -361,7 +362,7 @@ private void handlerAvailableMetrics(long monitorId, String app, CollectRep.Metr
preAlert.setStatus(CommonConstants.ALERT_STATUS_CODE_NOT_REACH);
}
}
} else if (avaAlertDefine.isRecoverNotice()) {
} else {
// Check whether an availability or unreachable alarm is generated before the association monitoring
// and send a clear alarm to clear the monitoring status
// 判断关联监控之前是否有可用性或者不可达告警,发送恢复告警进行监控状态恢复
Expand All @@ -372,6 +373,10 @@ private void handlerAvailableMetrics(long monitorId, String app, CollectRep.Metr
Map<String, String> tags = new HashMap<>(6);
tags.put(CommonConstants.TAG_MONITOR_ID, String.valueOf(monitorId));
tags.put(CommonConstants.TAG_MONITOR_APP, app);
tags.put(CommonConstants.TAG_ALARM_TYPE, "recover");
if (!avaAlertDefine.isRecoverNotice()) {
tags.put(CommonConstants.IGNORE, CommonConstants.IGNORE);
}
if (notResolvedAlert.getTags() != null) {
tags.putAll(notResolvedAlert.getTags());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public AlarmConvergeReduce(AlertConvergeDao alertConvergeDao) {
*/
@SuppressWarnings("unchecked")
public boolean filterConverge(Alert currentAlert) {
// ignore ALERT_STATUS_CODE_RESTORED
if (currentAlert.getStatus() == CommonConstants.ALERT_STATUS_CODE_RESTORED) {
// ignore monitor status auto recover notice
if (currentAlert.getTags() != null && currentAlert.getTags().containsKey(CommonConstants.IGNORE)) {
return true;
}
ICacheService<String, Object> convergeCache = CacheFactory.getAlertConvergeCache();
Expand Down
10 changes: 10 additions & 0 deletions collector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@
</activation>
<build>
<finalName>hertzbeat-collector</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>META-INF/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -210,6 +219,7 @@
<includes>
<include>*.yml</include>
<include>*.properties</include>
<include>*.xml</include>
<include>banner.txt</include>
<include>META-INF/**</include>
</includes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ public interface CommonConstants {
* 内有标签: app 监控类型
*/
String TAG_MONITOR_APP = "app";

/**
* 内有标签: alarm type
*/
String TAG_ALARM_TYPE = "type";

/**
* notice_period type 类型字段, 每日类型
Expand Down Expand Up @@ -296,4 +301,9 @@ public interface CommonConstants {
* locale spilt
*/
String LOCALE_SEPARATOR = "_";

/**
* ignore label
*/
String IGNORE = "ignore";
}
4 changes: 4 additions & 0 deletions home/docs/start/docker-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ sidebar_label: Install via Docker

```shell
$ docker run -d -p 1157:1157 -p 1158:1158 \
-e LANG=en_US.UTF-8 \
-e TZ=Asia/Shanghai \
-v $(pwd)/data:/opt/hertzbeat/data \
-v $(pwd)/logs:/opt/hertzbeat/logs \
-v $(pwd)/application.yml:/opt/hertzbeat/config/application.yml \
Expand All @@ -58,6 +60,8 @@ $ docker run -d -p 1157:1157 -p 1158:1158 \
This command starts a running HertzBeat Docker container with mapping port 1157-1158. If existing processes on the host use the port, please modify host mapped port.
- `docker run -d` : Run a container in the background via Docker
- `-p 1157:1157 -p 1158:1158` : Mapping container ports to the host, 1157 is web-ui port, 1158 is cluster port.
- `-e LANG=en_US.UTF-8` : Set the system language
- `-e TZ=Asia/Shanghai` : Set the system timezone
- `-v $(pwd)/data:/opt/hertzbeat/data` : (optional, data persistence) Important⚠️ Mount the H2 database file to the local host, to ensure that the data is not lost due creating or deleting container.
- `-v $(pwd)/logs:/opt/hertzbeat/logs` : (optional, if you don't have a need, just delete it) Mount the log file to the local host, to ensure the log will not be lost due creating or deleting container.
- `-v $(pwd)/application.yml:/opt/hertzbeat/config/application.yml` : (optional, if you don't have a need, just delete it) Mount the local configuration file into the container which has been modified in the previous step, namely using the local configuration file to cover container configuration file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ sidebar_label: Docker方式部署

```shell
$ docker run -d -p 1157:1157 -p 1158:1158 \
-e LANG=zh_CN.UTF-8 \
-e TZ=Asia/Shanghai \
-v $(pwd)/data:/opt/hertzbeat/data \
-v $(pwd)/logs:/opt/hertzbeat/logs \
-v $(pwd)/application.yml:/opt/hertzbeat/config/application.yml \
Expand All @@ -76,15 +78,12 @@ $ docker run -d -p 1157:1157 -p 1158:1158 \

这条命令启动一个运行HertzBeat的Docker容器,并且将容器的1157端口映射到宿主机的1157端口上。若宿主机已有进程占用该端口,则需要修改主机映射端口。
- `docker run -d` : 通过Docker运行一个容器,使其在后台运行

- `-e LANG=zh_CN.UTF-8` : 设置系统语言
- `-e TZ=Asia/Shanghai` : 设置系统时区
- `-p 1157:1157 -p 1158:1158` : 映射容器端口到主机端口,请注意,前面是宿主机的端口号,后面是容器的端口号。1157是WEB端口,1158是集群端口。

- `-v $(pwd)/data:/opt/hertzbeat/data` : (可选,数据持久化)重要⚠️ 挂载H2数据库文件到本地主机,保证数据不会因为容器的创建删除而丢失

- `-v $(pwd)/logs:/opt/hertzbeat/logs` : (可选,不需要可删除)挂载日志文件到本地主机,保证日志不会因为容器的创建删除而丢失,方便查看

- `-v $(pwd)/data:/opt/hertzbeat/data` : (可选,数据持久化)重要⚠️ 挂载H2数据库文件到本地主机,保证数据不会因为容器的创建删除而丢失
- `-v $(pwd)/logs:/opt/hertzbeat/logs` : (可选,不需要可删除)挂载日志文件到本地主机,保证日志不会因为容器的创建删除而丢失,方便查看
- `-v $(pwd)/application.yml:/opt/hertzbeat/config/application.yml` : (可选,不需要可删除)挂载上上一步修改的本地配置文件到容器中,即使用本地配置文件覆盖容器配置文件。我们需要修改此配置文件的MYSQL,TDengine配置信息来连接外部服务。

- `-v $(pwd)/sureness.yml:/opt/hertzbeat/config/sureness.yml` : (可选,不需要可删除)挂载上一步修改的账户配置文件到容器中,若无修改账户需求可删除此命令参数。

- 注意⚠️ 挂载文件时,前面参数为你自定义本地文件地址,后面参数为docker容器内文件地址(固定)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.dromara.hertzbeat.manager.service.NoticeConfigService;
import org.dromara.hertzbeat.manager.support.exception.AlertNoticeException;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hertzbeat.manager.support.exception.IgnoreException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -108,8 +109,11 @@ public void run() {
// 通知分发
sendNotify(alert);
}
} catch (IgnoreException ignored) {
} catch (InterruptedException e) {
log.error(e.getMessage());
} catch (Exception exception) {
log.error(exception.getMessage(), exception);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.dromara.hertzbeat.manager.service.MonitorService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hertzbeat.manager.support.exception.IgnoreException;
import org.springframework.stereotype.Component;

import java.util.Map;
Expand All @@ -47,7 +48,7 @@ final class DbAlertStoreHandlerImpl implements AlertStoreHandler {
@Override
public void store(Alert alert) {
Map<String, String> tags = alert.getTags();
String monitorIdStr = tags.get(CommonConstants.TAG_MONITOR_ID);
String monitorIdStr = tags != null ? tags.get(CommonConstants.TAG_MONITOR_ID) : null;
if (monitorIdStr != null) {
long monitorId = Long.parseLong(monitorIdStr);
Monitor monitor = monitorService.getMonitor(monitorId);
Expand All @@ -74,6 +75,9 @@ public void store(Alert alert) {
} else {
log.debug("store extern alert content: {}.", alert);
}
if (tags != null && tags.containsKey(CommonConstants.IGNORE)) {
throw new IgnoreException("Ignore this alarm.");
}
// Alarm store db
alertService.addAlert(alert);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void run(String... args) throws Exception {
.preset(true)
.times(1)
.enable(true)
.recoverNotice(true)
.recoverNotice(false)
.priority(CommonConstants.ALERT_PRIORITY_CODE_EMERGENCY)
.template("${app} monitoring availability alert, code is ${code}")
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* 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.
*/

package org.dromara.hertzbeat.manager.support.exception;

/**
* normal ignore
* @author tom
*
*/
public class IgnoreException extends RuntimeException {
public IgnoreException(String message) {
super(message);
}
}
4 changes: 2 additions & 2 deletions script/docker/collector/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ MAINTAINER tancloud "tomsun28@outlook.com"

ADD hertzbeat-collector-${VERSION}.tar /opt/

#ENV TZ=Asia/Shanghai
#ENV LANG=zh_CN.UTF-8
ENV TZ=Asia/Shanghai
ENV LANG=en_US.UTF-8

WORKDIR /opt/hertzbeat-collector/

Expand Down
4 changes: 2 additions & 2 deletions script/docker/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ RUN mkdir /var/run/sshd

ADD hertzbeat-${VERSION}.tar /opt/

#ENV TZ=Asia/Shanghai
#ENV LANG=zh_CN.UTF-8
ENV TZ=Asia/Shanghai
ENV LANG=en_US.UTF-8

EXPOSE 1157 1158 22

Expand Down
4 changes: 2 additions & 2 deletions web-app/src/app/pojo/NoticeRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class NoticeRule {
priorities!: number[];
tags!: TagItem[];
days!: number[];
periodStart: Date = new Date(2000, 2, 2, 0, 0, 0);
periodEnd: Date = new Date(2000, 2, 2, 23, 59, 59);
periodStart!: Date;
periodEnd!: Date;
creator!: string;
modifier!: string;
gmtCreate!: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class AlertNoticeComponent implements OnInit {
isManageRuleModalVisible: boolean = false;
isManageRuleModalAdd: boolean = true;
isManageRuleModalOkLoading: boolean = false;
rule: NoticeRule = new NoticeRule();
rule!: NoticeRule;
receiversOption: any[] = [];
searchTag!: string;
tagsOption: any[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
name="target"
id="target"
[nzShowSearch]="true"
[nzPlaceHolder]="'alert.setting.target.place-holder' | i18n"
[nzOptions]="appHierarchies"
[(ngModel)]="cascadeValues"
(ngModelChange)="cascadeOnChange($event)"
Expand Down
3 changes: 2 additions & 1 deletion web-app/src/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@
"alert.setting.edit": "Edit Threshold",
"alert.setting.delete": "Delete Threshold",
"alert.setting.target": "Metric Target",
"alert.setting.target.place-holder": "Please search or select metrics target",
"alert.setting.expr": "Threshold Trigger Expr",
"alert.setting.trigger": "Trigger Threshold Alerts",
"alert.setting.trigger": "Trigger alarms and update monitor status",
"alert.setting.rule": "Threshold Rule",
"alert.setting.number": "Numeric",
"alert.setting.string": "String",
Expand Down
3 changes: 2 additions & 1 deletion web-app/src/assets/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@
"alert.setting.edit": "编辑阈值",
"alert.setting.delete": "删除阈值",
"alert.setting.target": "指标对象",
"alert.setting.target.place-holder": "请搜索或选择指标对象",
"alert.setting.expr": "阈值触发表达式",
"alert.setting.trigger": "异常时触发告警",
"alert.setting.trigger": "异常时触发告警,变更监控可用性状态",
"alert.setting.rule": "阈值规则",
"alert.setting.number": "数值型",
"alert.setting.string": "字符型",
Expand Down
3 changes: 2 additions & 1 deletion web-app/src/assets/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@
"alert.setting.edit": "編輯阈值",
"alert.setting.delete": "刪除阈值",
"alert.setting.target": "指標對象",
"alert.setting.target.place-holder": "請搜索或選擇指標對象",
"alert.setting.expr": "阈值觸發表達式",
"alert.setting.trigger": "異常時觸發告警",
"alert.setting.trigger": "異常時觸發告警,變更監控可用性狀態",
"alert.setting.rule": "閾值規則",
"alert.setting.number": "數值型",
"alert.setting.string": "字符型",
Expand Down

0 comments on commit e9a19e3

Please sign in to comment.