Example #1
0
	def getMetrics(self):
		vals = parsers.splitLines(self._driver.readProc("meminfo"))
		return {
			"mem_total": ByteSize(vals.get("memtotal"), "kb"),
			"mem_free" : ByteSize(vals.get("memfree"), "kb"),
			"cached" : ByteSize(vals.get("cached"), "kb"),
			"swap_total" : ByteSize(vals.get("swaptotal"), "kb"),
			"swap_free" : ByteSize(vals.get("SwapFree"), "kb")
		}
Example #2
0
    def getMetrics(self):
        devices = parsers.splitLines(self._driver.readProc("net/dev"))

        interfaces = {}

        for d, v in devices:
            if (self._match == None or fnmatch(d, self._match)) and (
                    not self._hideEmpty or int(v[1]) > 0 or int(v[9]) > 0):
                #0,8:bytes, packets, errs, drop, fifo, frame, compressed, [multicast]
                interfaces[d] = {
                    'receive': {
                        'bytes': ByteSize(v[0]),
                        'packets': v[1],
                        'errors': v[2],
                        'drop': v[3]
                    },
                    'transmit': {
                        'bytes': ByteSize(v[8]),
                        'packets': v[9],
                        'errors': v[10],
                        'drop': v[11]
                    }
                }

        return {
            'interfaces': interfaces,
            'totals': {
                'received':
                ByteSize(
                    sum(
                        map(lambda x: int(x['receive']['bytes']),
                            interfaces.values()))),
                'transmitted':
                ByteSize(
                    sum(
                        map(lambda x: int(x['transmit']['bytes']),
                            interfaces.values())))
            }
        }
Example #3
0
    def getMetrics(self):
        df = self._driver.sh("df")

        metric = None

        #Parse and find matching metric
        for line in df['stdout'].splitlines():
            segs = line.split()
            if self._device and fnmatch(segs[0], self._device):  #mount point
                metric = segs
                break
            if self._mount and fnmatch(segs[5], self._mount):
                metric = segs
                break

        if not metric:
            return {}

        return {
            "size": ByteSize(metric[1], "kb"),
            "used": ByteSize(metric[2], "kb"),
            "available": ByteSize(metric[3], "kb"),
            "percent_full": int(metric[4][:-1])
        }
Example #4
0
	def getMetrics(self):
		shFind = ["find", "\"%s\"" % self._path, "-type", "f"]
		if self._maxDepth != None: shFind.extend(["-maxdepth", self._maxDepth])
		if self._minDepth != None: shFind.extend(["-mindepth", self._minDepth])

		cmd = str.join(' ', map(str, shFind)) + " | xargs stat -t"

		stats = self._driver.sh(cmd)

		files = stats['stdout'].splitlines()

		metrics = {
			'count': len(files),
			'files' : [],
			'oldest' : TimeSpan(0),
			'newest' : TimeSpan(0),
			'largest' : ByteSize(0),
			'smallest' : ByteSize(0),
			'size' : ByteSize(0)
		}

		for file in files:
			parts = file.split()
			if len(parts) >= 12:
				filename = parts[0]

				if self._match == None or fnmatch(filename, self._match):
					# 0 %n File name
					# 1 %s Size, bytes
					# 2 %b Numer of blocks
					# 3 %f raw mode
					# 4 %u User ID
					# 5 %g group
					# 6 %D device
					# 7 %i inode
					# 8 %h Numer of hard links
					# 9 %t Major device
					# 10 %T minor
					# 11 %X Time of last access
					# 12 %Y - last modified
					# 13 %Z - last status change
					# 14 %W file birth

					now = datetime.now()
					access_time = datetime.fromtimestamp(int(parts[11]))
					modified_time = datetime.fromtimestamp(int(parts[12]))

					metrics['files'].append({
						'path' : filename,
						'size' : ByteSize(parts[1]),
						'last_access' : access_time,
						'last_modified' : modified_time,
						'age' : TimeSpan.fromTimeDelta(now - modified_time)
					})

		if len(metrics['files']) > 0:
			metrics['oldest'] = max(map(lambda x: x['age'], metrics['files']))
			metrics['newest'] = min(map(lambda x: x['age'], metrics['files']))
			metrics['largest'] = max(map(lambda x: x['size'], metrics['files']))
			metrics['smallest'] = min(map(lambda x: x['size'], metrics['files']))
			metrics['size'] = ByteSize(sum(map(lambda x: int(x['size']), metrics['files'])))

		return metrics