Ver código fonte

20230804-添加监控model

iaun 3 anos atrás
pai
commit
27c4dddad9

+ 9 - 0
src/main/java/cn/iaun/it/controller/ItMonitorController.java

@@ -0,0 +1,9 @@
+package cn.iaun.it.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/monitor")
+public class ItMonitorController {
+}

+ 54 - 0
src/main/java/cn/iaun/it/model/ItMonitorAgent.java

@@ -0,0 +1,54 @@
+package cn.iaun.it.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+public class ItMonitorAgent {
+    @TableId(type = IdType.AUTO)
+    private Long agentId;
+    private String agentName;
+    private String agentIP;
+    private Long agentKeyId;
+
+    @Override
+    public String toString() {
+        return "ItMonitorAgent{" +
+                "agentId=" + agentId +
+                ", agentName='" + agentName + '\'' +
+                ", agentIP='" + agentIP + '\'' +
+                ", agentKeyId=" + agentKeyId +
+                '}';
+    }
+
+    public Long getAgentId() {
+        return agentId;
+    }
+
+    public void setAgentId(Long agentId) {
+        this.agentId = agentId;
+    }
+
+    public String getAgentName() {
+        return agentName;
+    }
+
+    public void setAgentName(String agentName) {
+        this.agentName = agentName;
+    }
+
+    public String getAgentIP() {
+        return agentIP;
+    }
+
+    public void setAgentIP(String agentIP) {
+        this.agentIP = agentIP;
+    }
+
+    public Long getAgentKeyId() {
+        return agentKeyId;
+    }
+
+    public void setAgentKeyId(Long agentKeyId) {
+        this.agentKeyId = agentKeyId;
+    }
+}

+ 34 - 0
src/main/java/cn/iaun/it/model/ItMonitorAgentKey.java

