def main(): """zfsiostats main loop""" global signal_received collection_interval = DEFAULT_COLLECTION_INTERVAL report_capacity_every_x_times = DEFAULT_REPORT_CAPACITY_EVERY_X_TIMES if (zfsiostats_conf): config = zfsiostats_conf.get_config() collection_interval = config['collection_interval'] report_capacity_every_x_times = config['report_capacity_every_x_times'] signal.signal(signal.SIGTERM, handlesignal) signal.signal(signal.SIGINT, handlesignal) try: p_zpool = subprocess.Popen( ["zpool", "iostat", "-v", str(collection_interval)], stdout=subprocess.PIPE, ) except OSError, e: if e.errno == errno.ENOENT: # it makes no sense to run this collector here sys.exit(13) # we signal tcollector to not run us raise
def main(): """zfsiostats main loop""" global signal_received collection_interval=DEFAULT_COLLECTION_INTERVAL report_capacity_every_x_times=DEFAULT_REPORT_CAPACITY_EVERY_X_TIMES report_disks_in_vdevs=DEFAULT_REPORT_DISKS_IN_VDEVS if(zfsiostats_conf): config = zfsiostats_conf.get_config() collection_interval=config['collection_interval'] report_capacity_every_x_times=config['report_capacity_every_x_times'] report_disks_in_vdevs=config['report_disks_in_vdevs'] signal.signal(signal.SIGTERM, handlesignal) signal.signal(signal.SIGINT, handlesignal) try: p_zpool = subprocess.Popen( ["zpool", "iostat", "-v", str(collection_interval)], stdout=subprocess.PIPE, ) except OSError, e: if e.errno == errno.ENOENT: # it makes no sense to run this collector here sys.exit(13) # we signal tcollector to not run us raise
def main(): """zfsiostats main loop""" global signal_received collection_interval=DEFAULT_COLLECTION_INTERVAL if(zfsiostats_conf): config = zfsiostats_conf.get_config() collection_interval=config['collection_interval'] signal.signal(signal.SIGTERM, handlesignal) signal.signal(signal.SIGINT, handlesignal) try: p_zpool = subprocess.Popen( ["zpool", "iostat", "-v", str(collection_interval)], stdout=subprocess.PIPE, ) except OSError, e: if e.errno == errno.ENOENT: # it makes no sense to run this collector here sys.exit(13) # we signal tcollector to not run us raise
def main(): """zfsiostats main loop""" global signal_received collection_interval = DEFAULT_COLLECTION_INTERVAL report_capacity_every_x_times = DEFAULT_REPORT_CAPACITY_EVERY_X_TIMES report_disks_in_vdevs = DEFAULT_REPORT_DISKS_IN_VDEVS if (zfsiostats_conf): config = zfsiostats_conf.get_config() collection_interval = config['collection_interval'] report_capacity_every_x_times = config['report_capacity_every_x_times'] report_disks_in_vdevs = config['report_disks_in_vdevs'] signal.signal(signal.SIGTERM, handlesignal) signal.signal(signal.SIGINT, handlesignal) try: p_zpool = subprocess.Popen( ["zpool", "iostat", "-v", str(collection_interval)], stdout=subprocess.PIPE, ) except OSError as e: if e.errno == errno.ENOENT: # it makes no sense to run this collector here sys.exit(13) # we signal tcollector to not run us raise firstloop = True report_capacity = (report_capacity_every_x_times - 1) lastleg = 0 ltype = None timestamp = int(time.time()) capacity_stats_pool = {} capacity_stats_device = {} io_stats_pool = {} io_stats_device = {} start_re = re.compile(".*capacity.*operations.*bandwidth") headers_re = re.compile(".*pool.*alloc.*free.*read.*write.*read.*write") separator_re = re.compile(".*-----.*-----.*-----") while signal_received is None: try: line = p_zpool.stdout.readline() except (IOError, OSError) as e: if e.errno in (errno.EINTR, errno.EAGAIN): break raise if not line: # end of the program, die break if start_re.match(line): assert ltype in (None, T_EMPTY), \ "expecting last state T_EMPTY or None, now got %s" % ltype ltype = T_START elif headers_re.match(line): assert ltype == T_START, \ "expecting last state T_START, now got %s" % ltype ltype = T_HEADERS elif separator_re.match(line): assert ltype in (T_DEVICE, T_HEADERS), \ "expecting last state T_DEVICE or T_HEADERS, now got %s" % ltype ltype = T_SEPARATOR elif len(line) < 2: assert ltype == T_SEPARATOR, \ "expecting last state T_SEPARATOR, now got %s" % ltype ltype = T_EMPTY elif line.startswith(" mirror"): assert ltype in (T_POOL, T_DEVICE), \ "expecting last state T_POOL or T_DEVICE, now got %s" % ltype ltype = T_LEG elif line.startswith(" "): assert ltype in (T_POOL, T_DEVICE, T_LEG), \ "expecting last state T_POOL or T_DEVICE or T_LEG, now got %s" % ltype ltype = T_DEVICE else: # must be a pool name #assert ltype == T_SEPARATOR, \ # "expecting last state T_SEPARATOR, now got %s" % ltype if ltype == T_SEPARATOR: parentpoolname = "" ltype = T_POOL if ltype == T_START: for x in ( capacity_stats_pool, capacity_stats_device, io_stats_pool, io_stats_device, ): x.clear() timestamp = int(time.time()) elif ltype == T_POOL: line = line.strip() poolname, s_df, s_io = extract_info(line, report_disks_in_vdevs) if parentpoolname == "": parentpoolname = poolname else: poolname = parentpoolname + "." + poolname capacity_stats_pool[poolname] = s_df io_stats_pool[poolname] = s_io # marker for leg last_leg = 0 elif ltype == T_LEG: last_leg = last_leg + 1 line = line.strip() devicename, s_df, s_io = extract_info(line, report_disks_in_vdevs) capacity_stats_device["%s %s%s" % (poolname, devicename, last_leg)] = s_df io_stats_device["%s %s%s" % (poolname, devicename, last_leg)] = s_io elif ltype == T_DEVICE: line = line.strip() devicename, s_df, s_io = extract_info(line, report_disks_in_vdevs) capacity_stats_device["%s %s" % (poolname, devicename)] = s_df io_stats_device["%s %s" % (poolname, devicename)] = s_io elif ltype == T_EMPTY: if report_capacity_every_x_times > 0: report_capacity += 1 if report_capacity == report_capacity_every_x_times: report_capacity = 0 for poolname, stats in capacity_stats_pool.items(): fm = "zfs.df.pool.kb.%s %d %s pool=%s" for statname, statnumber in stats.items(): print(fm % (statname, timestamp, statnumber, poolname)) for devicename, stats in capacity_stats_device.items(): fm = "zfs.df.device.kb.%s %d %s device=%s pool=%s" poolname, devicename = devicename.split(" ", 1) for statname, statnumber in stats.items(): print(fm % (statname, timestamp, statnumber, devicename, poolname)) if firstloop: # this flag prevents printing out of the data in the first loop # which is a since-boot summary similar to iostat # and is useless to us firstloop = False else: for poolname, stats in io_stats_pool.items(): fm = "zfs.io.pool.%s %d %s pool=%s" for statname, statnumber in stats.items(): print(fm % (statname, timestamp, statnumber, poolname)) for devicename, stats in io_stats_device.items(): fm = "zfs.io.device.%s %d %s device=%s pool=%s" poolname, devicename = devicename.split(" ", 1) for statname, statnumber in stats.items(): print(fm % (statname, timestamp, statnumber, devicename, poolname)) sys.stdout.flush() if signal_received is None: signal_received = signal.SIGTERM try: os.kill(p_zpool.pid, signal_received) except Exception: pass p_zpool.wait()
def main(): """zfsiostats main loop""" global signal_received collection_interval=DEFAULT_COLLECTION_INTERVAL report_capacity_every_x_times=DEFAULT_REPORT_CAPACITY_EVERY_X_TIMES report_disks_in_vdevs=DEFAULT_REPORT_DISKS_IN_VDEVS if(zfsiostats_conf): config = zfsiostats_conf.get_config() collection_interval=config['collection_interval'] report_capacity_every_x_times=config['report_capacity_every_x_times'] report_disks_in_vdevs=config['report_disks_in_vdevs'] signal.signal(signal.SIGTERM, handlesignal) signal.signal(signal.SIGINT, handlesignal) try: p_zpool = subprocess.Popen( ["zpool", "iostat", "-v", str(collection_interval)], stdout=subprocess.PIPE, ) except OSError as e: if e.errno == errno.ENOENT: # it makes no sense to run this collector here sys.exit(13) # we signal tcollector to not run us raise firstloop = True report_capacity = (report_capacity_every_x_times-1) lastleg = 0 ltype = None timestamp = int(time.time()) capacity_stats_pool = {} capacity_stats_device = {} io_stats_pool = {} io_stats_device = {} start_re = re.compile(".*capacity.*operations.*bandwidth") headers_re = re.compile(".*pool.*alloc.*free.*read.*write.*read.*write") separator_re = re.compile(".*-----.*-----.*-----") while signal_received is None: try: line = p_zpool.stdout.readline() except (IOError, OSError) as e: if e.errno in (errno.EINTR, errno.EAGAIN): break raise if not line: # end of the program, die break if start_re.match(line): assert ltype in (None, T_EMPTY), \ "expecting last state T_EMPTY or None, now got %s" % ltype ltype = T_START elif headers_re.match(line): assert ltype == T_START, \ "expecting last state T_START, now got %s" % ltype ltype = T_HEADERS elif separator_re.match(line): assert ltype in (T_DEVICE, T_HEADERS), \ "expecting last state T_DEVICE or T_HEADERS, now got %s" % ltype ltype = T_SEPARATOR elif len(line) < 2: assert ltype == T_SEPARATOR, \ "expecting last state T_SEPARATOR, now got %s" % ltype ltype = T_EMPTY elif line.startswith(" mirror"): assert ltype in (T_POOL, T_DEVICE), \ "expecting last state T_POOL or T_DEVICE, now got %s" % ltype ltype = T_LEG elif line.startswith(" "): assert ltype in (T_POOL, T_DEVICE, T_LEG), \ "expecting last state T_POOL or T_DEVICE or T_LEG, now got %s" % ltype ltype = T_DEVICE else: # must be a pool name #assert ltype == T_SEPARATOR, \ # "expecting last state T_SEPARATOR, now got %s" % ltype if ltype == T_SEPARATOR: parentpoolname = "" ltype = T_POOL if ltype == T_START: for x in ( capacity_stats_pool, capacity_stats_device, io_stats_pool, io_stats_device, ): x.clear() timestamp = int(time.time()) elif ltype == T_POOL: line = line.strip() poolname, s_df, s_io = extract_info(line,report_disks_in_vdevs) if parentpoolname == "": parentpoolname = poolname else: poolname=parentpoolname+"."+poolname capacity_stats_pool[poolname] = s_df io_stats_pool[poolname] = s_io # marker for leg last_leg = 0 elif ltype == T_LEG: last_leg = last_leg + 1 line = line.strip() devicename, s_df, s_io = extract_info(line,report_disks_in_vdevs) capacity_stats_device["%s %s%s" % (poolname, devicename, last_leg)] = s_df io_stats_device["%s %s%s" % (poolname, devicename, last_leg)] = s_io elif ltype == T_DEVICE: line = line.strip() devicename, s_df, s_io = extract_info(line,report_disks_in_vdevs) capacity_stats_device["%s %s" % (poolname, devicename)] = s_df io_stats_device["%s %s" % (poolname, devicename)] = s_io elif ltype == T_EMPTY: if report_capacity_every_x_times > 0: report_capacity += 1 if report_capacity == report_capacity_every_x_times: report_capacity=0 for poolname, stats in capacity_stats_pool.items(): fm = "zfs.df.pool.kb.%s %d %s pool=%s" for statname, statnumber in stats.items(): print(fm % (statname, timestamp, statnumber, poolname)) for devicename, stats in capacity_stats_device.items(): fm = "zfs.df.device.kb.%s %d %s device=%s pool=%s" poolname, devicename = devicename.split(" ", 1) for statname, statnumber in stats.items(): print(fm % (statname, timestamp, statnumber, devicename, poolname)) if firstloop: # this flag prevents printing out of the data in the first loop # which is a since-boot summary similar to iostat # and is useless to us firstloop = False else: for poolname, stats in io_stats_pool.items(): fm = "zfs.io.pool.%s %d %s pool=%s" for statname, statnumber in stats.items(): print(fm % (statname, timestamp, statnumber, poolname)) for devicename, stats in io_stats_device.items(): fm = "zfs.io.device.%s %d %s device=%s pool=%s" poolname, devicename = devicename.split(" ", 1) for statname, statnumber in stats.items(): print(fm % (statname, timestamp, statnumber, devicename, poolname)) sys.stdout.flush() if signal_received is None: signal_received = signal.SIGTERM try: os.kill(p_zpool.pid, signal_received) except Exception: pass p_zpool.wait()