예제 #1
0
	def __elapse(self):
		if self.__timer == 0:
			for m in self.__env.HOSTS:
				self.__scr.writeFooter(_("Loading ..."))
				self.__scr.refresh()
				try:
					self.__cpu_num[m] = Utils.safeInt(Data.getRRD("%s/%s/cpu_num.rrd" % (self.__env.DATADIR, m))[-1][1])
					self.__cpu_speed[m] = Utils.safeFloat(Data.getRRD("%s/%s/cpu_speed.rrd" % (self.__env.DATADIR, m))[-1][1])
					self.__cpu_user[m] = Data.getRRD("%s/%s/cpu_user.rrd" % (self.__env.DATADIR, m))
					self.__cpu_system[m] = Data.getRRD("%s/%s/cpu_system.rrd" % (self.__env.DATADIR, m))

					self.__mem_buffers[m] = Data.getRRD("%s/%s/mem_buffers.rrd" % (self.__env.DATADIR, m))
					self.__mem_cached[m] = Data.getRRD("%s/%s/mem_cached.rrd" % (self.__env.DATADIR, m))
					self.__mem_free[m] = Data.getRRD("%s/%s/mem_free.rrd" % (self.__env.DATADIR, m))
					self.__mem_total[m] = Data.getRRD("%s/%s/mem_total.rrd" % (self.__env.DATADIR, m))

					self.__cpu_topuser[m] = Data.getProcData("%s/%s/cpu_topuser" % (self.__env.DATADIR, m))
					self.__mem_topuser[m] = Data.getProcData("%s/%s/mem_topuser" % (self.__env.DATADIR, m))
				except ElementTree.ParseError:
					return False
				except IOError:
					return False

			self.__redraw = True

		# go ahead
		self.__timer += 1
		if self.__timer >= self.__options.interval * 1000 // Screen.timeout():
			self.__timer = 0

		return True
예제 #2
0
    def __elapse(self):
        if self.__timer == 0:
            for m in self.__env.HOSTS:
                self.__scr.writeFooter(_("Loading ..."))
                self.__scr.refresh()
                try:
                    self.__cpu_num[m] = Utils.safeInt(
                        Data.getRRD("%s/%s/cpu_num.rrd" %
                                    (self.__env.DATADIR, m))[-1][1])
                    self.__cpu_speed[m] = Utils.safeFloat(
                        Data.getRRD("%s/%s/cpu_speed.rrd" %
                                    (self.__env.DATADIR, m))[-1][1])
                    self.__cpu_user[m] = Data.getRRD("%s/%s/cpu_user.rrd" %
                                                     (self.__env.DATADIR, m))
                    self.__cpu_system[m] = Data.getRRD("%s/%s/cpu_system.rrd" %
                                                       (self.__env.DATADIR, m))

                    self.__mem_buffers[m] = Data.getRRD(
                        "%s/%s/mem_buffers.rrd" % (self.__env.DATADIR, m))
                    self.__mem_cached[m] = Data.getRRD("%s/%s/mem_cached.rrd" %
                                                       (self.__env.DATADIR, m))
                    self.__mem_free[m] = Data.getRRD("%s/%s/mem_free.rrd" %
                                                     (self.__env.DATADIR, m))
                    self.__mem_total[m] = Data.getRRD("%s/%s/mem_total.rrd" %
                                                      (self.__env.DATADIR, m))

                    self.__cpu_topuser[m] = Data.getProcData(
                        "%s/%s/cpu_topuser" % (self.__env.DATADIR, m))
                    self.__mem_topuser[m] = Data.getProcData(
                        "%s/%s/mem_topuser" % (self.__env.DATADIR, m))
                except ElementTree.ParseError:
                    return False
                except IOError:
                    return False

            self.__redraw = True

        # go ahead
        self.__timer += 1
        if self.__timer >= self.__options.interval * 1000 // Screen.timeout():
            self.__timer = 0

        return True
