CMS 3D CMS Logo

getRunAppsInfo.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """This module provides the PID and the log file name of the running DQM
3 applications (consumers), thus completing the information generated by
4 ExtractAppInfoFromXML.
5 
6 When used as a script the following options are accepted:
7  -f Show all columns
8  -h show headers
9 """
10 from __future__ import print_function
11 import sys
12 import os.path
13 import getopt as gop
14 import ExtractAppInfoFromXML as appinf
15 
16 # ssh srv-c2d05-18.cms ps -eo pid,cmd | grep 22101
17 ################################################################################
18 def getAppPID(srv,port):
19  try:
20  print("Connecting to server: "+srv+" and fetching PID for application running on port: "+port)
21  cf=os.popen('ssh '+srv+' ps -eo pid,cmd | grep '+port)
22  l=cf.readline();
23  if l=="":
24  cf.close()
25  return "App Not Running"
26  else:
27  pidv=l.split()
28  cf.close();
29  return pidv[0]
30  except:
31  sys.stderr.write( "Something went really bad\n" )
32  return -1
33 ################################################################################
34 def getAppLogFileName(srv,pid):
35 # try:
36  #pid=getAppPID(srv,port)
37  if pid=="App Not Running":
38  return "No active log file"
39  else:
40  print("Connecting to server: "+srv+" and fetching LogFile for application with PID: "+pid)
41  cf=os.popen('ssh '+srv+' ls -l /tmp | grep '+pid)
42  l=cf.readline();
43  if l=="":
44  cf.close()
45  return "App Not Running???"
46  else:
47  logfilev=l.split()
48  cf.close();
49  return logfilev[-1]
50 # except Exception,e:
51 # sys.stderr.write( "Something went really bad\n" + e[0])
52 # return -1
53 ################################################################################
54 def getRunningAppsInfo(filename):
55  (table,grid)=appinf.getAppInfo(filename,2,1,3,4)
56  for apps in grid:
57  apps.insert(3,getAppPID(apps[1],apps[2]))
58  apps.insert(4,getAppLogFileName(apps[1],apps[3]))
59  return grid
60 ################################################################################
61 #Script operation #
62 ################################################################################
63 if __name__ == "__main__":
64  fullinfo=False
65  headers=False
66  try:
67  (args,filename)=gop.getopt(sys.argv[1:],"hf",["help"])
68  except getopt.GetoptError:
69  sys.stderr.write( "Sintax Error unrecognised option" )
70  sys.stderr.write( __doc__ )
71  sys.exit(2)
72 
73  for item in args:
74  if item[0]=="-h":
75  headers=True
76  elif item[0]=="-f":
77  fullinfo=True
78  elif item[0]=="--help":
79  sys.stdout.write(__doc__)
80  sys.exit(2)
81  if len(filename)==0:
82  sys.stderr.write( "\nERROR: xdaq XML config file name not present, please specify\n\n" )
83  sys.stdout.write(__doc__)
84  elif len(filename) > 1:
85  sys.stderr.write( "\nERROR: Too many file names or other arguments, please specify only 1\n\n" )
86  sys.stdout.write(__doc__)
87  sys.exit(2)
88  elif not os.path.exists(filename[0]):
89  sys.stderr.write( "\nERROR: xdaq XML config file does not exist please verify\n\n" )
90  sys.stdout.write(__doc__)
91  sys.exit(2)
92  grid=getRunningAppsInfo(filename[0])
93  if fullinfo:
94  if headers:
95  grid.insert(0,["Application","Server","Port","PID","LogfileName","App Config File"])
96  else:
97  if headers:
98  i=0;
99  for record in grid:
100  newrecord=[record[0],record[3],record[4]]
101  grid[i]=newrecord
102  del record
103  i+=1
104  grid.insert(0,["Application","PID","LogfileName"])
105 
106  else:
107  i=0;
108  for record in grid:
109  newrecord=[record[0],record[3],record[4]]
110  grid[i]=newrecord
111  del record
112  i+=1
113 
114  appinf.printGrid(grid)
115 
116 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def getAppLogFileName(srv, pid)
def getAppPID(srv, port)
def getRunningAppsInfo(filename)