"""
return self.BOLD_SEQ + msg + self.RESET_SEQ
- def format_dimless(self, n, width, colored=True):
+ def format_units(self, n, width, colored, decimal):
"""
Format a number without units, so as to fit into `width` characters, substituting
an appropriate unit suffix.
+
+ Use decimal for dimensionless things, use base 2 (decimal=False) for byte sizes/rates.
"""
+
+ factor = 1000 if decimal else 1024
units = [' ', 'k', 'M', 'G', 'T', 'P']
unit = 0
- while len("%s" % (int(n) // (1000**unit))) > width - 1:
+ while len("%s" % (int(n) // (factor**unit))) > width - 1:
unit += 1
if unit > 0:
- truncated_float = ("%f" % (n / (1000.0 ** unit)))[0:width - 1]
+ truncated_float = ("%f" % (n / (float(factor) ** unit)))[0:width - 1]
if truncated_float[-1] == '.':
truncated_float = " " + truncated_float[0:-1]
else:
else:
return formatted
+ def format_dimless(self, n, width, colored=True):
+ return self.format_units(n, width, colored, decimal=True)
+
+ def format_bytes(self, n, width, colored=True):
+ return self.format_units(n, width, colored, decimal=False)
+
def get_latest(self, daemon_type, daemon_name, stat):
data = self.get_counter(daemon_type, daemon_name, stat)[stat]
#self.log.error("get_latest {0} data={1}".format(stat, data))
else:
rank_table.add_row([
- rank, "failed", "", "", ""
+ rank, "failed", "", "", "", ""
])
# Find the standby replays
stats = pool_stats[pool_id]
pools_table.add_row([
pools[pool_id]['pool_name'], pool_type,
- self.format_dimless(stats['bytes_used'], 5),
- self.format_dimless(stats['max_avail'], 5)
+ self.format_bytes(stats['bytes_used'], 5),
+ self.format_bytes(stats['max_avail'], 5)
])
output += "{0} - {1} clients\n".format(
return 0, "", output
def handle_osd_status(self, cmd):
- osd_table = PrettyTable(['id', 'host', 'used', 'avail', 'wr ops', 'wr data', 'rd ops', 'rd data'])
+ osd_table = PrettyTable(['id', 'host', 'used', 'avail', 'wr ops', 'wr data', 'rd ops', 'rd data', 'state'])
osdmap = self.get("osd_map")
filter_osds = set()
if bucket_filter and osd_id not in filter_osds:
continue
- metadata = self.get_metadata('osd', "%s" % osd_id)
- stats = osd_stats[osd_id]
+ hostname = ""
+ kb_used = 0
+ kb_avail = 0
+
+ if osd_id in osd_stats:
+ metadata = self.get_metadata('osd', "%s" % osd_id)
+ stats = osd_stats[osd_id]
+ hostname = metadata['hostname']
+ kb_used = stats['kb_used'] * 1024
+ kb_avail = stats['kb_avail'] * 1024
- osd_table.add_row([osd_id, metadata['hostname'],
- self.format_dimless(stats['kb_used'] * 1024, 5),
- self.format_dimless(stats['kb_avail'] * 1024, 5),
+ osd_table.add_row([osd_id, hostname,
+ self.format_bytes(kb_used, 5),
+ self.format_bytes(kb_avail, 5),
self.format_dimless(self.get_rate("osd", osd_id.__str__(), "osd.op_w") +
self.get_rate("osd", osd_id.__str__(), "osd.op_rw"), 5),
- self.format_dimless(self.get_rate("osd", osd_id.__str__(), "osd.op_in_bytes"), 5),
+ self.format_bytes(self.get_rate("osd", osd_id.__str__(), "osd.op_in_bytes"), 5),
self.format_dimless(self.get_rate("osd", osd_id.__str__(), "osd.op_r"), 5),
- self.format_dimless(self.get_rate("osd", osd_id.__str__(), "osd.op_out_bytes"), 5),
+ self.format_bytes(self.get_rate("osd", osd_id.__str__(), "osd.op_out_bytes"), 5),
+ ','.join(osd['state']),
])
return 0, "", osd_table.get_string()