コード例 #1
0
def get(config):
    """Get GridFTP information from /etc/gridftp and ps auxf"""
    info = {}
    if not os.path.isfile('/etc/gridftp.conf'):
        info = getCurrentRunningStats(info)
        if info['active_transfers'] == 0:
            return {}
        return info
    info['app'] = "gridftp"
    info['status'] = "running"  # TODO do it automatic
    info['configuration'] = {}
    tmpOut = externalCommand('cat /etc/gridftp.conf')
    for item in tmpOut:
        for desc in item.split('\n'):
            if desc.startswith('#'):
                continue
            if not desc:
                continue
            vals = desc.split(' ', 1)
            if len(vals) == 2:
                value = vals[1].strip().split(' ')
                name = vals[0].strip()
                if name.startswith('log_'):
                    continue
                if len(value) == 2:
                    name += "_%s" % value[1]
                info['configuration'][name] = tryConvertToNumeric(value[0])
            else:
                print 'GridFTP: Skipped this item: ', vals
    info = getCurrentRunningStats(info)
    return info
コード例 #2
0
ファイル: StorageInfo.py プロジェクト: sdn-sense/siterm
def get(config, logger):
    """Get storage mount points information."""
    storageInfo = {"Values": {}}
    tmpOut = externalCommand('df -P -h')
    storageInfo, _ = parseOut(tmpOut, dict(storageInfo))
    tmpOut = externalCommand('df -i -P')
    storageInfo, _ = parseOut(tmpOut, dict(storageInfo))
    outStorage = {"FileSystems": {}, "total_gb": 0, "app": "FileSystem"}

    totalSum = 0
    for mountName, mountVals in storageInfo["Values"].items():
        outStorage["FileSystems"][mountName] = mountVals['Avail_gb']
        totalSum += int(mountVals['Avail_gb'])
    outStorage["total_gb"] = totalSum
    storageInfo["FileSystems"] = outStorage
    return storageInfo
コード例 #3
0
def get(config, logger):
    """Get System kernel parameters information."""
    kernelInfo = {}
    tmpOut = externalCommand('sysctl -a')
    for item in tmpOut:
        for desc in item.decode('UTF-8').split('\n'):
            vals = desc.split(' = ')
            if len(vals) == 2:
                kernelInfo[vals[0].strip()] = tryConvertToNumeric(
                    vals[1].strip())
            else:
                print('KernelParams: Skipped this item: ', vals)
    return kernelInfo
コード例 #4
0
def get(config):
    """Get memory info from /proc/meminfo"""
    itemOut = {}
    tmpOut = runPipedCmd(
        'ps auxf', 'grep xrootd')  # TODO if nothing running. return empty
    configFiles = []
    pids = []
    itemOut['app'] = "xrootd"
    itemOut['status'] = "running"  # TODO do it automatic
    for item in tmpOut:
        if not item:
            continue
        for desc in item.split('\n'):
            if not desc:
                continue
            vals = [val for val in desc.split() if val]
            configPos = getItemPos('-c', vals)
            if configPos == -1:
                continue
            if vals[configPos + 1] not in configFiles:
                configFiles.append(vals[configPos + 1])
                pids.append(vals[1])
    counter = -1
    itemOut['configuration'] = {}
    for fileName in configFiles:
        counter += 1
        tmpOut = externalCommand('cat %s' % fileName)
        itemOut[pids[counter]] = {}
        itemOut[pids[counter]]['Config'] = {}
        for item in tmpOut:
            for desc in item.split('\n'):
                if desc.startswith('#'):
                    continue
                if not desc:
                    continue
                vals = desc.split(' ', 1)
                if len(vals) == 1:
                    vals.append(True)
                if vals[0] == 'sec.protocol':
                    tmpvals = [val for val in vals[1].split() if val]
                    for item1 in tmpvals:
                        tmpkeyVal = [val for val in item1.split(":") if val]
                        if tmpkeyVal[0] != '-cert':
                            continue
                itemOut['configuration'][pids[counter]]['Config'][
                    vals[0]] = vals[1]
        itemOut['configuration'][pids[counter]]['UsageInfo'] = getProcInfo(
            pids[counter])
    return itemOut
