Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- import sys
- import requests
- def get_metrics_string(url):
- """ get metrics content """
- r = requests.get(url)
- return r.content
- def parse_metrics_help(string):
- metrics = []
- lines = string.split("\n")
- for line in lines:
- if line.startswith("# HELP"):
- words = line.split()
- metrics.append((words[2], " ".join(words[3:])))
- return metrics
- def save_metrics_help(metrics, name):
- lines = [
- "| metric | help |",
- "| ------ | ---- |",
- ]
- for metric in metrics:
- lines.append("| %s | %s |" % (metric[0], metric[1]))
- lines.append("")
- with open(name, "w+") as f:
- f.write("\n".join(lines))
- def main():
- if len(sys.argv) != 3:
- print("Invalid arguments")
- return
- url, name = sys.argv[1:]
- string = get_metrics_string(url)
- metrics = parse_metrics_help(string)
- save_metrics_help(metrics, name)
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment