package net.talentSolution.Tools;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import org.hyperic.sigar.Sigar;
import net.talentSolution.TSPOS.Debug.DebugLog;
import net.talentSolution.TSPOS.Mail.EmailAccountInfo;
import net.talentSolution.TSPOS.POSEntity.Utility;
import net.talentSolution.Tools.TimerTasks.APPTask;
import net.talentSolution.Tools.TimerTasks.DiskTask;
import net.talentSolution.Tools.TimerTasks.FixedRateTask;
import net.talentSolution.Tools.TimerTasks.ServiceTask;
import net.talentSolution.Tools.TimerTasks.SystemTask;
/**
*
*/
public class ResourcesMonitor {
static Sigar sigar;
public static EmailAccountInfo emailInfo = new EmailAccountInfo();
public static List<FixedRateTask> allTasks = new ArrayList<FixedRateTask>();
public static boolean dingflag = false;
public static String dingurl;
public static String ip;
public static String appDir;
public static String net;
public static Sigar getSigarObject() {
return sigar; }
/**
* Read in configuration file line by line
*/
void processConfigurationFile() {
List<String> contents = Utility.readFile("ResourcesMonitor.config");
for (String aLine : contents) {
aLine = aLine.trim();
if(aLine == null || aLine.equals("") || aLine.startsWith("#")) { // Skip comments line
continue;
}
if (aLine.toUpperCase().startsWith("SMTP_SERVER =") || aLine.toUpperCase().startsWith("SMTP_SERVER=")) {
String url = aLine.substring(aLine.indexOf("=") + 1).trim();
//url = url.substring(0, url.indexOf("#")).trim();
if (! url.equals("")) {
emailInfo.SMTP_URL = url;
}
} else if (aLine.toUpperCase().startsWith("USERNAME =") || aLine.toUpperCase().startsWith("USERNAME=")) {
String name = aLine.substring(aLine.indexOf("=") + 1).trim();
//name = name.substring(0, name.indexOf("#")).trim();
if (! name.equals("")) {
emailInfo.usrName = name;
}
} else if (aLine.toUpperCase().startsWith("PASSWORD =") || aLine.toUpperCase().startsWith("PASSWORD=")) {
String pswd = aLine.substring(aLine.indexOf("=") + 1).trim();
//pswd = pswd.substring(0, pswd.indexOf("#")).trim();
if (! pswd.equals("")) {
emailInfo.password = pswd;
}
} else if (aLine.toUpperCase().startsWith("SENDFROM =") || aLine.toUpperCase().startsWith("SENDFROM=")) {
String sendFrom = aLine.substring(aLine.indexOf("=") + 1).trim();
//sendFrom = sendFrom.substring(0, sendFrom.indexOf("#")).trim();
if (! sendFrom.equals("")) {
emailInfo.fromAddress = sendFrom;
}
} else if (aLine.toUpperCase().startsWith("SUBJECT =") || aLine.toUpperCase().startsWith("SUBJECT=")) {
String subj = aLine.substring(aLine.indexOf("=") + 1).trim();
//subj = subj.substring(0, subj.indexOf("#")).trim();
if (! subj.equals("")) {
emailInfo.subject = subj;
}
} else if (aLine.toUpperCase().startsWith("APPDIR =") || aLine.toUpperCase().startsWith("APPDIR=")) {
String appDir = aLine.substring(aLine.indexOf("=") + 1).trim();
//appDir = appDir.substring(0, appDir.indexOf("#")).trim();
if (! appDir.equals("")) {
ResourcesMonitor.appDir = appDir;
}
} else if (aLine.toUpperCase().startsWith("CPU =") || aLine.toUpperCase().startsWith("CPU=")) {
// CPU = 90%,2000,LOG
aLine = aLine.substring(aLine.indexOf("=") + 1).trim();
//aLine = aLine.substring(0, aLine.lastIndexOf("#")).trim();
String[] tokens = aLine.split(",");
if(tokens.length < 2) {
DebugLog.logger.error("关于CPU监测的参数配置有误,正确的格式应该为:CPU = 阈值%, 监测时间间隔,报警方式");
} else {
try {
int threshold = Integer.parseInt(tokens[0].substring(0, tokens[0].indexOf("%")));
int interval = Integer.parseInt(tokens[1]);
if (tokens[2].trim().toUpperCase().equals("LOG")) {
allTasks.add(new SystemTask(SystemTask.CPU, threshold, interval, null));
} else {
String[] emailList = tokens[2].split(";");
allTasks.add(new SystemTask(SystemTask.CPU, threshold, interval, emailList));
}
} catch (Exception e) {
DebugLog.logger.error("Exception: 创建CPU监测记录时出现异常 - ", e);
}
}
} else if (aLine.toUpperCase().startsWith("MEM =") || aLine.toUpperCase().startsWith("MEM=")) {
// MEM = 90%,2000,LOG
aLine = aLine.substring(aLine.indexOf("=") + 1).trim();
//aLine = aLine.substring(0, aLine.lastIndexOf("#")).trim();
String[] tokens = aLine.split(",");
if(tokens.length < 2) {
DebugLog.logger.error("关于MEM监测的参数配置有误,正确的格式应该为:MEM = 阈值%, 监测时间间隔,报警方式");
} else {
try {
int threshold = Integer.parseInt(tokens[0].substring(0, tokens[0].indexOf("%")));
int interval = Integer.parseInt(tokens[1].trim());
if (tokens[2].trim().toUpperCase().equals("LOG")) {
allTasks.add(new SystemTask(SystemTask.MEM, threshold, interval, null));
} else {
String[] emailList = tokens[2].split(";");
allTasks.add(new SystemTask(SystemTask.MEM, threshold, interval, emailList));
}
} catch (Exception e) {
DebugLog.logger.error("Exception: 创建MEM监测记录时出现异常 - ", e);
}
}
} else if (aLine.toUpperCase().startsWith("NETWORK =") || aLine.toUpperCase().startsWith("NETWORK=")) {
// Network = ,60000,Mialto:abc@123.com;xyz@123.com
aLine = aLine.substring(aLine.indexOf("=") + 1).trim();
//aLine = aLine.substring(0, aLine.lastIndexOf("#")).trim();
String[] tokens = aLine.split(",");
if(tokens.length < 2) {
DebugLog.logger.error("关于Network监测的参数配置有误,正确的格式应该为:Network = , 监测时间间隔,报警方式");
} else {
try {
int interval = Integer.parseInt(tokens[1]);
if (tokens[2].trim().toUpperCase().equals("LOG")) {
allTasks.add(new SystemTask(SystemTask.NET, 0, interval, null));
} else {
String[] emailList = tokens[2].split(";");
allTasks.add(new SystemTask(SystemTask.NET, 0, interval, emailList));
}
} catch (Exception e) {
DebugLog.logger.error("Exception: 创建NET监测记录时出现异常 - ", e);
}
}
} else if (aLine.toUpperCase().startsWith("THREADS =") || aLine.toUpperCase().startsWith("THREADS=")) {
// Threads = ,10000,LOG
aLine = aLine.substring(aLine.indexOf("=") + 1).trim();
//aLine = aLine.substring(0, aLine.lastIndexOf("#")).trim();
String[] tokens = aLine.split(",");
if(tokens.length < 2) {
DebugLog.logger.error("关于Threads监测的参数配置有误,正确的格式应该为:Threads = , 监测时间间隔,报警方式");
} else {
try {
int interval = Integer.parseInt(tokens[1]);
if (tokens[2].trim().toUpperCase().equals("LOG")) {
allTasks.add(new SystemTask(SystemTask.THREADS, 0, interval, null));
} else {
String[] emailList = tokens[2].split(";");
allTasks.add(new SystemTask(SystemTask.THREADS, 0, interval, emailList));
}
} catch (Exception e) {
DebugLog.logger.error("Exception: 创建Threads监测记录时出现异常 - ", e);
}
}
} else if (aLine.toUpperCase().startsWith("APP_")) {
// APP_1 = iSPOS_BO.exe, D:/iSPOS_BO/start_iSPOS_BO.bat, 30000,log
aLine = aLine.substring(aLine.indexOf("=") + 1).trim();
//aLine = aLine.substring(0, aLine.lastIndexOf("#")).trim();
String[] tokens = aLine.split(",");
if(tokens.length < 3) {
DebugLog.logger.error("关于APP监测的参数配置有误,正确的格式应该为:[名称]= [exe或服务全名
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
监控服务器CPU使用率,内存(MEM)使用率,硬盘剩余,网络连接状态,开启线程数量,是否开启某进程或某APP; 自动开启某服务某进程...etc. 有问题发邮件,发钉钉群里面。。。通过配置文件配置。。。主要用了pslist获取进程信息,sigar获取cpu,网络信息,disc使用情况。。。有托盘功能。。。。
资源推荐
资源详情
资源评论
收起资源包目录
ResourceMonitor.rar (62个子文件)
ResourceMonitor
bin
log4j.properties 546B
net
talentSolution
TSPOS
Mail
SendEmail.class 2KB
EmailAccountInfo.class 450B
Debug
CustomOutputStream.class 1KB
DebugLog.class 924B
POSEntity
Utility.class 3KB
SendMsg.class 741B
HttpHelper.class 5KB
Tools
MyTray.class 2KB
ResourcesMonitor.class 10KB
TimerTasks
NETTask.class 351B
SystemTask.class 9KB
FixedRateTask.class 425B
ServiceTask.class 5KB
APPTask.class 4KB
DiskTask.class 4KB
MyTray$1.class 710B
MyTray$2.class 966B
0.jpg 109KB
log4j.properties 3KB
.settings
org.eclipse.core.resources.prefs 57B
org.eclipse.jdt.core.prefs 598B
10.jpg 109KB
src
log4j.properties 546B
net
talentSolution
TSPOS
Mail
SendEmail.java 1KB
EmailAccountInfo.java 145B
Debug
DebugLog.java 1KB
POSEntity
HttpHelper.java 4KB
Utility.java 2KB
SendMsg.java 423B
Tools
TimerTasks
DiskTask.java 3KB
NETTask.java 103B
SystemTask.java 13KB
ServiceTask.java 4KB
APPTask.java 4KB
FixedRateTask.java 235B
MyTray.java 2KB
ResourcesMonitor.java 13KB
0.jpg 109KB
.project 391B
ResourcesMonitor.config 2KB
.classpath 1KB
debug
ResourcesMonitor.log.bak 2KB
ResourcesMonitor.log 712B
pslist64.exe 198KB
pslist.exe 175KB
libs
jug-2.0.0-asl.jar 31KB
junit-3.8.2.jar 118KB
javax.mail.jar 558KB
sigar-1.6.4.jar 415KB
sigar-x86-winnt.dll 256KB
httpcore-4.3.jar 276KB
commons-email-1.4.jar 50KB
sigar-amd64-winnt.dll 390KB
commons-logging-1.1.3.jar 61KB
sigar-x86-winnt.lib 97KB
httpmime-4.3.jar 36KB
commons-io-2.2.jar 170KB
fastjson-1.1.40.jar 350KB
log4j-1.2.17.jar 478KB
commons-lang3-3.1.jar 308KB
httpclient-4.3.jar 572KB
共 62 条
- 1
资源评论
- 老郭812017-09-09运行后怎么删掉卸载改软件,好像已经进程隐藏了
baidu_16092675
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 《软件测试训练营》学习笔记-举例注册测试用例
- 机器学习预测.rar机器学习预测.rar机器学习预测.rar
- VIS 110Nm lib ip
- 848694479200715布谷鸟配音_1.10.8.0.apk
- 基于改进粒子群算法微电网日前优化(matlab程序)
- Energy Hub Integration: Optimizing Electricity and Heat Market P
- 基于C51单片机蓝牙控制小车proteus仿真程序源码+相关技术文档资料.zip
- Integrated-Energy-Systems-with-CAES-(注释完全,可直接运行)
- PDF为英语文本绘制热区(DEMO)
- Python一种新的需求响应机制DR-VCG研究(注释完全,可直接运行)(文档加Matlab源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功