예제 #3
0
	def __drawStatus(self, x, y, current, step, hostname):

		# variables
		cpu_user    = self.__cpu_user[hostname]
		cpu_system  = self.__cpu_system[hostname]
		cpu_num     = self.__cpu_num[hostname]
		cpu_speed   = self.__cpu_speed[hostname]
		cpu_topuser = self.__cpu_topuser[hostname]
		mem_free    = self.__mem_free[hostname]
		mem_buffers = self.__mem_buffers[hostname]
		mem_cached  = self.__mem_cached[hostname]
		mem_total   = self.__mem_total[hostname]
		mem_topuser = self.__mem_topuser[hostname]

		# utilities
		hspace = ' ' * self.__chart_w
		hline = '-' * self.__chart_w
		rowText = lambda l, r, sep: sep + l + sep + r + sep # ex. '|@@@@|####|'

		cpu_title = "cpu (%d * %sHz)" % (cpu_num, (("%.1fG" % (cpu_speed / 1000)) if cpu_speed >= 1000 else ("%.1fM" % cpu_speed)))
		mem_title = "mem (%siB)" % (("%.1fG" % (mem_total[-1][1] / 1024 / 1024)) if mem_total[-1][1] >= 1024 else ("%.1fM" % (mem_total[-1][1] / 1024)))
		cpu_title = cpu_title[:self.__chart_w]
		mem_title = mem_title[:self.__chart_w]

		self.__scr.write(y + 1, x, rowText(hspace, hspace, ' '))
		self.__scr.write(y + 1, x + 1, cpu_title.center(self.__chart_w))
		self.__scr.write(y + 1, x + self.__chart_w + 2, mem_title.center(self.__chart_w))
		self.__scr.write(y + 2, x, rowText(hline, hline, '|'))

		for i in range(self.__chart_h):
			self.__scr.write(y + 3 + i, x, rowText(hspace, hspace, '|'))
			
		self.__scr.write(y + 3 + self.__chart_h, x, rowText(hline, hline, '|'))
		
		for j in range(self.__chart_w):
			val1 = Data.getRRDValue(cpu_system, current + (j - self.__chart_w + 1) * step, step)
			val2 = Data.getRRDValue(cpu_user, current + (j - self.__chart_w + 1) * step, step)
			if val1 < 0 or val2 < 0:
				for i in range(self.__chart_h):
					self.__scr.write(y + 3 + i, x + 1 + j, "?")
				continue
			val2 += val1

			for i in range(self.__chart_h):
				if val2 > i / self.__chart_h * 100:
					self.__scr.write(y + self.__chart_h + 2 - i, x + 1 + j, "#", 'USER')
			for i in range(self.__chart_h):
				if val1 > i / self.__chart_h * 100:
					self.__scr.write(y + self.__chart_h + 2 - i, x + 1 + j, "@", 'SYSTEM')

		i = 0

		if self.__showusers:
			self.__scr.write(y + 4 + self.__chart_h, x, rowText(hspace, hspace, '|'))
			self.__scr.write(y + 5 + self.__chart_h, x, rowText(hspace, hspace, '|'))
			self.__scr.write(y + 6 + self.__chart_h, x, rowText(hline, hline, '|'))

			for u in cpu_topuser:
				mu = u[:]
				mu[1] += "%"
				mu[2] = mu[2].split("/")[-1]
				s = " ".join(mu)
				self.__scr.write(y + self.__chart_h + 4 + i, x + 2, s[:self.__chart_w - 2])
				i += 1

		for j in range(self.__chart_w):
			total = Data.getRRDValue(mem_total, current + (j - self.__chart_w + 1) * step, step)
			val1 = Data.getRRDValue(mem_free, current + (j - self.__chart_w + 1) * step, step)
			val2 = Data.getRRDValue(mem_cached, current + (j - self.__chart_w + 1) * step, step)
			val3 = Data.getRRDValue(mem_buffers, current + (j - self.__chart_w + 1) * step, step)
			if total <= 0 or val1 < 0 or val2 < 0 or val3 < 0:
				for i in range(self.__chart_h):
					self.__scr.write(y + 3 + i, x + self.__chart_w + 2 + j, "?")
				continue

			used = (total - val1) / total
			active = used - (val2 - val3) / total
			
			for i in range(self.__chart_h):
				r = (self.__chart_h - i) / self.__chart_h
				if r < active:
					self.__scr.write(y + 3 + i, x + self.__chart_w + 2 + j, "#", 'USER')
				elif r < used:
					self.__scr.write(y + 3 + i, x + self.__chart_w + 2 + j, ".", 'CACHE')
	
		i = 0

		if self.__showusers:
			for u in mem_topuser:
				mu = u[:]
				mu[1] += "%"
				mu[2] = mu[2].split("/")[-1]
				s = " ".join(mu)
				self.__scr.write(y + self.__chart_h + 4 + i, x + self.__chart_w + 3, s[:self.__chart_w - 2])
				i += 1
