Example #1
0
 def export_getInfo(self):
     """  Get versions of the installed DIRAC software and extensions, setup of the
      local installation
 """
     return gComponentInstaller.getInfo()
Example #2
0
    def __readHostInfo():
        """ Get host current loads, memory, etc
    """

        result = dict()
        # Memory info
        re_parser = re.compile(r'^(?P<key>\S*):\s*(?P<value>\d*)\s*kB')
        for line in open('/proc/meminfo'):
            match = re_parser.match(line)
            if not match:
                continue
            key, value = match.groups(['key', 'value'])
            result[key] = int(value)

        for mtype in ['Mem', 'Swap']:
            memory = int(result.get(mtype + 'Total'))
            mfree = int(result.get(mtype + 'Free'))
            if memory > 0:
                percentage = float(memory - mfree) / float(memory) * 100.
            else:
                percentage = 0
            name = 'Memory'
            if mtype == "Swap":
                name = 'Swap'
            result[name] = '%.1f%%/%.1fMB' % (percentage, memory / 1024.)

        # Loads
        l1, l5, l15 = (str(lx) for lx in os.getloadavg())
        result['Load1'] = l1
        result['Load5'] = l5
        result['Load15'] = l15
        result['Load'] = '/'.join([l1, l5, l15])

        # CPU info
        with open('/proc/cpuinfo', 'r') as fd:
            lines = fd.readlines()
            processors = 0
            physCores = {}
            for line in lines:
                if line.strip():
                    parameter, value = line.split(':')
                    parameter = parameter.strip()
                    value = value.strip()
                    if parameter.startswith('processor'):
                        processors += 1
                    if parameter.startswith('physical id'):
                        physCores[value] = parameter
                    if parameter.startswith('model name'):
                        result['CPUModel'] = value
                    if parameter.startswith('cpu MHz'):
                        result['CPUClock'] = value
            result['Cores'] = processors
            result['PhysicalCores'] = len(physCores)

        # Disk occupancy
        summary = ''
        _status, output = commands.getstatusoutput('df')
        lines = output.split('\n')
        for i in xrange(len(lines)):
            if lines[i].startswith('/dev'):
                fields = lines[i].split()
                if len(fields) == 1:
                    fields += lines[i + 1].split()
                _disk = fields[0].replace('/dev/sd', '')
                partition = fields[5]
                occupancy = fields[4]
                summary += ",%s:%s" % (partition, occupancy)
        result['DiskOccupancy'] = summary[1:]
        result['RootDiskSpace'] = Os.getDiskSpace(rootPath)

        # Open files
        puser = getpass.getuser()
        _status, output = commands.getstatusoutput('lsof')
        pipes = 0
        files = 0
        sockets = 0
        lines = output.split('\n')
        for line in lines:
            fType = line.split()[4]
            user = line.split()[2]
            if user == puser:
                if fType in ['REG']:
                    files += 1
                elif fType in ['unix', 'IPv4']:
                    sockets += 1
                elif fType in ['FIFO']:
                    pipes += 1
        result['OpenSockets'] = sockets
        result['OpenFiles'] = files
        result['OpenPipes'] = pipes

        infoResult = gComponentInstaller.getInfo()
        if infoResult['OK']:
            result.update(infoResult['Value'])
            # the infoResult value is {"Extensions":{'a1':'v1',a2:'v2'}; we convert to a string
            result.update({
                "Extensions":
                ";".join([
                    "%s:%s" % (key, value) for (key, value) in
                    infoResult["Value"].get('Extensions').iteritems()
                ])
            })

        # Host certificate properties
        certFile, _keyFile = getHostCertificateAndKeyLocation()
        chain = X509Chain()
        chain.loadChainFromFile(certFile)
        resultCert = chain.getCredentials()
        if resultCert['OK']:
            result['SecondsLeft'] = resultCert['Value']['secondsLeft']
            result['CertificateValidity'] = str(
                timedelta(seconds=resultCert['Value']['secondsLeft']))
            result['CertificateDN'] = resultCert['Value']['subject']
            result['HostProperties'] = resultCert['Value']['groupProperties']
            result['CertificateIssuer'] = resultCert['Value']['issuer']

        # Host uptime
        result['Uptime'] = str(
            timedelta(seconds=(time.time() - psutil.boot_time())))

        return S_OK(result)
