multiprocessing retrieving several's dict data from func in

This is the place for queries that don't fit in any of the other categories.

multiprocessing retrieving several's dict data from func in

Postby tbaror » Sun Jul 28, 2013 7:04 pm

multiprocessing retrieving several's dictionary data from function in while loop

I am in process of writing a utility that doing some task/test. During that test/task i need to run in different thread/process to check current 4 subsytem cpu/mem/disk/net.

while the task is running i need to run this function constantly in while loop and in some condition i need to get back the data back which is few dictionary for every subsystem and retrieve it to main executing process or send command to write data to file ,my question is how can achieve such task if i someone would show me example will be great.

Thanks

Code: Select all
import wmi
import datetime
import json
from random import betavariate

def WmiProc():

    #Genaral Time stamp
    chars = 0
    ts = (str(datetime.datetime.now()))
    #cpu values
    values = []
    valuesque = []
    #memory values
    valmemavail = []
    valmempool = []

    #disk values

    valds_names = {}
    valds_rlatency = {}
    valds_wlatency = {}
    valds_CQL = {}
    valds_DsReByPsec = {}
    val_DsWrByPsec = {}
    val_DsRePersec = {}
    val_DskWrPersec = {}

    #network values
    val_ifnames = {}
    val_ByRePsec = {}
    val_BySePsec = {}
    val_OpQueLen = {} #OutputQueueLength
    val_PaOuDiscarded = {} #PacketsOutboundDiscarded
    val_PaOuErr ={} #PacketsOutboundErrors
    val_PaReDiscarded = {} #PacketsReceivedDiscarded
    val_PaReErr ={} #PacketsReceivedErrors
    val_PaReNonUnicastPersec = {} #PacketsReceivedNonUnicastPersec
    val_PaSeNonUnicastPersec = {} #PacketsSentNonUnicastPersec
    val_PaRePersec = {} #PacketsReceivedPersec
    val_PacSePersec = {} #PacketsSentPersec



    #Populate Disk name dictionary names
    c = wmi.WMI ()
    for d in c.Win32_PerfFormattedData_PerfDisk_PhysicalDisk ():
        valds_rlatency.update({d.Name:[]})
        valds_wlatency.update({d.Name:[]})
        valds_CQL.update({d.Name:[]})
        valds_DsReByPsec.update({d.Name:[]})
        val_DsWrByPsec.update({d.Name:[]})
        val_DsRePersec.update({d.Name:[]})
        val_DskWrPersec.update({d.Name:[]})

    #Populate Network IF names dictionary names
    for n in c.Win32_PerfFormattedData_Tcpip_NetworkInterface():

        val_ifnames.update({n.Name:n.Name})
        val_ByRePsec.update({n.Name:[]})
        val_BySePsec.update({n.Name:[]})
        val_OpQueLen.update({n.Name:[]})
        val_PaOuDiscarded.update({n.Name:[]})
        val_PaOuErr.update({n.Name:[]})
        val_PaReDiscarded.update({n.Name:[]})
        val_PaReErr.update({n.Name:[]})
        val_PaReNonUnicastPersec.update({n.Name:[]})
        val_PaSeNonUnicastPersec.update({n.Name:[]})
        val_PaRePersec.update({n.Name:[]})
        val_PacSePersec.update({n.Name:[]})

    i = 9
    while i < 10:
        #CPU Section
        for cpu in c.Win32_PerfFormattedData_PerfOS_Processor (Name ='_Total'):

            values.append(cpu.PercentProcessorTime)


        for cpuqueu in c.Win32_PerfFormattedData_PerfOS_System ():
            valuesque.append(cpuqueu.ProcessorQueueLength)

        #Memory section
        for memavail in c.Win32_PerfFormattedData_PerfOS_Memory ():
            valmemavail.append(memavail.AvailableMBytes)
            valmempool.append(memavail.PoolNonpagedBytes)

        #Disk section

        for valds in c.Win32_PerfFormattedData_PerfDisk_PhysicalDisk ():

            #AvgDisksecPerRead
            valds_rlatency[valds.Name].append(valds.AvgDisksecPerRead)

            #AvgDisksecPerWrite
            valds_wlatency[valds.Name].append(valds.AvgDisksecPerWrite)

            #CurrentDiskQueueLength
            valds_CQL[valds.Name].append(valds.CurrentDiskQueueLength)

            #DiskReadBytesPersec
            valds_DsReByPsec[valds.Name].append(valds.DiskReadBytesPersec)

            #DiskWriteBytesPersec
            val_DsWrByPsec[valds.Name].append(valds.DiskWriteBytesPersec)

            #DiskReadsPersec
            val_DsRePersec[valds.Name].append(valds.DiskReadsPersec)

            #DiskWritesPersec
            val_DskWrPersec[valds.Name].append(valds.DiskWritesPersec)

        #Network Section
        for netdt in c.Win32_PerfFormattedData_Tcpip_NetworkInterface():
            #BytesReceivedPersec
            val_ByRePsec[netdt.Name].append(netdt.BytesReceivedPersec)
            #BytesSentPersec
            val_BySePsec[netdt.Name].append(netdt.BytesSentPersec)
            #OutputQueueLength
            val_OpQueLen[netdt.Name].append(netdt.OutputQueueLength)
            #PacketsOutboundDiscarded
            val_PaOuDiscarded[netdt.Name].append(netdt.PacketsOutboundDiscarded)
            #PacketsOutboundErrors
            val_PaOuErr[netdt.Name].append(netdt.PacketsOutboundErrors)
            #PacketsReceivedDiscarded
            val_PaReDiscarded[netdt.Name].append(netdt.PacketsReceivedDiscarded)
            #PacketsReceivedErrors
            val_PaReErr[netdt.Name].append(netdt.PacketsReceivedErrors)
            #PacketsReceivedNonUnicastPersec
            val_PaReNonUnicastPersec[netdt.Name].append(netdt.PacketsReceivedNonUnicastPersec)
            #PacketsSentNonUnicastPersec
            val_PaSeNonUnicastPersec[netdt.Name].append(netdt.PacketsSentNonUnicastPersec)
            #PacketsReceivedPersec
            val_PaRePersec[netdt.Name].append(netdt.PacketsReceivedPersec)
            #PacketsSentPersec
            val_PacSePersec[netdt.Name].append(netdt.PacketsSentPersec)









if __name__ == '__main__':

    WmiProc()
tbaror
 
Posts: 13
Joined: Sun Jul 07, 2013 8:06 pm

Re: multiprocessing retrieving several's dict data from func

Postby Yoriz » Sun Jul 28, 2013 11:49 pm

The futures module will probably help you achive this.
https://pypi.python.org/pypi/futures/2.1.4 python2.7
http://docs.python.org/3/library/concur ... tures.html python3
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 871
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to General Coding Help

Who is online

Users browsing this forum: Baidu [Spider], pete1845 and 2 guests