예제 #4
0
    def __drawStatus(self, x, y, current, step, hostname):

        # variables
        cpu_user = self.__cpu_user[hostname]
        cpu_system = self.__cpu_system[hostname]
        cpu_num = self.__cpu_num[hostname]
        cpu_speed = self.__cpu_speed[hostname]
        cpu_topuser = self.__cpu_topuser[hostname]
        mem_free = self.__mem_free[hostname]
        mem_buffers = self.__mem_buffers[hostname]
        mem_cached = self.__mem_cached[hostname]
        mem_total = self.__mem_total[hostname]
        mem_topuser = self.__mem_topuser[hostname]

        # utilities
        hspace = ' ' * self.__chart_w
        hline = '-' * self.__chart_w
        rowText = lambda l, r, sep: sep + l + sep + r + sep  # ex. '|@@@@|####|'

        cpu_title = "cpu (%d * %sHz)" % (cpu_num, (
            ("%.1fG" % (cpu_speed / 1000)) if cpu_speed >= 1000 else
            ("%.1fM" % cpu_speed)))
        mem_title = "mem (%siB)" % (
            ("%.1fG" %
             (mem_total[-1][1] / 1024 / 1024)) if mem_total[-1][1] >= 1024 else
            ("%.1fM" % (mem_total[-1][1] / 1024)))
        cpu_title = cpu_title[:self.__chart_w]
        mem_title = mem_title[:self.__chart_w]

        self.__scr.write(y + 1, x, rowText(hspace, hspace, ' '))
        self.__scr.write(y + 1, x + 1, cpu_title.center(self.__chart_w))
        self.__scr.write(y + 1, x + self.__chart_w + 2,
                         mem_title.center(self.__chart_w))
        self.__scr.write(y + 2, x, rowText(hline, hline, '|'))

        for i in range(self.__chart_h):
            self.__scr.write(y + 3 + i, x, rowText(hspace, hspace, '|'))

        self.__scr.write(y + 3 + self.__chart_h, x, rowText(hline, hline, '|'))

        for j in range(self.__chart_w):
            val1 = Data.getRRDValue(cpu_system,
                                    current + (j - self.__chart_w + 1) * step,
                                    step)
            val2 = Data.getRRDValue(cpu_user,
                                    current + (j - self.__chart_w + 1) * step,
                                    step)
            if val1 < 0 or val2 < 0:
                for i in range(self.__chart_h):
                    self.__scr.write(y + 3 + i, x + 1 + j, "?")
                continue
            val2 += val1

            for i in range(self.__chart_h):
                if val2 > i / self.__chart_h * 100:
                    self.__scr.write(y + self.__chart_h + 2 - i, x + 1 + j,
                                     "#", 'USER')
            for i in range(self.__chart_h):
                if val1 > i / self.__chart_h * 100:
                    self.__scr.write(y + self.__chart_h + 2 - i, x + 1 + j,
                                     "@", 'SYSTEM')

        i = 0

        if self.__showusers:
            self.__scr.write(y + 4 + self.__chart_h, x,
                             rowText(hspace, hspace, '|'))
            self.__scr.write(y + 5 + self.__chart_h, x,
                             rowText(hspace, hspace, '|'))
            self.__scr.write(y + 6 + self.__chart_h, x,
                             rowText(hline, hline, '|'))

            for u in cpu_topuser:
                mu = u[:]
                mu[1] += "%"
                mu[2] = mu[2].split("/")[-1]
                s = " ".join(mu)
                self.__scr.write(y + self.__chart_h + 4 + i, x + 2,
                                 s[:self.__chart_w - 2])
                i += 1

        for j in range(self.__chart_w):
            total = Data.getRRDValue(mem_total,
                                     current + (j - self.__chart_w + 1) * step,
                                     step)
            val1 = Data.getRRDValue(mem_free,
                                    current + (j - self.__chart_w + 1) * step,
                                    step)
            val2 = Data.getRRDValue(mem_cached,
                                    current + (j - self.__chart_w + 1) * step,
                                    step)
            val3 = Data.getRRDValue(mem_buffers,
                                    current + (j - self.__chart_w + 1) * step,
                                    step)
            if total <= 0 or val1 < 0 or val2 < 0 or val3 < 0:
                for i in range(self.__chart_h):
                    self.__scr.write(y + 3 + i, x + self.__chart_w + 2 + j,
                                     "?")
                continue

            used = (total - val1) / total
            active = used - (val2 - val3) / total

            for i in range(self.__chart_h):
                r = (self.__chart_h - i) / self.__chart_h
                if r < active:
                    self.__scr.write(y + 3 + i, x + self.__chart_w + 2 + j,
                                     "#", 'USER')
                elif r < used:
                    self.__scr.write(y + 3 + i, x + self.__chart_w + 2 + j,
                                     ".", 'CACHE')

        i = 0

        if self.__showusers:
            for u in mem_topuser:
                mu = u[:]
                mu[1] += "%"
                mu[2] = mu[2].split("/")[-1]
                s = " ".join(mu)
                self.__scr.write(y + self.__chart_h + 4 + i,
                                 x + self.__chart_w + 3,
                                 s[:self.__chart_w - 2])
                i += 1