コード例 #5
0
ファイル: MemInfo.py プロジェクト: sdn-sense/siterm
def get(config, logger):
    """Get memory info from /proc/meminfo."""
    memInfo = {}
    tmpOut = externalCommand('cat /proc/meminfo')
    for item in tmpOut:
        for desc in item.decode('UTF-8').split('\n'):
            vals = desc.split(':')
            if len(vals) == 2:
                value = vals[1].strip().split(' ')
                # We strip it to remove white spaces and split to remove kb in the end
                name = vals[0].strip()
                if len(value) == 2:
                    name += "_%s" % value[1]
                memInfo[name] = tryConvertToNumeric(value[0])
            else:
                print('MemInfo: Skipped this item: ', vals)
    memInfo['memory_mb'] = int(old_div(memInfo['MemTotal_kB'], 1000))
    return memInfo
コード例 #6
0
ファイル: CPUInfo.py プロジェクト: juztas/backup-siterm-agent
def get(config):
    """Get lscpu information"""
    cpuInfo = {}
    tmpOut = externalCommand('lscpu')
    for item in tmpOut:
        for desc in item.split('\n'):
            vals = desc.split(':')
            if len(vals) == 2:
                cpuInfo[vals[0].strip()] = tryConvertToNumeric(vals[1].strip())
            else:
                print 'CpuInfo: Skipped this item: ', vals
    cpuInfo['num_cores'] = 1
    if 'Socket(s)' in cpuInfo and 'Core(s) per socket':
        try:
            cpuInfo['num_cores'] = int(cpuInfo['Socket(s)']) * int(
                cpuInfo['Core(s) per socket'])
        except Exception:
            print 'Failed to calculate num_cores from %s. will set to 1' % cpuInfo
    return cpuInfo
