打造自己的Linux服务器监控小工具
作者:网络转载 发布时间:[ 2014/7/18 14:26:40 ] 推荐标签:linux 操作系统
代码
1 LinuxService
|
package com.sunfan.monitor.service;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.sunfan.monitor.manager.pool.LinuxConnectionPool;
import com.sunfan.monitor.platform.IConnectable;
import com.sunfan.monitor.platform.linux.LinuxSessionHandle;
/**
*
* @author sunfan
*
*/
@Component
public class LinuxService {
private String defaultTopComand = "top -b -n 1";
private String defaultMpstatComand = "mpstat -P ALL";
private String defaultFreeCommand = "free -m";
private String defaultIostatCommand = "iostat -d -m";
@Autowired
private LinuxConnectionPool pool ;
@Autowired
private LinuxSessionHandle handle;
/**
* execute default command "top -b -n 1" and return String type reslut
*
* @param url server's ip
* @param user login name
* @param password login password
* @return
* @throws IOException
*/
public String topMonitor(String url,String user,String password) throws IOException{
return this.executeCommand(url, user, password, defaultTopComand);
}
/**
* execute default command "mpstat -P ALL" to get cpus performance
*
* @param url
* @param user
* @param password
* @return
* @throws IOException
*/
public String cpuMonitor(String url,String user,String password) throws IOException{
return this.executeCommand(url, user, password, defaultMpstatComand);
}
/**
* execute default command "free -m" to get memory performance
* @param url
* @param user
* @param password
* @return
* @throws IOException
*/
public String memoryMonitor(String url,String user,String password) throws IOException{
return this.executeCommand(url, user, password, defaultFreeCommand);
}
/**
* execute default command "free -m" to get memory performance
* @param url
* @param user
* @param password
* @return
* @throws IOException
*/
public String inputOutputMonitor(String url,String user,String password) throws IOException{
return this.executeCommand(url, user, password, defaultIostatCommand);
}
public String executeCommand(String url,String user,String password,String command) throws IOException{
IConnectable lc = pool.borrowObject(url,user,password);
return handle.executeCommand(lc.getConnection(),command);
}
}
|
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。
相关推荐
Linux下开源的DDR压力测试工具曝Linux恶意软件:让树莓派设备挖掘数字货币linux系统中不同颜色的文件夹及根目录介绍软件测试工程师必知必会Linux命令Linux下DNS服务器配置如何成为不可替代的Linux运维工程师?详解Linux进程(作业)的查看和杀死Linux 日志定时轮询流程详解比特币勒索病毒不只Windows系统有,Linux版的来了Linux日志定时轮询流程详解Linux iommu和vfio概念空间解构Linux系统如何低于TCP洪水攻击Linux无损调整分区大小Linux下防火墙配置实例Linux使用Jexus托管Asp.Net Core应用程序Linux中引号的那些事

sales@spasvo.com