in AWSIoTDeviceDefenderAgentSDK/collector.py [0:0]
def main():
"""Use this method to run the collector in stand-alone mode to tests metric collection."""
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--sample_rate", action="store", dest="sample_rate", required=False,
help="Interval between individual samples, cannot exceed Upload Rate")
parser.add_argument("-n", "--number_samples", action="store", dest="number_samples", default=0, required=False,
help="Number of samples to collect before exiting")
parser.add_argument("-l", "--list_size", action="store",
dest="max_list_size", default=None, required=False,
help="Lists larger than this size will be sampled")
parser.add_argument("--short-names", action="store_true", dest="short_names", default=False, required=False,
help="Produce metric report with short names")
parser.add_argument('-cm','--custom-metrics', action="store_true", dest="custom_metrics", default=False, help="Adds custom metrics to payload.")
args = parser.parse_args()
collector = Collector(short_metrics_names=args.short_names,use_custom_metrics=args.custom_metrics)
if args.sample_rate:
count = int(args.number_samples)
while True:
count -= 1
# setup a loop to collect
metric = collector.collect_metrics()
print(metric.to_json_string(pretty_print=True))
if count == 0:
break
sleep(float(args.sample_rate))
else:
metric = collector.collect_metrics()
if args.max_list_size:
metric.max_list_size = int(args.max_list_size)
print(metric.to_json_string(pretty_print=True))
exit()