Back to home page

Project CMSSW displayed by LXR

 
 

    


Warning, /DQM/Integration/scripts/XMLcfgfiles/getRunAppsInfo is written in an unsupported language. File is not indexed.

0001 #!/usr/bin/env python3
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 import sys
0011 import os.path
0012 import getopt as gop
0013 import ExtractAppInfoFromXML as appinf
0014 
0015 # ssh srv-c2d05-18.cms ps -eo pid,cmd | grep 22101
0016 ################################################################################
0017 def getAppPID(srv,port):
0018         try:
0019                 print "Connecting to server: "+srv+" and fetching PID for application running on port: "+port
0020                 cf=os.popen('ssh '+srv+' ps -eo pid,cmd | grep '+port)
0021                 l=cf.readline();
0022                 if l=="":
0023                         cf.close()
0024                         return "App Not Running" 
0025                 else:
0026                         pidv=l.split()
0027                         cf.close();
0028                         return pidv[0]
0029         except:
0030                 sys.stderr.write(  "Something went really bad\n" )
0031         return -1
0032 ################################################################################
0033 def getAppLogFileName(srv,pid):
0034 #       try:
0035                 #pid=getAppPID(srv,port)
0036                 if pid=="App Not Running":
0037                         return "No active log file"
0038                 else:
0039                         print "Connecting to server: "+srv+" and fetching LogFile for application with PID: "+pid
0040                         cf=os.popen('ssh '+srv+' ls -l /tmp | grep '+pid)
0041                         l=cf.readline();
0042                         if l=="":
0043                                 cf.close()
0044                                 return "App Not Running???" 
0045                         else:
0046                                 logfilev=l.split()
0047                                 cf.close();
0048                                 return logfilev[-1]
0049 #       except Exception,e:
0050 #               sys.stderr.write(  "Something went really bad\n" + e[0])
0051 #        return -1
0052 ################################################################################
0053 def getRunningAppsInfo(filename):
0054         (table,grid)=appinf.getAppInfo(filename,2,1,3,4)
0055         for apps in grid:
0056                 apps.insert(3,getAppPID(apps[1],apps[2]))
0057                 apps.insert(4,getAppLogFileName(apps[1],apps[3]))
0058         return grid
0059 ################################################################################
0060 #Script operation                                                              #
0061 ################################################################################
0062 if __name__ == "__main__":             
0063         fullinfo=False
0064         headers=False
0065         try:
0066                 (args,filename)=gop.getopt(sys.argv[1:],"hf",["help"])
0067         except getopt.GetoptError:
0068                 sys.stderr.write(  "Sintax Error unrecognised option" )
0069                 sys.stderr.write( __doc__ )
0070                 sys.exit(2)
0071         
0072         for item in args:
0073                 if item[0]=="-h":
0074                         headers=True
0075                 elif item[0]=="-f":
0076                         fullinfo=True
0077                 elif item[0]=="--help":
0078                         sys.stdout.write(__doc__)
0079                         sys.exit(2)
0080         if len(filename)==0:
0081                 sys.stderr.write(  "\nERROR: xdaq XML config file name not present, please specify\n\n" )
0082                 sys.stdout.write(__doc__)
0083         elif len(filename) > 1:
0084                 sys.stderr.write(  "\nERROR: Too many file names or other arguments, please specify only 1\n\n" )
0085                 sys.stdout.write(__doc__)
0086                 sys.exit(2)
0087         elif not os.path.exists(filename[0]):
0088                 sys.stderr.write(  "\nERROR: xdaq XML config file does not exist please verify\n\n" )
0089                 sys.stdout.write(__doc__)
0090                 sys.exit(2)
0091         grid=getRunningAppsInfo(filename[0])
0092         if fullinfo:
0093                 if headers:
0094                         grid.insert(0,["Application","Server","Port","PID","LogfileName","App Config File"])
0095         else:
0096                 if headers:
0097                         i=0;
0098                         for record in grid:
0099                                 newrecord=[record[0],record[3],record[4]]
0100                                 grid[i]=newrecord
0101                                 del record
0102                                 i+=1
0103                         grid.insert(0,["Application","PID","LogfileName"])
0104                         
0105                 else:
0106                         i=0;
0107                         for record in grid:
0108                                 newrecord=[record[0],record[3],record[4]]
0109                                 grid[i]=newrecord
0110                                 del record
0111                                 i+=1
0112         
0113         appinf.printGrid(grid)
0114                 
0115