123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #include "dogcore.h"
- #include "boxshm.h"
- DogCore::DogCore(QObject *parent) : QObject(parent)
- {
- logThread = new LogThread(this);
- logThread->start();
- isWorking = false;
- timer = new QTimer(this);
- connect(timer,SIGNAL(timeout()),this,SLOT(time_out()));
- for(int i=0;i<128;i++)
- chkTime[i] = QDateTime::currentDateTime().toTime_t();
- }
- unsigned int DogCore::chkrootprocmem(QString proname)
- {
- FILE *f1=NULL,*f2=NULL;
- int pid, vmrss;
- char buff[512],name[64];
- QString cmd = QString("pgrep %1 -u root").arg(proname);
- f1 = popen(cmd.toUtf8().data(),"r");
- if(f1==NULL)
- return 0;
- if(NULL == fgets(buff,512,f1)){
- pclose(f1);
- return 0;
- }
- pid = atoi(buff);
- pclose(f1);
- QString filename = QString("/proc/%1/status").arg(pid);
- f2 = fopen(filename.toUtf8().data(),"r");
- if(NULL == f2)
- return 0;
- for(int i=0;i<16;i++)
- fgets(buff,512,f2);
- fgets(buff,512,f2);
- sscanf(buff,"%s %d",name,&vmrss);
- fclose(f2);
- return (vmrss>>10);
- }
- void DogCore::time_out()
- {
- if(!isWorking){
- isWorking = true;
- uint chkTime1 = QDateTime::currentDateTime().toTime_t();
- if((chkTime1-chkTime[1])>=300){
- chkTime[1]=chkTime1;
- if(chkrootprocmem("agDP0001")>200){
- logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0001): %4")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(chkTime[1])
- .arg(chkrootprocmem("agDP0001")));
- system("killall agDP0001");
- sleep(3);
- system("/root/bin/agDP0001 &");
- }
- }
- if((agBoxShm->processStatus[1].t_time>0)
- &&(static_cast<int>(chkTime1-agBoxShm->processStatus[1].t_time)>60)){
- if(system("killall agDP0001")!=-1){
- sleep(3);
- if(system("/root/bin/agDP0001 &")!=-1){
- logThread->appendData(QString("[ %1 agBoxDog %2 ] agDP0001 time out: %3")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[1].t_time)));
- }
- }
- }
- if((chkTime1-chkTime[2])>300){
- chkTime[2]=chkTime1;
- if(chkrootprocmem("agDP0002")>200){
- logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0002): %4")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(chkTime[2])
- .arg(chkrootprocmem("agDP0002")));
- system("killall agDP0002");
- sleep(3);
- system("/root/bin/agDP0002 &");
- }
- }
- if((agBoxShm->processStatus[2].t_time>0)
- &&(static_cast<int>(chkTime1-agBoxShm->processStatus[2].t_time)>60)){
- if(system("killall agDP0002")!=-1){
- sleep(3);
- if(system("/root/bin/agDP0002 &")!=-1){
- logThread->appendData(QString("[%1 agBoxDog %2] agDP0002 time out: %3")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[2].t_time)));
- }
- }
- }
- if((chkTime1-chkTime[3])>300){
- chkTime[3]=chkTime1;
- if(chkrootprocmem("agDP0003")>200){
- logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0003): %4")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(chkTime[3])
- .arg(chkrootprocmem("agDP0003")));
- system("killall agDP0003");
- sleep(3);
- system("/root/bin/agDP0003 &");
- }
- }
- if((agBoxShm->processStatus[3].t_time>0)
- &&(static_cast<int>(chkTime1-agBoxShm->processStatus[3].t_time)>60)){
- if(system("killall agDP0003")!=-1){
- sleep(3);
- if(system("/root/bin/agDP0003 &")!=-1){
- logThread->appendData(QString("[%1 agBoxDog %2] agDP0003 time out: %3")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[3].t_time)));
- }
- }
- }
- if((chkTime1-chkTime[4])>300){
- chkTime[4]=chkTime1;
- if(chkrootprocmem("agDP0004")>200){
- logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0004): %4")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(chkTime[4])
- .arg(chkrootprocmem("agDP0004")));
- system("killall agDP0004");
- sleep(3);
- system("/root/bin/agDP0004 &");
- }
- }
- if((agBoxShm->processStatus[4].t_time>0)
- &&(static_cast<int>(chkTime1-agBoxShm->processStatus[4].t_time)>60)){
- if(system("killall agDP0004")!=-1){
- sleep(3);
- if(system("/root/bin/agDP0004 &")!=-1){
- logThread->appendData(QString("[%1 agBoxDog %2] agDP0004 time out: %3")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[4].t_time)));
- }
- }
- }
- if((chkTime1-chkTime[5])>300){
- chkTime[5]=chkTime1;
- if(chkrootprocmem("agDP0005")>200){
- logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0005): %4")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(chkTime[5])
- .arg(chkrootprocmem("agDP0005")));
- system("killall agDP0005");
- sleep(3);
- system("/root/bin/agDP0005 &");
- }
- }
- if((agBoxShm->processStatus[5].t_time>0)
- &&(static_cast<int>(chkTime1-agBoxShm->processStatus[5].t_time)>300)){
- if(system("killall agDP0005")!=-1){
- sleep(3);
- if(system("/root/bin/agDP0005 &")!=-1){
- logThread->appendData(QString("[%1 agBoxDog %2] agDP0005 time out: %3")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[5].t_time)));
- }
- }
- }
- if((chkTime1-chkTime[6])>300){
- chkTime[6]=chkTime1;
- if(chkrootprocmem("agDP0006")>200){
- logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0006): %4")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(chkTime[6])
- .arg(chkrootprocmem("agDP0006")));
- system("killall agDP0006");
- sleep(3);
- system("/root/bin/agDP0006 &");
- }
- }
- if((agBoxShm->processStatus[6].t_time>0)
- &&(static_cast<int>(chkTime1-agBoxShm->processStatus[6].t_time)>90)){
- if(system("killall agDP0006")!=-1){
- sleep(3);
- if(system("/root/bin/agDP0006 &")!=-1){
- logThread->appendData(QString("[%1 agBoxDog %2] agDP0006 time out: %3")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[6].t_time)));
- }
- }
- }
-
- if((chkTime1-chkTime[11])>300){
- chkTime[11]=chkTime1;
- if(chkrootprocmem("agDP0011")>200){
- logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0011): %4")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(chkTime[11])
- .arg(chkrootprocmem("agDP0011")));
- system("killall agDP0011");
- sleep(3);
- system("/root/bin/agDP0011 &");
- }
- }
- if((agBoxShm->processStatus[11].t_time>0)
- &&(static_cast<int>(chkTime1-agBoxShm->processStatus[11].t_time)>90)){
- if(system("killall agDP0011")!=-1){
- sleep(3);
- if(system("/root/bin/agDP0011 &")!=-1){
- logThread->appendData(QString("[%1 agBoxDog %2] agDP0011 time out: %3")
- .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
- .arg(chkTime1)
- .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[11].t_time)));
- }
- }
- }
- isWorking = false;
- }
- }
- void DogCore::start(){
- time_out();
- timer->start(30000);
- }
|