def test_clustermetric(): # construct 2 SARMetric metric1 = SARMetric('SAR-cpuusage-host1', 'sar.cpuusage.out', 'host1', '.', 'logs', 'SAR-cpuusage-host1', None, None, {}, None, None) metric1.csv_column_map[ 'logs/SAR-cpuusage-host1.all.percent-sys.csv'] = 'all.%sys' metric1.column_csv_map[ 'all.%sys'] = 'logs/SAR-cpuusage-host1.all.percent-sys.csv' metric2 = SARMetric('SAR-cpuusage-host2', 'sar.cpuusage.out', 'host2', '.', 'logs', 'SAR-cpuusage-host2', None, None, {}, None, None) metric2.csv_column_map[ 'logs/SAR-cpuusage-host2.all.percent-sys.csv'] = 'all.%sys' metric2.column_csv_map[ 'all.%sys'] = 'logs/SAR-cpuusage-host2.all.percent-sys.csv' # construct a ClusterMetric aggregate_metrics = 'SAR-cpuusage.all.percent-sys:raw,avg,sum,count' section = 'CLUSTER-cpuusage-1' label = 'CLUSTER-cpuusage-1' resource_path = 'resources' rule_strings = {} output_directory = tmp_dir aggregate_hosts = 'host1 host2' other_options = {} ts_start = None ts_end = None metrics = [metric1, metric2] cur_metric = ClusterMetric(section, aggregate_hosts, aggregate_metrics, metrics, output_directory, resource_path, label, ts_start, ts_end, rule_strings, None, None) # create sub-directory of resource_path sub_dir = os.path.join(output_directory, resource_path) if not os.path.exists(sub_dir): os.makedirs(sub_dir) # the only method to test; it will write to the directory the final csv files; cur_metric.collect() # check the existance of the output files functions = aggregate_metrics.split(':') prefix = functions[0].split('.') # 'SAR-cpuusage.all.percent-sys' prefix[0] = section prefix = '.'.join(prefix) # CLUSTER-cpuusage-1.all.percent-sys for func in functions[1].split(','): # 'raw,avg,sum,count' file_name = prefix + '.' + func + '.csv' file_path = os.path.join(sub_dir, file_name) # print 'file to check = ' + file_path # resources/CLUSTER-cpuusage-1.all.percent-sys.raw.csv assert os.path.exists(file_path)
def get_all_sar_objects(metrics, indir, hostname, output_directory, label, ts_start, ts_end, options): metrics = [] sar_types = ('device', 'cpuusage', 'cpuhz', 'memory', 'memutil', 'paging') for sar_metric_type in sar_types: #infile = indir + '/' + 'sar.' + sar_metric_type + '.out' infile = os.path.join(indir, 'sar.' + sar_metric_type + '.out') if os.path.exists(infile): obj_type = 'SAR-' + sar_metric_type metric = SARMetric(obj_type, infile, hostname, output_directory, label, ts_start, ts_end, options) metrics.append(metric) return metrics