File indexing completed on 2024-04-06 12:07:43
0001
0002 """This module provides the PID and the log file name of the running DQM
0003 applications (consumers), thus completing the information generated by
0004 ExtractAppInfoFromXML.
0005
0006 When used as a script the following options are accepted:
0007 -f Show all columns
0008 -h show headers
0009 """
0010 from __future__ import print_function
0011 import sys
0012 import os.path
0013 import getopt as gop
0014 import ExtractAppInfoFromXML as appinf
0015
0016
0017
0018 def getAppPID(srv,port):
0019 try:
0020 print("Connecting to server: "+srv+" and fetching PID for application running on port: "+port)
0021 cf=os.popen('ssh '+srv+' ps -eo pid,cmd | grep '+port)
0022 l=cf.readline();
0023 if l=="":
0024 cf.close()
0025 return "App Not Running"
0026 else:
0027 pidv=l.split()
0028 cf.close();
0029 return pidv[0]
0030 except:
0031 sys.stderr.write( "Something went really bad\n" )
0032 return -1
0033
0034 def getAppLogFileName(srv,pid):
0035
0036
0037 if pid=="App Not Running":
0038 return "No active log file"
0039 else:
0040 print("Connecting to server: "+srv+" and fetching LogFile for application with PID: "+pid)
0041 cf=os.popen('ssh '+srv+' ls -l /tmp | grep '+pid)
0042 l=cf.readline();
0043 if l=="":
0044 cf.close()
0045 return "App Not Running???"
0046 else:
0047 logfilev=l.split()
0048 cf.close();
0049 return logfilev[-1]
0050
0051
0052
0053
0054 def getRunningAppsInfo(filename):
0055 (table,grid)=appinf.getAppInfo(filename,2,1,3,4)
0056 for apps in grid:
0057 apps.insert(3,getAppPID(apps[1],apps[2]))
0058 apps.insert(4,getAppLogFileName(apps[1],apps[3]))
0059 return grid
0060
0061
0062
0063 if __name__ == "__main__":
0064 fullinfo=False
0065 headers=False
0066 try:
0067 (args,filename)=gop.getopt(sys.argv[1:],"hf",["help"])
0068 except getopt.GetoptError:
0069 sys.stderr.write( "Sintax Error unrecognised option" )
0070 sys.stderr.write( __doc__ )
0071 sys.exit(2)
0072
0073 for item in args:
0074 if item[0]=="-h":
0075 headers=True
0076 elif item[0]=="-f":
0077 fullinfo=True
0078 elif item[0]=="--help":
0079 sys.stdout.write(__doc__)
0080 sys.exit(2)
0081 if len(filename)==0:
0082 sys.stderr.write( "\nERROR: xdaq XML config file name not present, please specify\n\n" )
0083 sys.stdout.write(__doc__)
0084 elif len(filename) > 1:
0085 sys.stderr.write( "\nERROR: Too many file names or other arguments, please specify only 1\n\n" )
0086 sys.stdout.write(__doc__)
0087 sys.exit(2)
0088 elif not os.path.exists(filename[0]):
0089 sys.stderr.write( "\nERROR: xdaq XML config file does not exist please verify\n\n" )
0090 sys.stdout.write(__doc__)
0091 sys.exit(2)
0092 grid=getRunningAppsInfo(filename[0])
0093 if fullinfo:
0094 if headers:
0095 grid.insert(0,["Application","Server","Port","PID","LogfileName","App Config File"])
0096 else:
0097 if headers:
0098 i=0;
0099 for record in grid:
0100 newrecord=[record[0],record[3],record[4]]
0101 grid[i]=newrecord
0102 del record
0103 i+=1
0104 grid.insert(0,["Application","PID","LogfileName"])
0105
0106 else:
0107 i=0;
0108 for record in grid:
0109 newrecord=[record[0],record[3],record[4]]
0110 grid[i]=newrecord
0111 del record
0112 i+=1
0113
0114 appinf.printGrid(grid)
0115
0116