@@ -0,0 +1,34 @@
+package cn.iaun.it.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+public class ItMonitorAgentKey {
+    @TableId(type = IdType.AUTO)
+    private Long agentKeyId;
+    private String key;
+
+    @Override
+    public String toString() {
+        return "ItMonitorAgentKey{" +
+                "agentKeyId=" + agentKeyId +
+                ", key='" + key + '\'' +
+                '}';
+    }
+
+    public Long getAgentKeyId() {
+        return agentKeyId;
+    }
+
+    public void setAgentKeyId(Long agentKeyId) {
+        this.agentKeyId = agentKeyId;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+}

+ 96 - 0
src/main/java/cn/iaun/it/model/ItMonitorAlarm.java

@@ -0,0 +1,96 @@
+package cn.iaun.it.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+import java.util.Date;
+
+public class ItMonitorAlarm {
+    @TableId(type = IdType.AUTO)
+    private Long alarmId;
+    private Long itemId;
+    private Long resourceId;
+    private String alarmTxt;
+    private Integer alarmType;
+    private Integer alarmStatus;
+    private Date firstAlarmTime;
+    private Integer alarmTimes; // 连续警告次数
+
+    @Override
+    public String toString() {
+        return "ItMonitorAlarm{" +
+                "alarmId=" + alarmId +
+                ", itemId=" + itemId +
+                ", resourceId=" + resourceId +
+                ", alarmTxt='" + alarmTxt + '\'' +
+                ", alarmType=" + alarmType +
+                ", alarmStatus=" + alarmStatus +
+                ", firstAlarmTime=" + firstAlarmTime +
+                ", alarmTimes=" + alarmTimes +
+                '}';
+    }
+
+    public Long getAlarmId() {
+        return alarmId;
+    }
+
+    public void setAlarmId(Long alarmId) {
+        this.alarmId = alarmId;
+    }
+
+    public Long getItemId() {
+        return itemId;
+    }
+
+    public void setItemId(Long itemId) {
+        this.itemId = itemId;
+    }
+
+    public Long getResourceId() {
+        return resourceId;
+    }
+
+    public void setResourceId(Long resourceId) {
+        this.resourceId = resourceId;
+    }
+
+    public String getAlarmTxt() {
+        return alarmTxt;
+    }
+
+    public void setAlarmTxt(String alarmTxt) {
+        this.alarmTxt = alarmTxt;
+    }
+
+    public Integer getAlarmType() {
+        return alarmType;
+    }
+
+    public void setAlarmType(Integer alarmType) {
+        this.alarmType = alarmType;
+    }
+
+    public Integer getAlarmStatus() {
+        return alarmStatus;
+    }
+
+    public void setAlarmStatus(Integer alarmStatus) {
+        this.alarmStatus = alarmStatus;
+    }
+
+    public Date getFirstAlarmTime() {
+        return firstAlarmTime;
+    }
+
+    public void setFirstAlarmTime(Date firstAlarmTime) {
+        this.firstAlarmTime = firstAlarmTime;
+    }
+
+    public Integer getAlarmTimes() {
+        return alarmTimes;
+    }
+
+    public void setAlarmTimes(Integer alarmTimes) {
+        this.alarmTimes = alarmTimes;
+    }
+}

+ 52 - 0
src/main/java/cn/iaun/it/model/ItMonitorData.java

@@ -0,0 +1,52 @@
+package cn.iaun.it.model;
+
+import java.util.Date;
+
+public class ItMonitorData {
+    private Long resourceId;
+    private Long itemId;
+    private Date recordTime;
+    private String data;
+
+    @Override
+    public String toString() {
+        return "ItMonitorData{" +
+                "resourceId=" + resourceId +
+                ", itemId=" + itemId +
+                ", recordTime=" + recordTime +
+                ", data='" + data + '\'' +
+                '}';
+    }
+
+    public Long getResourceId() {
+        return resourceId;
+    }
+
+    public void setResourceId(Long resourceId) {
+        this.resourceId = resourceId;
+    }
+
+    public Long getItemId() {
+        return itemId;
+    }
+
+    public void setItemId(Long itemId) {
+        this.itemId = itemId;
+    }
+
+    public Date getRecordTime() {
+        return recordTime;
+    }
+
+    public void setRecordTime(Date recordTime) {
+        this.recordTime = recordTime;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public void setData(String data) {
+        this.data = data;
+    }
+}

+ 64 - 0
src/main/java/cn/iaun/it/model/ItMonitorItem.java

@@ -0,0 +1,64 @@
+package cn.iaun.it.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+public class ItMonitorItem {
+    @TableId(type = IdType.AUTO)
+    private Long itemId;
+    private String itemName;
+    private String itemKeyName;
+    private Long itemGroupId;
+    private Integer itemType;
+
+    @Override
+    public String toString() {
+        return "ItMonitorItem{" +
+                "itemId=" + itemId +
+                ", itemName='" + itemName + '\'' +
+                ", itemKeyName='" + itemKeyName + '\'' +
+                ", itemGroupId=" + itemGroupId +
+                ", itemType=" + itemType +
+                '}';
+    }
+
+    public Long getItemId() {
+        return itemId;
+    }
+
+    public void setItemId(Long itemId) {
+        this.itemId = itemId;
+    }
+
+    public String getItemName() {
+        return itemName;
+    }
+
+    public void setItemName(String itemName) {
+        this.itemName = itemName;
+    }
+
+    public String getItemKeyName() {
+        return itemKeyName;
+    }
+
+    public void setItemKeyName(String itemKeyName) {
+        this.itemKeyName = itemKeyName;
+    }
+
+    public Long getItemGroupId() {
+        return itemGroupId;
+    }
+
+    public void setItemGroupId(Long itemGroupId) {
+        this.itemGroupId = itemGroupId;
+    }
+
+    public Integer getItemType() {
+        return itemType;
+    }
+
+    public void setItemType(Integer itemType) {
+        this.itemType = itemType;
+    }
+}

+ 64 - 0
src/main/java/cn/iaun/it/model/ItMonitorItemGroup.java

@@ -0,0 +1,64 @@
+package cn.iaun.it.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+public class ItMonitorItemGroup {
+    @TableId(type = IdType.AUTO)
+    private Long groupId;
+    private String groupName;
+    private Long templateId;
+    private Integer interval;
+    private Long topItemId;
+
+    @Override
+    public String toString() {
+        return "ItMonitorItemGroup{" +
+                "groupId=" + groupId +
+                ", groupName='" + groupName + '\'' +
+                ", templateId=" + templateId +
+                ", interval=" + interval +
+                ", topItemId=" + topItemId +
+                '}';
+    }
+
+    public Long getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(Long groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getGroupName() {
+        return groupName;
+    }
+
+    public void setGroupName(String groupName) {
+        this.groupName = groupName;
+    }
+
+    public Long getTemplateId() {
+        return templateId;
+    }
+
+    public void setTemplateId(Long templateId) {
+        this.templateId = templateId;
+    }
+
+    public Integer getInterval() {
+        return interval;
+    }
+
+    public void setInterval(Integer interval) {
+        this.interval = interval;
+    }
+
+    public Long getTopItemId() {
+        return topItemId;
+    }
+
+    public void setTopItemId(Long topItemId) {
+        this.topItemId = topItemId;
+    }
+}

+ 64 - 0
src/main/java/cn/iaun/it/model/ItMonitorResource.java

@@ -0,0 +1,64 @@
+package cn.iaun.it.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+public class ItMonitorResource {
+    @TableId(type = IdType.AUTO)
+    private Long resourceId;
+    private Long templateId;
+    private Long agentId;
+    private Long resourceGroupId;
+    private String resourceName;
+
+    @Override
+    public String toString() {
+        return "ItMonitorResource{" +
+                "resourceId=" + resourceId +
+                ", templateId=" + templateId +
+                ", agentId=" + agentId +
+                ", resourceGroupId=" + resourceGroupId +
+                ", resourceName='" + resourceName + '\'' +
+                '}';
+    }
+
+    public Long getResourceId() {
+        return resourceId;
+    }
+
+    public void setResourceId(Long resourceId) {
+        this.resourceId = resourceId;
+    }
+
+    public Long getTemplateId() {
+        return templateId;
+    }
+
+    public void setTemplateId(Long templateId) {
+        this.templateId = templateId;
+    }
+
+    public Long getAgentId() {
+        return agentId;
+    }
+
+    public void setAgentId(Long agentId) {
+        this.agentId = agentId;
+    }
+
+    public Long getResourceGroupId() {
+        return resourceGroupId;
+    }
+
+    public void setResourceGroupId(Long resourceGroupId) {
+        this.resourceGroupId = resourceGroupId;
+    }
+
+    public String getResourceName() {
+        return resourceName;
+    }
+
+    public void setResourceName(String resourceName) {
+        this.resourceName = resourceName;
+    }
+}

+ 34 - 0
src/main/java/cn/iaun/it/model/ItMonitorResourceGroup.java

@@ -0,0 +1,34 @@
+package cn.iaun.it.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+public class ItMonitorResourceGroup {
+    @TableId(type = IdType.AUTO)
+    private Long groupId;
+    private String groupName;
+
+    @Override
+    public String toString() {
+        return "ItMonitorResourceGroup{" +
+                "groupId=" + groupId +
+                ", groupName='" + groupName + '\'' +
+                '}';
+    }
+
+    public Long getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(Long groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getGroupName() {
+        return groupName;
+    }
+
+    public void setGroupName(String groupName) {
+        this.groupName = groupName;
+    }
+}

+ 34 - 0
src/main/java/cn/iaun/it/model/ItMonitorTemplate.java

@@ -0,0 +1,34 @@
+package cn.iaun.it.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+public class ItMonitorTemplate {
+    @TableId(type = IdType.AUTO)
+    private Long templateId;
+    private String templateName;
+
+    @Override
+    public String toString() {
+        return "ItMonitorTemplate{" +
+                "templateId=" + templateId +
+                ", templateName='" + templateName + '\'' +
+                '}';
+    }
+
+    public Long getTemplateId() {
+        return templateId;
+    }
+
+    public void setTemplateId(Long templateId) {
+        this.templateId = templateId;
+    }
+
+    public String getTemplateName() {
+        return templateName;
+    }
+
+    public void setTemplateName(String templateName) {
+        this.templateName = templateName;
+    }
+}

+ 70 - 0
src/main/java/cn/iaun/it/model/ItMonitorThreshold.java

@@ -0,0 +1,70 @@
+package cn.iaun.it.model;
+
+public class ItMonitorThreshold {
+    private Long itemId;
+    private Long resourceId;
+    private Integer alarmType;
+    private Integer thresholdType;
+    private String threshold;
+    private Integer times;
+
+    @Override
+    public String toString() {
+        return "ItMonitorThreshold{" +
+                "itemId=" + itemId +
+                ", resourceId=" + resourceId +
+                ", alarmType=" + alarmType +
+                ", thresholdType=" + thresholdType +
+                ", threshold='" + threshold + '\'' +
+                ", times=" + times +
+                '}';
+    }
+
+    public Long getItemId() {
+        return itemId;
+    }
+
+    public void setItemId(Long itemId) {
+        this.itemId = itemId;
+    }
+
+    public Long getResourceId() {
+        return resourceId;
+    }
+
+    public void setResourceId(Long resourceId) {
+        this.resourceId = resourceId;
+    }
+
+    public Integer getAlarmType() {
+        return alarmType;
+    }
+
+    public void setAlarmType(Integer alarmType) {
+        this.alarmType = alarmType;
+    }
+
+    public Integer getThresholdType() {
+        return thresholdType;
+    }
+
+    public void setThresholdType(Integer thresholdType) {
+        this.thresholdType = thresholdType;
+    }
+
+    public String getThreshold() {
+        return threshold;
+    }
+
+    public void setThreshold(String threshold) {
+        this.threshold = threshold;
+    }
+
+    public Integer getTimes() {
+        return times;
+    }
+
+    public void setTimes(Integer times) {
+        this.times = times;
+    }
+}

+ 4 - 0
src/main/java/cn/iaun/it/service/ItMonitorService.java

@@ -0,0 +1,4 @@
+package cn.iaun.it.service;
+
+public interface ItMonitorService {
+}

+ 1 - 0
src/main/resources/application.yml

@@ -18,6 +18,7 @@ spring:
     password: hello6379
   jackson:
     time-zone: GMT+8
+    date-format: yyyy-MM-dd HH:mm:ss
 
 logging:
   level:

+ 115 - 1
src/main/resources/db/schema.sql

@@ -85,4 +85,118 @@ create table `it_resource_value`
     `attribute_id`    bigint(20) not null comment '属性ID',
     `attribute_value` text       not null comment '资源属性的值',
     primary key (`resource_id`, `attribute_id`)
-) comment ='资源属性的值';
+) comment ='资源属性的值';
+
+drop TABLE if exists it_monitor_agent;
+CREATE TABLE `it_monitor_agent`
+(
+    `agent_id`     BIGINT(20)   NOT NULL AUTO_INCREMENT,
+    `agent_name`   VARCHAR(255) NOT NULL DEFAULT '',
+    `agent_ip`     VARCHAR(255) NOT NULL DEFAULT '',
+    `agent_key_id` BIGINT(20)   NOT NULL,
+    PRIMARY KEY (`agent_id`)
+) COMMENT ='agent'
+;
+
+drop TABLE if exists it_monitor_agent_key;
+CREATE TABLE `it_monitor_agent_key`
+(
+    `agent_key_id` BIGINT(20)   NOT NULL AUTO_INCREMENT,
+    `key`          VARCHAR(255) NOT NULL,
+    PRIMARY KEY (`agent_key_id`)
+) COMMENT ='Agent 认证'
+;
+
+drop TABLE if exists it_monitor_alarm;
+CREATE TABLE `it_monitor_alarm`
+(
+    `alarm_id`         BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '告警ID',
+    `item_id`          BIGINT(20) NOT NULL COMMENT '指标ID',
+    `resource_id`      BIGINT(20) NOT NULL COMMENT '资源ID',
+    `alarm_txt`        TEXT       NOT NULL COMMENT '告警内容',
+    `alarm_type`       INT(11)    NOT NULL COMMENT '告警级别',
+    `alarm_status`     INT(11)    NOT NULL DEFAULT '0' COMMENT '告警状态:0未处理;1已恢复;2已处理',
+    `first_alarm_time` TIMESTAMP  NOT NULL COMMENT '初次告警时间',
+    `alarm_times`      INT(11)    NOT NULL DEFAULT '0' COMMENT '连续告警次数',
+    PRIMARY KEY (`alarm_id`)
+) COMMENT ='监控-告警'
+;
+
+drop TABLE if exists it_monitor_data;
+CREATE TABLE `it_monitor_data`
+(
+    `resource_id` BIGINT(20) NOT NULL,
+    `item_id`     BIGINT(20) NOT NULL,
+    `record_time` TIMESTAMP  NOT NULL,
+    `data`        TEXT       NOT NULL,
+    PRIMARY KEY (`resource_id`, `item_id`)
+) COMMENT ='监控-数据'
+;
+
+drop TABLE if exists it_monitor_item;
+CREATE TABLE `it_monitor_item`
+(
+    `item_id`       BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '指标ID',
+    `item_name`     VARCHAR(255) NOT NULL COMMENT '指标名称',
+    `item_key_name` VARCHAR(255) NOT NULL COMMENT '指标key',
+    `item_group_id` BIGINT(20)   NOT NULL COMMENT '指标组ID',
+    `item_type`     INT(11)      NOT NULL COMMENT '指标类型:0文本,1纯数字,2百分比,3大小(除文本外都是数字大类,前端进行细分)',
+    PRIMARY KEY (`item_id`),
+    UNIQUE INDEX `item_key_name` (`item_key_name`)
+) COMMENT ='监控指标'
+;
+
+drop TABLE if exists it_monitor_item_group;
+CREATE TABLE `it_monitor_item_group`
+(
+    `group_id`    BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '组ID',
+    `group_name`  VARCHAR(255) NOT NULL COMMENT '组名',
+    `template_id` BIGINT(20)   NOT NULL COMMENT '所属模板ID',
+    `interval`    INT(11)      NOT NULL COMMENT '间隔',
+    `top_item_id` BIGINT(20)   NOT NULL DEFAULT '-1' COMMENT '置顶指标',
+    PRIMARY KEY (`group_id`)
+) COMMENT ='监控指标组'
+;
+
+drop TABLE if exists it_monitor_resource;
+CREATE TABLE `it_monitor_resource`
+(
+    `resource_id`       BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '资源ID',
+    `template_id`       BIGINT(20)   NOT NULL COMMENT '模板ID',
+    `agent_id`          BIGINT(20)   NOT NULL COMMENT 'Agent ID',
+    `resource_group_id` BIGINT(20)   NOT NULL COMMENT '资源组ID',
+    `resource_name`     VARCHAR(255) NOT NULL COMMENT '资源名称',
+    PRIMARY KEY (`resource_id`)
+) COMMENT ='监控-资源表'
+;
+
+drop TABLE if exists it_monitor_resource_group;
+CREATE TABLE `it_monitor_resource_group`
+(
+    `group_id`   BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '组ID',
+    `group_name` VARCHAR(255) NOT NULL COMMENT '组名',
+    PRIMARY KEY (`group_id`)
+) COMMENT ='监控-资源组'
+;
+
+drop TABLE if exists it_monitor_template;
+CREATE TABLE `it_monitor_template`
+(
+    `template_id`   BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT '模板ID',
+    `template_name` VARCHAR(255) NOT NULL COMMENT '模板名称',
+    PRIMARY KEY (`template_id`)
+) COMMENT ='监控模板'
+;
+
+drop TABLE if exists it_monitor_threshold;
+CREATE TABLE `it_monitor_threshold`
+(
+    `item_id`        BIGINT(20)   NOT NULL COMMENT '指标ID',
+    `resource_id`    BIGINT(20)   NOT NULL COMMENT '资源ID',
+    `alarm_type`     INT(11)      NOT NULL COMMENT '告警级别',
+    `threshold_type` INT(11)      NOT NULL COMMENT '阈值类型:0发生变化;1大于;2小于;3大于等于;4小于等于;5等于;6不等于;7包含;8不包含',
+    `threshold`      VARCHAR(255) NOT NULL COMMENT '阈值',
+    `times`          INT(11)      NOT NULL COMMENT '连续触发次数',
+    PRIMARY KEY (`item_id`, `resource_id`)
+) COMMENT ='监控-阈值'
+;