dogcore.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #include "dogcore.h"
  2. #include "boxshm.h"
  3. DogCore::DogCore(QObject *parent) : QObject(parent)
  4. {
  5. logThread = new LogThread(this);
  6. logThread->start();
  7. isWorking = false;
  8. timer = new QTimer(this);
  9. connect(timer,SIGNAL(timeout()),this,SLOT(time_out()));
  10. for(int i=0;i<128;i++)
  11. chkTime[i] = QDateTime::currentDateTime().toTime_t();
  12. }
  13. unsigned int DogCore::chkrootprocmem(QString proname)
  14. {
  15. FILE *f1=NULL,*f2=NULL;
  16. int pid, vmrss;
  17. char buff[512],name[64];
  18. QString cmd = QString("pgrep %1 -u root").arg(proname);
  19. f1 = popen(cmd.toUtf8().data(),"r");
  20. if(f1==NULL)
  21. return 0;
  22. if(NULL == fgets(buff,512,f1)){
  23. pclose(f1);
  24. return 0;
  25. }
  26. pid = atoi(buff);
  27. pclose(f1);
  28. QString filename = QString("/proc/%1/status").arg(pid);
  29. f2 = fopen(filename.toUtf8().data(),"r");
  30. if(NULL == f2)
  31. return 0;
  32. for(int i=0;i<16;i++)
  33. fgets(buff,512,f2);
  34. fgets(buff,512,f2);
  35. sscanf(buff,"%s %d",name,&vmrss);
  36. fclose(f2);
  37. return (vmrss>>10);
  38. }
  39. void DogCore::time_out()
  40. {
  41. if(!isWorking){
  42. isWorking = true;
  43. uint chkTime1 = QDateTime::currentDateTime().toTime_t();
  44. if((chkTime1-chkTime[1])>=300){
  45. chkTime[1]=chkTime1;
  46. if(chkrootprocmem("agDP0001")>200){
  47. logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0001): %4")
  48. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  49. .arg(chkTime1)
  50. .arg(chkTime[1])
  51. .arg(chkrootprocmem("agDP0001")));
  52. system("killall agDP0001");
  53. sleep(3);
  54. system("/root/bin/agDP0001 &");
  55. }
  56. }
  57. if((agBoxShm->processStatus[1].t_time>0)
  58. &&(static_cast<int>(chkTime1-agBoxShm->processStatus[1].t_time)>60)){
  59. if(system("killall agDP0001")!=-1){
  60. sleep(3);
  61. if(system("/root/bin/agDP0001 &")!=-1){
  62. logThread->appendData(QString("[ %1 agBoxDog %2 ] agDP0001 time out: %3")
  63. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  64. .arg(chkTime1)
  65. .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[1].t_time)));
  66. }
  67. }
  68. }
  69. if((chkTime1-chkTime[2])>300){
  70. chkTime[2]=chkTime1;
  71. if(chkrootprocmem("agDP0002")>200){
  72. logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0002): %4")
  73. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  74. .arg(chkTime1)
  75. .arg(chkTime[2])
  76. .arg(chkrootprocmem("agDP0002")));
  77. system("killall agDP0002");
  78. sleep(3);
  79. system("/root/bin/agDP0002 &");
  80. }
  81. }
  82. if((agBoxShm->processStatus[2].t_time>0)
  83. &&(static_cast<int>(chkTime1-agBoxShm->processStatus[2].t_time)>60)){
  84. if(system("killall agDP0002")!=-1){
  85. sleep(3);
  86. if(system("/root/bin/agDP0002 &")!=-1){
  87. logThread->appendData(QString("[%1 agBoxDog %2] agDP0002 time out: %3")
  88. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  89. .arg(chkTime1)
  90. .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[2].t_time)));
  91. }
  92. }
  93. }
  94. if((chkTime1-chkTime[3])>300){
  95. chkTime[3]=chkTime1;
  96. if(chkrootprocmem("agDP0003")>200){
  97. logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0003): %4")
  98. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  99. .arg(chkTime1)
  100. .arg(chkTime[3])
  101. .arg(chkrootprocmem("agDP0003")));
  102. system("killall agDP0003");
  103. sleep(3);
  104. system("/root/bin/agDP0003 &");
  105. }
  106. }
  107. if((agBoxShm->processStatus[3].t_time>0)
  108. &&(static_cast<int>(chkTime1-agBoxShm->processStatus[3].t_time)>60)){
  109. if(system("killall agDP0003")!=-1){
  110. sleep(3);
  111. if(system("/root/bin/agDP0003 &")!=-1){
  112. logThread->appendData(QString("[%1 agBoxDog %2] agDP0003 time out: %3")
  113. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  114. .arg(chkTime1)
  115. .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[3].t_time)));
  116. }
  117. }
  118. }
  119. if((chkTime1-chkTime[4])>300){
  120. chkTime[4]=chkTime1;
  121. if(chkrootprocmem("agDP0004")>200){
  122. logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0004): %4")
  123. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  124. .arg(chkTime1)
  125. .arg(chkTime[4])
  126. .arg(chkrootprocmem("agDP0004")));
  127. system("killall agDP0004");
  128. sleep(3);
  129. system("/root/bin/agDP0004 &");
  130. }
  131. }
  132. if((agBoxShm->processStatus[4].t_time>0)
  133. &&(static_cast<int>(chkTime1-agBoxShm->processStatus[4].t_time)>60)){
  134. if(system("killall agDP0004")!=-1){
  135. sleep(3);
  136. if(system("/root/bin/agDP0004 &")!=-1){
  137. logThread->appendData(QString("[%1 agBoxDog %2] agDP0004 time out: %3")
  138. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  139. .arg(chkTime1)
  140. .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[4].t_time)));
  141. }
  142. }
  143. }
  144. if((chkTime1-chkTime[5])>300){
  145. chkTime[5]=chkTime1;
  146. if(chkrootprocmem("agDP0005")>200){
  147. logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0005): %4")
  148. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  149. .arg(chkTime1)
  150. .arg(chkTime[5])
  151. .arg(chkrootprocmem("agDP0005")));
  152. system("killall agDP0005");
  153. sleep(3);
  154. system("/root/bin/agDP0005 &");
  155. }
  156. }
  157. if((agBoxShm->processStatus[5].t_time>0)
  158. &&(static_cast<int>(chkTime1-agBoxShm->processStatus[5].t_time)>300)){
  159. if(system("killall agDP0005")!=-1){
  160. sleep(3);
  161. if(system("/root/bin/agDP0005 &")!=-1){
  162. logThread->appendData(QString("[%1 agBoxDog %2] agDP0005 time out: %3")
  163. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  164. .arg(chkTime1)
  165. .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[5].t_time)));
  166. }
  167. }
  168. }
  169. if((chkTime1-chkTime[6])>300){
  170. chkTime[6]=chkTime1;
  171. if(chkrootprocmem("agDP0006")>200){
  172. logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0006): %4")
  173. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  174. .arg(chkTime1)
  175. .arg(chkTime[6])
  176. .arg(chkrootprocmem("agDP0006")));
  177. system("killall agDP0006");
  178. sleep(3);
  179. system("/root/bin/agDP0006 &");
  180. }
  181. }
  182. if((agBoxShm->processStatus[6].t_time>0)
  183. &&(static_cast<int>(chkTime1-agBoxShm->processStatus[6].t_time)>90)){
  184. if(system("killall agDP0006")!=-1){
  185. sleep(3);
  186. if(system("/root/bin/agDP0006 &")!=-1){
  187. logThread->appendData(QString("[%1 agBoxDog %2] agDP0006 time out: %3")
  188. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  189. .arg(chkTime1)
  190. .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[6].t_time)));
  191. }
  192. }
  193. }
  194. if((chkTime1-chkTime[11])>300){
  195. chkTime[11]=chkTime1;
  196. if(chkrootprocmem("agDP0011")>200){
  197. logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0011): %4")
  198. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  199. .arg(chkTime1)
  200. .arg(chkTime[11])
  201. .arg(chkrootprocmem("agDP0011")));
  202. system("killall agDP0011");
  203. sleep(3);
  204. system("/root/bin/agDP0011 &");
  205. }
  206. }
  207. if((agBoxShm->processStatus[11].t_time>0)
  208. &&(static_cast<int>(chkTime1-agBoxShm->processStatus[11].t_time)>90)){
  209. if(system("killall agDP0011")!=-1){
  210. sleep(3);
  211. if(system("/root/bin/agDP0011 &")!=-1){
  212. logThread->appendData(QString("[%1 agBoxDog %2] agDP0011 time out: %3")
  213. .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
  214. .arg(chkTime1)
  215. .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[11].t_time)));
  216. }
  217. }
  218. }
  219. isWorking = false;
  220. }
  221. }
  222. void DogCore::start(){
  223. time_out();
  224. timer->start(30000);
  225. }