Skip to content

Commit

Permalink
[improve] update monitor state desc (apache#2028)
Browse files Browse the repository at this point in the history
Signed-off-by: tomsun28 <[email protected]>
  • Loading branch information
tomsun28 authored May 23, 2024
1 parent 8115e39 commit a78f71d
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public CalculateAlarm(AlerterWorkerPool workerPool, CommonDataQueue dataQueue,
this.triggeredAlertMap = new ConcurrentHashMap<>(16);
this.notRecoveredAlertMap = new ConcurrentHashMap<>(16);
// Initialize stateAlertMap
List<Monitor> monitors = monitorDao.findMonitorsByStatus(CommonConstants.UN_AVAILABLE_CODE);
List<Monitor> monitors = monitorDao.findMonitorsByStatus(CommonConstants.MONITOR_DOWN_CODE);
if (monitors != null) {
for (Monitor monitor : monitors) {
HashMap<String, String> tags = new HashMap<>(8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,21 @@ public interface CommonConstants {
* Response status code: Incorrect login account password
*/
byte MONITOR_LOGIN_FAILED_CODE = 0x05;

/**
* Response status code: Registration failed exception
*/
byte MONITOR_REGISTER_FAILED_CODE = 0x06;



/**
* Monitoring Status Code: Unmonitored
* Monitoring status 0: Paused, 1: Up, 2: Down
*/
byte UN_MANAGE_CODE = 0x00;
byte MONITOR_PAUSED_CODE = 0x00;

/**
* Monitoring Status Code: Available
* Monitoring status 0: Paused, 1: Up, 2: Down
*/
byte AVAILABLE_CODE = 0x01;
byte MONITOR_UP_CODE = 0x01;

/**
* Monitoring Status Code: Not Available
* Monitoring status 0: Paused, 1: Up, 2: Down
*/
byte UN_AVAILABLE_CODE = 0x02;
byte MONITOR_DOWN_CODE = 0x02;

/**
* Alarm status: 0 - normal alarm (to be processed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,13 @@ public class Monitor {

/**
* Type of monitoring: linux, mysql, jvm...
* 监控的类型:linux,mysql,jvm...
*/
@Schema(title = "Type of monitoring", example = "TanCloud", accessMode = READ_WRITE)
@Size(max = 100)
private String app;

/**
* Monitored peer host: ipv4, ipv6, domain name
* 监控的对端host:ipv4,ipv6,域名
*/
@Schema(title = "The host to monitor", example = "192.167.25.11", accessMode = READ_WRITE)
@Size(max = 100)
Expand All @@ -104,24 +102,21 @@ public class Monitor {

/**
* Monitoring collection interval time, in seconds
* 监控的采集间隔时间,单位秒
*/
@Schema(title = "Monitoring of the acquisition interval time in seconds", example = "600", accessMode = READ_WRITE)
@Min(10)
private Integer intervals;

/**
* Monitoring status 0: Unmonitored, 1: Available, 2: Unavailable
* 任务状态 0:未监控,1:可用,2:不可用
* Monitoring status 0: Paused, 1: Up, 2: Down
*/
@Schema(title = "Task status 0: not monitored,1: available,2: unavailable", accessMode = READ_WRITE)
@Schema(title = "Task status 0: Paused, 1: Up, 2: Down", accessMode = READ_WRITE)
@Min(0)
@Max(4)
private byte status;

/**
* Monitoring note description
* 监控备注描述
*/
@Schema(title = "Monitor note description", example = "Availability monitoring of the SAAS website TanCloud", accessMode = READ_WRITE)
@Size(max = 255)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ public void store(Alert alert) {
if (!tags.containsKey(CommonConstants.TAG_MONITOR_HOST)) {
tags.put(CommonConstants.TAG_MONITOR_HOST, monitor.getHost());
}
if (monitor.getStatus() == CommonConstants.UN_MANAGE_CODE) {
if (monitor.getStatus() == CommonConstants.MONITOR_PAUSED_CODE) {
// When monitoring is not monitored, ignore and silence its alarm messages
return;
}
if (CommonConstants.AVAILABILITY.equals(alert.getTarget())) {
if (alert.getStatus() == CommonConstants.ALERT_STATUS_CODE_PENDING && monitor.getStatus() == CommonConstants.AVAILABLE_CODE) {
if (alert.getStatus() == CommonConstants.ALERT_STATUS_CODE_PENDING && monitor.getStatus() == CommonConstants.MONITOR_UP_CODE) {
// Availability Alarm Need to change the monitoring status to unavailable
monitorService.updateMonitorStatus(monitor.getId(), CommonConstants.UN_AVAILABLE_CODE);
} else if (alert.getStatus() == CommonConstants.ALERT_STATUS_CODE_RESTORED && monitor.getStatus() == CommonConstants.UN_AVAILABLE_CODE) {
monitorService.updateMonitorStatus(monitor.getId(), CommonConstants.MONITOR_DOWN_CODE);
} else if (alert.getStatus() == CommonConstants.ALERT_STATUS_CODE_RESTORED && monitor.getStatus() == CommonConstants.MONITOR_DOWN_CODE) {
// If the alarm is restored, the monitoring state needs to be restored
monitorService.updateMonitorStatus(monitorId, CommonConstants.AVAILABLE_CODE);
monitorService.updateMonitorStatus(monitorId, CommonConstants.MONITOR_UP_CODE);
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ private void startCalculate() {
List<Monitor> monitorList = monitorDao.findAll(specification);
state = CommonConstants.STATUS_PAGE_COMPONENT_STATE_UNKNOWN;
for (Monitor monitor : monitorList) {
if (monitor.getStatus() == CommonConstants.UN_AVAILABLE_CODE) {
if (monitor.getStatus() == CommonConstants.MONITOR_DOWN_CODE) {
state = CommonConstants.STATUS_PAGE_COMPONENT_STATE_ABNORMAL;
break;
} else if (monitor.getStatus() == CommonConstants.AVAILABLE_CODE) {
} else if (monitor.getStatus() == CommonConstants.MONITOR_UP_CODE) {
state = CommonConstants.STATUS_PAGE_COMPONENT_STATE_NORMAL;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void collectorGoOnline(String identity, CollectorInfo collectorInfo) {
continue;
}
Monitor monitor = monitorOptional.get();
if (monitor.getStatus() == CommonConstants.UN_MANAGE_CODE) {
if (monitor.getStatus() == CommonConstants.MONITOR_PAUSED_CODE) {
continue;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void addMonitor(Monitor monitor, List<Param> params, String collector) th
}
monitor.setId(monitorId);
monitor.setJobId(jobId);
monitor.setStatus(CommonConstants.AVAILABLE_CODE);
monitor.setStatus(CommonConstants.MONITOR_UP_CODE);
monitorDao.save(monitor);
paramDao.saveAll(params);
} catch (Exception e) {
Expand Down Expand Up @@ -258,7 +258,7 @@ public void addNewMonitorOptionalMetrics(List<String> metrics, Monitor monitor,
try {
monitor.setId(monitorId);
monitor.setJobId(jobId);
monitor.setStatus(CommonConstants.AVAILABLE_CODE);
monitor.setStatus(CommonConstants.MONITOR_UP_CODE);
monitorDao.save(monitor);
paramDao.saveAll(params);
} catch (Exception e) {
Expand Down Expand Up @@ -514,7 +514,7 @@ public void modifyMonitor(Monitor monitor, List<Param> params, String collector)
tag.setTagValue(monitor.getName());
}
}
if (preMonitor.getStatus() != CommonConstants.UN_MANAGE_CODE) {
if (preMonitor.getStatus() != CommonConstants.MONITOR_PAUSED_CODE) {
// Construct the collection task Job entity
Job appDefine = appService.getAppDefine(monitor.getApp());
if (CommonConstants.PROMETHEUS.equals(monitor.getApp())) {
Expand Down Expand Up @@ -640,8 +640,8 @@ public void cancelManageMonitors(HashSet<Long> ids) {
// The jobId is not deleted, and the jobId is reused again after the management is started.
List<Monitor> managedMonitors = monitorDao.findMonitorsByIdIn(ids)
.stream().filter(monitor ->
monitor.getStatus() != CommonConstants.UN_MANAGE_CODE)
.peek(monitor -> monitor.setStatus(CommonConstants.UN_MANAGE_CODE))
monitor.getStatus() != CommonConstants.MONITOR_PAUSED_CODE)
.peek(monitor -> monitor.setStatus(CommonConstants.MONITOR_PAUSED_CODE))
.collect(Collectors.toList());
if (!managedMonitors.isEmpty()) {
for (Monitor monitor : managedMonitors) {
Expand All @@ -656,8 +656,8 @@ public void enableManageMonitors(HashSet<Long> ids) {
// Update monitoring status Add corresponding monitoring periodic task
List<Monitor> unManagedMonitors = monitorDao.findMonitorsByIdIn(ids)
.stream().filter(monitor ->
monitor.getStatus() == CommonConstants.UN_MANAGE_CODE)
.peek(monitor -> monitor.setStatus(CommonConstants.AVAILABLE_CODE))
monitor.getStatus() == CommonConstants.MONITOR_PAUSED_CODE)
.peek(monitor -> monitor.setStatus(CommonConstants.MONITOR_UP_CODE))
.collect(Collectors.toList());
if (!unManagedMonitors.isEmpty()) {
for (Monitor monitor : unManagedMonitors) {
Expand Down Expand Up @@ -708,9 +708,9 @@ public List<AppCount> getAllAppMonitorsCount() {
AppCount appCount = appCountMap.getOrDefault(item.getApp(), new AppCount());
appCount.setApp(item.getApp());
switch (item.getStatus()) {
case CommonConstants.AVAILABLE_CODE -> appCount.setAvailableSize(appCount.getAvailableSize() + item.getSize());
case CommonConstants.UN_AVAILABLE_CODE -> appCount.setUnAvailableSize(appCount.getUnAvailableSize() + item.getSize());
case CommonConstants.UN_MANAGE_CODE -> appCount.setUnManageSize(appCount.getUnManageSize() + item.getSize());
case CommonConstants.MONITOR_UP_CODE -> appCount.setAvailableSize(appCount.getAvailableSize() + item.getSize());
case CommonConstants.MONITOR_DOWN_CODE -> appCount.setUnAvailableSize(appCount.getUnAvailableSize() + item.getSize());
case CommonConstants.MONITOR_PAUSED_CODE -> appCount.setUnManageSize(appCount.getUnManageSize() + item.getSize());
default -> {}
}
appCountMap.put(item.getApp(), appCount);
Expand Down Expand Up @@ -750,7 +750,7 @@ public void copyMonitors(List<Long> ids) {
@Override
public void updateAppCollectJob(Job job) {
List<Monitor> monitors = monitorDao.findMonitorsByAppEquals(job.getApp())
.stream().filter(monitor -> monitor.getStatus() != CommonConstants.UN_MANAGE_CODE)
.stream().filter(monitor -> monitor.getStatus() != CommonConstants.MONITOR_PAUSED_CODE)
.toList();
if (monitors.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ void enableManageMonitors() {
List<Monitor> monitors = new ArrayList<>();
for (Long id : ids) {
Monitor monitor = Monitor.builder().jobId(id).intervals(1).app("app").name("memory").host("host").id(id).build();
monitor.setStatus(CommonConstants.UN_MANAGE_CODE);
monitor.setStatus(CommonConstants.MONITOR_PAUSED_CODE);
monitors.add(monitor);
}
when(monitorDao.findMonitorsByIdIn(ids)).thenReturn(monitors);
Expand All @@ -700,7 +700,7 @@ void getAllAppMonitorsCount() {
List<AppCount> appCounts = new ArrayList<>();
AppCount appCount = new AppCount();
appCount.setApp("test");
appCount.setStatus(CommonConstants.AVAILABLE_CODE);
appCount.setStatus(CommonConstants.MONITOR_UP_CODE);
appCounts.add(appCount);
when(monitorDao.findAppsStatusCount()).thenReturn(appCounts);

Expand All @@ -721,7 +721,7 @@ void getMonitor() {

@Test
void updateMonitorStatus() {
assertDoesNotThrow(() -> monitorService.updateMonitorStatus(1L, CommonConstants.AVAILABLE_CODE));
assertDoesNotThrow(() -> monitorService.updateMonitorStatus(1L, CommonConstants.MONITOR_UP_CODE));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/app/pojo/Monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Monitor {
app!: string;
host!: string;
intervals: number = 60;
// 任务状态 0:未监控,1:可用,2:不可用
// Monitoring status 0: Paused, 1: Up, 2: Down
status!: number;
description!: string;
creator!: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@
</nz-form-label>
<nz-form-control [nzSpan]="10">
<span style="color: red">
<nz-tag nzColor="error">{{ 'monitor.status.unavailable' | i18n }}</nz-tag>
<nz-tag nzColor="error">{{ 'monitor.status.down' | i18n }}</nz-tag>
<nz-tag nzColor="error">{{ 'monitor.status.unreachable' | i18n }}</nz-tag>
{{ 'alert.setting.trigger' | i18n }}
</span>
Expand Down
Loading

0 comments on commit a78f71d

Please sign in to comment.