Example #1
0
    def get_data(self):
        netdev = self._proc.open('net', 'dev')
        netsnmp = self._proc.open('net', 'snmp')
        netdev.readline()
        data = self._get_dev_data(netdev.read())
        sdata = self._get_snmp_data(netsnmp.read())

        data[self.node_subject] = sdata
        data = full_event_types(data, EVENT_TYPES)
        return data
    def get_data(self):
        proc = subprocess.Popen(self.command,
                                stdout = subprocess.PIPE,
                                stderr = subprocess.PIPE)
        output = proc.communicate()

        if not output[0]:
            raise CmdError(output[1])
        try:
            data = self._extract_data(output[0])
        except NonMatchingOutputError as e:
            logger.exc("get_data", e)
            return {}
        data = full_event_types(data, self.EVENT_TYPES)
        return data
Example #3
0
    def get_data(self):
        """Get general host CPU information (first line of /proc/stat)

        Return: {'user':.1, 'system':.9, 'nice':0.0, etc... }
        """

        stat_file = self._proc.open("stat")
        line = stat_file.readline()
        #timestamp=time.time() # not sure whether this goes here or
                               # just before function call
        fields = line.split()
        key = fields[0]
        v = map(int, fields[1:])

        # basic values
        cpudata = dict(zip(('user', 'nice', 'system', 'idle'), v[0:4]))
        # extended values
        if len(v) >= 7:
            cpudata.update(dict(zip(('iowait', 'hwirq', 'swirq'),
                                    v[4:7])))
        # steal and guest if available
        if len(v) >=9:
            cpudata.update(dict(zip(('steal', 'guest'), v[7:9])))
        # calculate deltas and scale
        prev_values = self._prev_cpu_hz
        prev_total = self._prev_cpu_total_hz
        total_hz = sum(v)
        total_elapsed_hz = total_hz - prev_total
        for key, value in cpudata.items():
            prev = prev_values.get(key, 0.0)
            elapsed_hz = value - prev
            if total_elapsed_hz == 0:
                cpudata[key] = 0.0
            else:
                cpudata[key] = 1.0 * elapsed_hz / total_elapsed_hz
                prev_values[key] = value # save abs. value
        (d1, d2, d3) = os.getloadavg()
        cpudata.update({"onemin":d1, "fivemin":d2, "fifteenmin":d3})
        result=full_event_types(cpudata, EVENT_TYPES)
        self._prev_cpu_hz = prev_values
        self._prev_cpu_total_hz = total_hz
        return result
Example #4
0
    def get_data(self):
        bean_counts = self._proc.exists("user_beancounters")
        meminfo = self._proc.open("meminfo")
        ans = {}
        page_size_kb=resource.getpagesize()/1024
        total = 0
        free = 0
        for line in meminfo.readlines():
            linel=line.split()
            if not linel:
                continue
            if linel[0].startswith("MemFree"):
                ans.update({"free":int(linel[1])})
                free=int(linel[1])
            elif linel[0].startswith("Buffers"):
                ans.update({"buffer":int(linel[1])})
            elif linel[0].startswith("Cached"):
                ans.update({"cache":int(linel[1])})
            elif linel[0].startswith("MemTotal"):
                total=int(linel[1])
            elif linel[0].startswith("Slab"):
                ans.update({"kernel":int(linel[1])})
        ans.update({"used":(total-free)})

        if bean_counts: # we are on a vm
            del ans["kernel"]
            del ans["cache"]
            del ans["buffer"]
            # don't delete free - turns out its pretty tough to get a notion of free
            # in an openvz container, so we'll report free for the whole machine
            for line in bean_counts:
                linel=line.split()
                if "kmemsize" in linel:
                    loc = linel.index("kmemsize")+1
                    ans.update({"kernel":int(linel[loc])/1024})
                elif "physpages" in linel:
                    loc = linel.index("physpages")+1
                    ans.update({"used":int(linel[loc])*page_size_kb})

        ans = full_event_types(ans, EVENT_TYPES)
        return ans
Example #5
0
	def get_data(self, ip):
		proc = subprocess.Popen(self.command,
								stdout = subprocess.PIPE,
								stderr = subprocess.PIPE)
		output = proc.communicate()

		if not output[0]:
			raise CmdError(output[1])
		try:
			# print " --- Obt data ---- \n"
			data = self._extract_data(output[0])
			# print data
			rtt = data.get("rtt")
			ip_rtt_pair = ip+":"+rtt
			rtt_list.append(ip_rtt_pair)
			if len(rtt_list) == 0:
				self.get_data(ip)
			self.ping_result(rtt_list)
		except NonMatchingOutputError as e:
			logger.exc("get_data", e)
			return {}
		data = full_event_types(data, self.EVENT_TYPES)
		# print data
		return data