监控Teamcenter poolmanger 死进程

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.LineNumberReader;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Date;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Timer;

import java.util.TimerTask;

 

import cn.hutool.log.Log;

import cn.hutool.log.LogFactory;

 

public class GetDetail {

 

public static Map<String,Integer> mapPids=new HashMap<String,Integer>();

public static int runClount=0;

public static Log log = LogFactory.get();

 

public static void main(String[] args) {

try {

mapPids.clear();

cycle1();

} catch (Exception e) {

e.printStackTrace();

}

}

 

public static void cycle1() throws Exception {

final Timer timer = new Timer();

timer.schedule(new TimerTask() {

public void run() {

try {

runClount++;

if(runClount >10000) {

runClount=0;

mapPids.clear();

}

log.info("正在监控PoolManage:"+runClount+"......");

String pid="";

String user="";

String pr="";

String ni="";

String virt="";

String res="";

String shr="";

String s="";

String cpu="";

String mem="";

String time="";

String command="";

 

Runtime rt = Runtime.getRuntime();

//Process p = rt.exec("top -u infodba");

Process p = rt.exec("top -b -n 1 -u infodba");//5分钟

 

BufferedReader in = null;

in = new BufferedReader(new InputStreamReader(p.getInputStream()));

String str = "";

int linecount = 0;

while ((str = in.readLine()) != null) {

 

linecount++;

//log.info("第"+linecount+":"+str);

String[] strArray=str.split("\\s+");

if(strArray!=null && strArray.length==12) {

pid=strArray[0];

user=strArray[1];

cpu=strArray[9];

command=strArray[11];

//System.out.println("pid"+pid+";cpu"+cpu);

double dCpu=Double.parseDouble(cpu);

if(dCpu > 0.9 && user.equals("infodba") && command.equals("tcserver")) {

log.info("pid1"+pid+";cpu"+cpu);

if(mapPids.containsKey(pid)) {

int count=mapPids.get(pid);

if(count >1000) {

//Process p1 = rt.exec("kill -9 -"+pid);//kill进程

log.info("执行 kill pid1"+pid+";cpu"+cpu);

 

}else {

count =count+1;

mapPids.put(pid, count);

}

}else{

mapPids.put(pid, 1);

}

}

}

}

} catch (Exception e) {

e.printStackTrace();

}

 

}

}, 0, 1000*300);//5分钟

}

 

}

posted @   张永全-PLM顾问  阅读(69)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示