def check_zpool_iostat(cmd): """查看存储池读写负载""" # cmd = "zpool iostat 1 3 | grep '_pool'" content = ["CHECK ZPOOL IOSTAT"] sub = SubProcess(cmd) for line in sub.readlines(): line = line.strip('\n') line_list = line.split(' ') line_list = [x for x in line_list if x] if len(line_list) != 7: content.append("check error!!!") content.append("After separate line, the element count is not 7.") break bandwidth_read, bandwidth_write = line_list[5:] match_read = re.match(r"([0-9,.]+)M", bandwidth_read) match_write = re.match(r"([0-9,.]+)M", bandwidth_write) if match_read: read_value = match_read.groups()[0] if float(read_value) > 300: content.append(line) continue if match_write: write_value = match_write.groups()[0] if float(write_value) > 500: content.append(line) __print_output(content)
def check_system_memory(): """查看系统内存使用百分比""" content = ["SYSTEM FREE MEMORY"] if system_info.memory_available() < 1: cmd = "free -h" sub = SubProcess(cmd) content.append(sub.read()) __print_output(content)
def main(): cmd = "zpool get all | grep metadata | awk '{print $1,$2,$3,$4}'" sub = SubProcess(cmd) data = OrderedDict() for line in sub.readlines(): d = line.rstrip().split(' ') pool_name, metadata_type, value = d[0:3] if not data.has_key(pool_name): data[pool_name] = {} data[pool_name].update({metadata_type: value}) new_data = __format_data(data) return new_data
def search_file(): """执行搜索文件任务""" for date in date_list: new_cmd = "tail -n {num} {file} | grep '{date}' | {cmd} | tail -n 5".format( num=line_num, file=file, date=date, cmd=cmd ) sub = SubProcess(new_cmd) for line in sub.readlines(): content.append(line.strip('\n')) __print_output(content)
def check_core_dump(path, before_day=3): """查看是否存在core dump错误""" content = ["CHECK COREDUMP"] if not os.path.exists(path): print "Directory %s not exists!!!" % path else: cmd = "find {path} -mtime -{before_day} -ls | grep -v '{path}'".format( path=path, before_day=before_day ) sub = SubProcess(cmd) for line in sub.readlines(): content.append(line.strip('\n')) __print_output(content)
def __init__(self, core, num_files=6): SubProcess.__init__(self, core) self.num_files = num_files # check if needed fname = self.core.fname_sublink_short() exists = os.path.exists(fname) print("File '{}' exists: {}".format(fname, exists)) self.needed = True if exists: with h5py.File(fname, 'r') as f: keys = list(f) if 'Descendant_index' in keys: print( '\tSublinkIndexFind descendant indices already added to sublink_short.' ) self.needed = False
def get_disk_info(cmd): """获取磁盘信息""" pool_name, raid_name = None, None sub = SubProcess(cmd) for line in sub.readlines(): # 匹配pool行:'\tpool3 ONLINE 0 0 0\n' match_pool = __match_line( line, '^\t[\w]*pool[\w]*\s+[A-Z]+\s+\d+\s+\d+\s+\d+$') if match_pool: TOTAL['pool_count'] += 1 pool_name = match_pool['name'] continue # 匹配raid行:'\t raidz2-0 ONLINE 0 0 0\n' match_raid = __match_line(line, '^\t\s+raid.+\s+[A-Z]+\s+\d+\s+\d+\s+\d+$') if match_raid: TOTAL['raid_count'] += 1 raid_name = match_raid['name'] continue data_type = "Data Disk" # 匹配metadata行:\t metadata:mirror-2 ONLINE 0 0 0\n' match_metadata = __match_line( line, '^\t\s+raid.+\s+[A-Z]+\s+\d+\s+\d+\s+\d+$') if match_metadata: data_type = "Metadata Disk" continue # 匹配磁盘行:'\t 63301357-8a79-4ce1-953e-dbd857cc1e23 ONLINE 0 0 0\n' match_disk = __match_line( line, '^\t\s+[\w-]+\s+[A-Z]+\s+\d+\s+\d+\s+\d+.*$') if match_disk: TOTAL['disk_count'] += 1 check_disk(match_disk, pool_name, raid_name, data_type) return ERROR_DISKS, TOTAL
def check_pool_usage(): """查看存储池使用百分比""" content = ["STORAGE POOL USAGE"] cmd = "df -h | grep 'pool' | awk '{print $6}'" sub = SubProcess(cmd) for pool_name in sub.readlines(): pool_name = pool_name.strip('\n') if system_info.disk_percent(pool_name) > 95: sub = SubProcess("df -h | grep {}".format(pool_name)) content.append(sub.read().strip('\n')) __print_output(content)