Esempio n. 1
0
    def collectData(self):
        """Collect disk usage data.
        """

        dfre = "^([/0-9a-zA-Z]+)\s*\(([/0-9a-zA-Z])\s*\)\s*:\s*([0-9]+)\s*total allocated Kb\s*([0-9]+)\s*free allocated Kb\s*([0-9]+)\s*used allocated Kb\s*([0-9]+)\s*% allocation used"

        rawList = utils.safe_popen('df -ktffs', 'r')
        rawList.readline()  # skip header

        self.data.datahash = {}  # dict of filesystems keyed by device
        self.data.mounthash = {}  # dict of filesystems keyed by mount point

        prevline = None
        for line in rawList.readlines():
            if prevline:
                line = prevline + " " + line  # join any previous line to current
                prevline = None
            fields = string.split(line)
            if len(fields) == 1:  # if 1 field, assume rest on next line
                prevline = line
                continue
            p = df(fields)
            self.data.datahash[fields[0]] = p  # dict of filesystem devices
            self.data.mounthash[fields[5]] = p  # dict of mount points
            prevline = None

        utils.safe_pclose(rawList)

        log.log(
            "<df>dfList.collectData(): collected data for %d filesystems" %
            (len(self.data.datahash.keys())), 6)
Esempio n. 2
0
    def collectData(self):
        """
        Collect process list.
        """

        self.data.datahash = {}                # dict of processes keyed by pid
        self.data.proclist = []                # list of processes
        self.data.nameHash = {}                # dict of processes keyed by process name

        # TODO: read process info from /proc instead of parsing 'ps' output...
        #rawList = utils.safe_popen('ps -e -o "s user ruser group rgroup uid ruid gid rgid pid ppid pgid sid pri opri pcpu pmem vsz rss osz time etime stime f c tty addr nice class wchan fname comm args"', 'r')
        # remove wchan field - it sometimes causes kernel warnings
        rawList = utils.safe_popen('ps -e -o s,user,ruser,group,rgroup,uid,ruid,gid,rgid,pid,ppid,pgid,sid,pri,opri,pcpu,pmem,vsz,rss,osz,time,etime,stime,f,c,tty,addr,nice,class,fname,comm,args', 'r')
        rawList.readline()
 
        for line in rawList.readlines():
            p = proc(line)
            self.data.proclist.append(p)
            self.data.datahash[p.pid] = p
            #self.data.nameHash[string.split(p.comm, '/')[-1]] = p
            self.data.nameHash[string.split(p.procname, '/')[-1]] = p

        utils.safe_pclose( rawList )

        log.log( "<proc>procList.collectData(): new process list created", 7 )
Esempio n. 3
0
    def collectData(self):
        """Collect network interface data.
        """

        self.data.datahash = {}                # hash of same objects keyed on interface name
        self.data.numinterfaces = 0

        # get the interface packet stats
        rawList = utils.safe_popen('netstat -ind', 'r')

        for line in rawList.readlines():
            f = string.split(line)

            if len(f) != 10:
                continue                # should be 10 fields per line

            # only want lines where Address is a valid IP address
            int_re = "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
            sre = re.compile(int_re)
            inx = sre.search( f[3] )
            if inx != None:
                t = interface(f)                # new interface instance

                self.data.datahash[t.name] = t
                self.data.numinterfaces = self.data.numinterfaces + 1

        utils.safe_pclose( rawList )

        # get the interface bytes stats
        rawList = utils.safe_popen('netstat -inb', 'r')

        for line in rawList.readlines():
            f = string.split(line)

            if len(f) != 6:
                continue                # should be 6 fields per line

            # only want lines where Address is a valid IP address
            int_re = "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
            sre = re.compile(int_re)
            inx = sre.search( f[3] )
            if inx != None:
                # only want interfaces that were found above
                if f[0] in self.data.datahash.keys():
                    self.data.datahash[f[0]].interface_bytes(f)        # update interface data
                else:
                    log.log( "<netstat>IntTable.collectData(): interface mismatch in netstat -inb, %s" %(f[0]), 5 )

        utils.safe_pclose( rawList )


        log.log( "<netstat>IntTable.collectData(): Collected data for %d interfaces" %(self.data.numinterfaces), 6 )
    def collectData(self):

        #self.data.datalist = []                # list of disk objects
        self.data.datahash = {
        }  # hash of same objects keyed on device name (eg: sd100, md10)
        self.data.numdisks = 0

        if not os.path.isfile(KSTAT_CMD):
            #log.log( "<diskdevice>DiskStatistics.collectData(): No kstat command '%s'" %(KSTAT_CMD), 4 )
            raise datacollect.DataFailure, "No kstat command '%s'" % (
                KSTAT_CMD)

        # get the tcp stats
        cmd = "%s %s %s" % (KSTAT_CMD, KSTAT_ARG, self.kstat_class)
        rawList = utils.safe_popen(cmd, 'r')

        for line in rawList.readlines():
            try:
                (keys, value) = string.split(line)
            except ValueError:
                # should be 2 white-space separated fields per line
                log.log(
                    "<diskdevice>DiskStatistics.collectData(): cannot parse kstat line '%s'"
                    % (lines), 5)
                continue

            try:
                (type, index, name, key) = string.split(keys, ':')
            except ValueError:
                # should be 4 colon separated fields for keys
                log.log(
                    "<diskdevice>DiskStatistics.collectData(): cannot parse kstat keys '%s'"
                    % (keys), 5)
                continue

            try:
                # fetch already existing Disk object
                disk = self.data.datahash[name]
            except KeyError:
                # create new Disk object if needed
                disk = Disk(type, index, name)
                self.data.datahash[name] = disk
                #self.data.datalist.append( disk )
                self.data.numdisks = self.data.numdisks + 1

            disk.setStat(key, value)

        utils.safe_pclose(rawList)

        log.log(
            "<diskdevice>DiskStatistics.collectData(): Collected stats for %d disks"
            % (self.data.numdisks), 6)