The service is divided into two parts
1. Information collection
2. Information display and push and monitoring management
Information collection
1. Information collection adopts SIGAR to collect the required server information
2. Information storage: The information collected by SIGAR is stored in mysql database
3. Servers to be monitored Each server only needs to deploy the collection service
Information push and configuration
1. Information is pushed to DD group through DD robot
2. The collected policy can be adjusted by modifying the configuration in the mysql table
The final result
If a collection service is deployed on the server to be collected, Windows and Linux will periodically collect the desired data to the database
The information display service can cooperate with the front end to display the monitored data, and can also pass various push notifications
In the hands of those who need to know, the collection service is managed by managing the configuration of the database
project
Overall project structure
Common contains some database models, Mapper and mapping
Collect is a separate boot service
1. Before collecting information, check whether the server needs to collect information based on the IP address of the server.
MonitorServer monitorServer = monitorServerMapper.selectByIpAddress(ip); If (monitorServer == null) {log.info(" Server not configured "); return; }Copy the code
2. If you need to collect the information you need to collect, I only collect the memory and hard disk information
Memory part
Mem mem = sigar.getMem();
ServerMemory serverMemory = new ServerMemory();
serverMemory.setMonitorServerId(monitorServer.getId());
serverMemory.setCreateTime(LocalDateTime.now());
serverMemory.setUpdateTime(LocalDateTime.now());
if (Constans.osType.indexOf("WINDOWS") != -1) {
serverMemory.setTotalSize((int) (mem.getTotal() / (1024L * 1024L)));
serverMemory.setUsed((int) (mem.getUsed() / (1024L * 1024L)));
serverMemory.setAvail((int) (mem.getFree() / (1024L * 1024L)));
} else {
int used = (int) (mem.getActualUsed() / (1024L * 1024L));
int avail = (int) (mem.getActualFree() / (1024L * 1024L));
int total = used + avail;
serverMemory.setTotalSize(total);
serverMemory.setUsed(used);
serverMemory.setAvail(avail);
}
serverMemoryMapper.insertSelective(serverMemory);
Copy the code
3. After collection, it will be stored in the corresponding table
Display is to display and manage services
Here push is the address of the nail robot
1, management and display can cooperate with the front end to modify and adjust the table of the service to be monitored, and add and modify the nail push table
2. Push the collected information
3, database SQL statement
Nail configuration table
CREATE TABLE `dd_robot_config` ( `id` int(11) NOT NULL AUTO_INCREMENT, 'monitor_server_id' int(11) DEFAULT NULL COMMENT 'Server ID ',' note 'varchar(50) DEFAULT NULL COMMENT' Cluster description ', 'secret' varchar(200) DEFAULT NULL COMMENT 'id ',' web_hook 'varchar(255) DEFAULT NULL COMMENT' id ', 'create_time' TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'add time ', 'update_time' datetime DEFAULT NULL COMMENT 'update time ', PRIMARY KEY (' id ') ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET= UTf8MB4 COMMENT=' mysql ';Copy the code
Monitor the server configuration table
CREATE TABLE 'monitor_server' (' id 'int(11) NOT NULL AUTO_INCREMENT,' note 'vARCHar (50) DEFAULT NULL COMMENT' Server description ', 'ip_address' varchar(20) NOT NULL COMMENT 'IP address ', 'status' (11) DEFAULT '1' COMMENT' STATUS ' 'notifyer_phone' varchar(15) DEFAULT NULL COMMENT 'Notifyer_phone' varchar(15) DEFAULT NULL COMMENT ' 'create_time' TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'create time ', 'update_time' datetime DEFAULT NULL COMMENT 'update_time ', PRIMARY KEY (' id ',' ip_address '), KEY 'IP' (' ip_address ') ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET= UTf8MB4 COMMENT=' server info ';Copy the code
Memory monitoring table
CREATE TABLE `server_memory` ( `id` int(11) NOT NULL AUTO_INCREMENT, 'monitor_server_id' int(11) DEFAULT NULL COMMENT 'server ID ',' total_size 'int(11) DEFAULT NULL COMMENT' total M', 'Used' int(11) DEFAULT NULL COMMENT 'used ',' Avail 'int(11) DEFAULT NULL COMMENT' remainder ', 'create_time' TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'create time ', 'update_time' datetime DEFAULT NULL COMMENT 'update time ', PRIMARY KEY (' id ') ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET= UTf8MB4 COMMENT=' unsigned ';Copy the code
The project address
GitHub