Example #3
0
 def export_getInfo( self ):
   """  Get versions of the installed DIRAC software and extensions, setup of the
        local installation
   """
   return gComponentInstaller.getInfo( getCSExtensions() )
Example #4
0
  def __readHostInfo():
    """ Get host current loads, memory, etc
    """

    result = dict()
    # Memory info
    re_parser = re.compile( r'^(?P<key>\S*):\s*(?P<value>\d*)\s*kB' )
    for line in open( '/proc/meminfo' ):
      match = re_parser.match( line )
      if not match:
        continue
      key, value = match.groups( ['key', 'value'] )
      result[key] = int( value )

    for mtype in ['Mem', 'Swap']:
      memory = int( result.get( mtype + 'Total' ) )
      mfree = int( result.get( mtype + 'Free' ) )
      if memory > 0:
        percentage = float( memory - mfree ) / float( memory ) * 100.
      else:
        percentage = 0
      name = 'Memory'
      if mtype == "Swap":
        name = 'Swap'
      result[name] = '%.1f%%/%.1fMB' % ( percentage, memory / 1024. )

    # Loads
    with open( '/proc/loadavg' ) as fd:
      line = fd.read()
      l1, l5, l15, _d1, _d2 = line.split()
    result['Load1'] = l1
    result['Load5'] = l5
    result['Load15'] = l15
    result['Load'] = '/'.join( [l1, l5, l15] )

    # CPU info
    with open( '/proc/cpuinfo', 'r' ) as fd:
      lines = fd.readlines()
      processors = 0
      physCores = {}
      for line in lines:
        if line.strip():
          parameter, value = line.split( ':' )
          parameter = parameter.strip()
          value = value.strip()
          if parameter.startswith( 'processor' ):
            processors += 1
          if parameter.startswith( 'physical id' ):
            physCores[value] = parameter
          if parameter.startswith( 'model name' ):
            result['CPUModel'] = value
          if parameter.startswith( 'cpu MHz' ):
            result['CPUClock'] = value
      result['Cores'] = processors
      result['PhysicalCores'] = len( physCores )

    # Disk occupancy
    summary = ''
    _status, output = commands.getstatusoutput( 'df' )
    lines = output.split( '\n' )
    for i in range( len( lines ) ):
      if lines[i].startswith( '/dev' ):
        fields = lines[i].split()
        if len( fields ) == 1:
          fields += lines[i + 1].split()
        _disk = fields[0].replace( '/dev/sd', '' )
        partition = fields[5]
        occupancy = fields[4]
        summary += ",%s:%s" % ( partition, occupancy )
    result['DiskOccupancy'] = summary[1:]
    result['RootDiskSpace'] = Os.getDiskSpace( DIRAC.rootPath )

    # Open files
    puser = getpass.getuser()
    _status, output = commands.getstatusoutput( 'lsof' )
    pipes = 0
    files = 0
    sockets = 0
    lines = output.split( '\n' )
    for line in lines:
      fType = line.split()[4]
      user = line.split()[2]
      if user == puser:
        if fType in ['REG']:
          files += 1
        elif fType in ['unix', 'IPv4']:
          sockets += 1
        elif fType in ['FIFO']:
          pipes += 1
    result['OpenSockets'] = sockets
    result['OpenFiles'] = files
    result['OpenPipes'] = pipes

    infoResult = gComponentInstaller.getInfo( getCSExtensions() )
    if infoResult['OK']:
      result.update( infoResult['Value'] )
      # the infoResult value is {"Extensions":{'a1':'v1',a2:'v2'}; we convert to a string
      result.update( {"Extensions":";".join( ["%s:%s" % ( key, value ) for ( key, value ) in infoResult["Value"].get( 'Extensions' ).iteritems()] )} )

    # Host certificate properties
    certFile, _keyFile = getHostCertificateAndKeyLocation()
    chain = X509Chain()
    chain.loadChainFromFile( certFile )
    resultCert = chain.getCredentials()
    if resultCert['OK']:
      result['SecondsLeft'] = resultCert['Value']['secondsLeft']
      result['CertificateValidity'] = str( timedelta( seconds = resultCert['Value']['secondsLeft'] ) )
      result['CertificateDN'] = resultCert['Value']['subject']
      result['HostProperties'] = resultCert['Value']['groupProperties']
      result['CertificateIssuer'] = resultCert['Value']['issuer']

    # Host uptime
    try:
      with open( '/proc/uptime', 'r' ) as upFile:
        uptime_seconds = float( upFile.readline().split()[0] )
      result['Uptime'] = str( timedelta( seconds = uptime_seconds ) )
    except:
      pass

    return S_OK(result)
    def __readHostInfo():
        """Get host current loads, memory, etc"""

        result = dict()
        # Memory info
        re_parser = re.compile(r"^(?P<key>\S*):\s*(?P<value>\d*)\s*kB")
        for line in open("/proc/meminfo"):
            match = re_parser.match(line)
            if not match:
                continue
            key, value = match.groups(["key", "value"])
            result[key] = int(value)

        for mtype in ["Mem", "Swap"]:
            memory = int(result.get(mtype + "Total"))
            mfree = int(result.get(mtype + "Free"))
            if memory > 0:
                percentage = float(memory - mfree) / float(memory) * 100.0
            else:
                percentage = 0
            name = "Memory"
            if mtype == "Swap":
                name = "Swap"
            result[name] = "%.1f%%/%.1fMB" % (percentage, memory / 1024.0)

        # Loads
        l1, l5, l15 = (str(lx) for lx in os.getloadavg())
        result["Load1"] = l1
        result["Load5"] = l5
        result["Load15"] = l15
        result["Load"] = "/".join([l1, l5, l15])

        # CPU info
        with open("/proc/cpuinfo", "r") as fd:
            lines = fd.readlines()
            processors = 0
            physCores = {}
            for line in lines:
                if line.strip():
                    parameter, value = line.split(":")
                    parameter = parameter.strip()
                    value = value.strip()
                    if parameter.startswith("processor"):
                        processors += 1
                    if parameter.startswith("physical id"):
                        physCores[value] = parameter
                    if parameter.startswith("model name"):
                        result["CPUModel"] = value
                    if parameter.startswith("cpu MHz"):
                        result["CPUClock"] = value
            result["Cores"] = processors
            result["PhysicalCores"] = len(physCores)

        # Disk occupancy
        summary = ""
        _status, output = commands.getstatusoutput("df")
        lines = output.split("\n")
        for i in range(len(lines)):
            if lines[i].startswith("/dev"):
                fields = lines[i].split()
                if len(fields) == 1:
                    fields += lines[i + 1].split()
                partition = fields[5]
                occupancy = fields[4]
                summary += ",%s:%s" % (partition, occupancy)
        result["DiskOccupancy"] = summary[1:]
        result["RootDiskSpace"] = Os.getDiskSpace(rootPath)

        # Open files
        puser = getpass.getuser()
        _status, output = commands.getstatusoutput("lsof")
        pipes = 0
        files = 0
        sockets = 0
        lines = output.split("\n")
        for line in lines:
            fType = line.split()[4]
            user = line.split()[2]
            if user == puser:
                if fType in ["REG"]:
                    files += 1
                elif fType in ["unix", "IPv4"]:
                    sockets += 1
                elif fType in ["FIFO"]:
                    pipes += 1
        result["OpenSockets"] = sockets
        result["OpenFiles"] = files
        result["OpenPipes"] = pipes

        infoResult = gComponentInstaller.getInfo()
        if infoResult["OK"]:
            result.update(infoResult["Value"])
            # the infoResult value is {"Extensions":{'a1':'v1',a2:'v2'}; we convert to a string
            result.update({
                "Extensions":
                ";".join([
                    "%s:%s" % (key, value)
                    for (key, value
                         ) in infoResult["Value"].get("Extensions").items()
                ])
            })

        # Host certificate properties
        certFile, _keyFile = getHostCertificateAndKeyLocation()
        chain = X509Chain()
        chain.loadChainFromFile(certFile)
        resultCert = chain.getCredentials()
        if resultCert["OK"]:
            result["SecondsLeft"] = resultCert["Value"]["secondsLeft"]
            result["CertificateValidity"] = str(
                timedelta(seconds=resultCert["Value"]["secondsLeft"]))
            result["CertificateDN"] = resultCert["Value"]["subject"]
            result["CertificateIssuer"] = resultCert["Value"]["issuer"]

        # Host uptime
        result["Uptime"] = str(
            timedelta(seconds=(time.time() - psutil.boot_time())))

        return S_OK(result)
    def __readHostInfo(self):
        """ Get host current loads, memory, etc
    """

        result = dict()
        # Memory info
        re_parser = re.compile(r"^(?P<key>\S*):\s*(?P<value>\d*)\s*kB")
        for line in open("/proc/meminfo"):
            match = re_parser.match(line)
            if not match:
                continue
            key, value = match.groups(["key", "value"])
            result[key] = int(value)

        for mtype in ["Mem", "Swap"]:
            memory = int(result.get(mtype + "Total"))
            mfree = int(result.get(mtype + "Free"))
            if memory > 0:
                percentage = float(memory - mfree) / float(memory) * 100.0
            else:
                percentage = 0
            name = "Memory"
            if mtype == "Swap":
                name = "Swap"
            result[name] = "%.1f%%/%.1fMB" % (percentage, memory / 1024.0)

        # Loads
        with open("/proc/loadavg") as fd:
            line = fd.read()
            l1, l5, l15, _d1, _d2 = line.split()
        result["Load1"] = l1
        result["Load5"] = l5
        result["Load15"] = l15
        result["Load"] = "/".join([l1, l5, l15])

        # CPU info
        with open("/proc/cpuinfo", "r") as fd:
            lines = fd.readlines()
            processors = 0
            physCores = {}
            for line in lines:
                if line.strip():
                    parameter, value = line.split(":")
                    parameter = parameter.strip()
                    value = value.strip()
                    if parameter.startswith("processor"):
                        processors += 1
                    if parameter.startswith("physical id"):
                        physCores[value] = parameter
                    if parameter.startswith("model name"):
                        result["CPUModel"] = value
                    if parameter.startswith("cpu MHz"):
                        result["CPUClock"] = value
            result["Cores"] = processors
            result["PhysicalCores"] = len(physCores)

        # Disk occupancy
        summary = ""
        _status, output = commands.getstatusoutput("df")
        lines = output.split("\n")
        for i in range(len(lines)):
            if lines[i].startswith("/dev"):
                fields = lines[i].split()
                if len(fields) == 1:
                    fields += lines[i + 1].split()
                _disk = fields[0].replace("/dev/sd", "")
                partition = fields[5]
                occupancy = fields[4]
                summary += ",%s:%s" % (partition, occupancy)
        result["DiskOccupancy"] = summary[1:]
        result["RootDiskSpace"] = Os.getDiskSpace(DIRAC.rootPath)

        # Open files
        puser = getpass.getuser()
        _status, output = commands.getstatusoutput("lsof")
        pipes = 0
        files = 0
        sockets = 0
        lines = output.split("\n")
        for line in lines:
            fType = line.split()[4]
            user = line.split()[2]
            if user == puser:
                if fType in ["REG"]:
                    files += 1
                elif fType in ["unix", "IPv4"]:
                    sockets += 1
                elif fType in ["FIFO"]:
                    pipes += 1
        result["OpenSockets"] = sockets
        result["OpenFiles"] = files
        result["OpenPipes"] = pipes

        infoResult = gComponentInstaller.getInfo(getCSExtensions())
        if infoResult["OK"]:
            result.update(infoResult["Value"])

        # Host certificate properties
        certFile, _keyFile = getHostCertificateAndKeyLocation()
        chain = X509Chain()
        chain.loadChainFromFile(certFile)
        resultCert = chain.getCredentials()
        if resultCert["OK"]:
            result["SecondsLeft"] = resultCert["Value"]["secondsLeft"]
            result["CertificateValidity"] = str(timedelta(seconds=resultCert["Value"]["secondsLeft"]))
            result["CertificateDN"] = resultCert["Value"]["subject"]
            result["HostProperties"] = ",".join(resultCert["Value"]["groupProperties"])
            result["CertificateIssuer"] = resultCert["Value"]["issuer"]

        # Host uptime
        try:
            with open("/proc/uptime", "r") as upFile:
                uptime_seconds = float(upFile.readline().split()[0])
            result["Uptime"] = str(timedelta(seconds=uptime_seconds))
        except:
            pass

        return S_OK(result)