コード例 #7
0
def get(config, logger):
    """Get all network information"""
    vlansON = getVlansOnSystem(config, logger)
    netInfo = {}
    interfaces = config.get('agent', "interfaces").split(",")
    for intf in interfaces:
        nicInfo = netInfo.setdefault(intf, {})
        vlanRange = config.get(intf, "vlans")
        vlanMin = config.get(intf, "vlan_min")
        vlanMax = config.get(intf, "vlan_max")
        switchPort = config.get(intf, "port")
        switch = config.get(intf, "switch")
        sharedInterface = config.get(intf, "shared")
        if config.has_option(intf, 'isAlias'):
            nicInfo['isAlias'] = config.get(intf, 'isAlias')
        if config.has_option(intf, "ips"):
            nicInfo['ipv4-floatingip-pool'] = config.get(intf, "ips")
        nicInfo['vlan_range'] = vlanRange
        nicInfo['min_bandwidth'] = int(vlanMin)
        nicInfo['max_bandwidth'] = int(vlanMax)
        nicInfo['switch_port'] = str(switchPort).replace('/', '_')
        nicInfo['switch'] = str(switch)
        nicInfo['shared'] = str2bool(sharedInterface)
        nicInfo['vlans'] = {}
        # TODO. It should calculate available capacity, depending on installed vlans.
        # Currently we set it same as max_bandwidth.
        nicInfo['available_bandwidth'] = int(vlanMax)  # TODO
        # TODO. It should also calculate reservable capacity depending on installed vlans;
        # Currently we set it to max available;
        nicInfo['reservable_bandwidth'] = int(vlanMax)  # TODO
    tmpifAddr = psutil.net_if_addrs()
    tmpifStats = psutil.net_if_stats()
    tmpIOCount = psutil.net_io_counters(pernic=True)
    foundInterfaces = []
    for nic, addrs in tmpifAddr.items():
        # TODO: Check with configuration of which vlans are provisioned;
        # Currently it is a hack. if it is a vlan, I assume it is provisioned by orchestrator;
        nicSplit = nic.split('.')
        nicInfo = netInfo.setdefault(nicSplit[0], {'vlans': {}})
        if len(nicSplit) == 2:
            nicInfo = nicInfo['vlans'].setdefault(nic, {})
            nicInfo['provisioned'] = True
            nicInfo['vlanid'] = nicSplit[1]
        else:
            nicInfo['provisioned'] = False
        foundInterfaces.append(nic)
        for vals in addrs:
            familyInfo = nicInfo.setdefault(str(vals.family), {})
            # vals - family=2, address='127.0.0.1', netmask='255.0.0.0', broadcast=None, ptp=None
            # For family more information look here: http://lxr.free-electrons.com/source/include/linux/socket.h#L160
            familyInfo["family"] = vals.family
            familyInfo["address"] = vals.address
            familyInfo["netmask"] = vals.netmask
            if int(vals.family) in [2, 10] and vals.address and vals.netmask:
                try:
                    ipwithnetmask = ipaddress.ip_interface(
                        u"%s/%s" % (vals.address, vals.netmask))
                    if isinstance(ipwithnetmask, ipaddress.IPv4Interface):
                        familyInfo["ipv4-address"] = str(ipwithnetmask)
                    elif isinstance(ipwithnetmask, ipaddress.IPv6Interface):
                        familyInfo["ipv6-address"] = str(ipwithnetmask)
                    else:
                        print "This type was not understood by the system. Type: %s and value: %s" %  \
                              (type(ipwithnetmask), str(ipwithnetmask))
                except ValueError as ex:
                    print 'Got an exception %s' % ex
            elif int(vals.family) in [17]:
                familyInfo["mac-address"] = vals.address
            familyInfo["broadcast"] = vals.broadcast
            familyInfo["ptp"] = vals.ptp
            # tmpifStats - snicstats(isup=True, duplex=0, speed=0, mtu=1500)
            if vals.family == 2:
                familyInfo["UP"] = tmpifStats[nic].isup
                familyInfo["duplex"] = tmpifStats[nic].duplex
                familyInfo["speed"] = tmpifStats[nic].speed
                familyInfo["MTU"] = tmpifStats[nic].mtu
                # tmpIOCount - (bytes_sent=13839798, bytes_recv=690754706, packets_sent=151186,
                #               packets_recv=630590, errin=0, errout=0, dropin=0, dropout=0)
                familyInfo["bytes_sent"] = tmpIOCount[nic].bytes_sent
                familyInfo["bytes_received"] = tmpIOCount[nic].bytes_recv
                familyInfo["packets_sent"] = tmpIOCount[nic].packets_sent
                familyInfo["packets_recv"] = tmpIOCount[nic].packets_recv
                familyInfo["errin"] = tmpIOCount[nic].errin
                familyInfo["errout"] = tmpIOCount[nic].errout
                familyInfo["dropin"] = tmpIOCount[nic].dropin
                familyInfo["dropout"] = tmpIOCount[nic].dropout
                # Additional info which is not provided by psutil so far...
                # More detail information about all types here:
                # http://lxr.free-electrons.qcom/source/include/uapi/linux/if_arp.h
                nicType = externalCommand('cat /sys/class/net/' + nic +
                                          "/type")
                familyInfo["Type"] = nicType[0].strip()
                txQueueLen = externalCommand('cat /sys/class/net/' + nic +
                                             "/tx_queue_len")
                familyInfo["txqueuelen"] = txQueueLen[0].strip()
    # Check in the end which interfaces where defined in config but not available...
    outputForFE = {"interfaces": {}, "routes": []}
    for intfName, intfDict in netInfo.iteritems():
        if intfName.split('.')[0] not in foundInterfaces:
            print 'This interface was defined in configuration, but not available. Will not add it to final output'
        else:
            outputForFE["interfaces"][intfName] = intfDict
    print vlansON
    for intfName, intfDict in netInfo.iteritems():
        if intfName.split('.')[0] == 'vlan':
            for vlankey, vlandict in intfDict['vlans'].items():
                if vlankey in vlansON.keys():
                    mainInf = vlansON[vlankey]
                    outputForFE["interfaces"].setdefault(
                        mainInf, {'vlans': {}})
                    outputForFE["interfaces"][mainInf]['vlans'][
                        vlankey] = vlandict
        else:
            print 'This interface was defined in configuration, but not available. Will not add it to final output'
            print intfName, intfDict
    # Get Routing Information
    outputForFE["routes"] = getRoutes(config)
    return outputForFE