Created
January 16, 2019 06:01
-
-
Save lixianyang/fd5c40fcc47de33bb99878271c81d94a to your computer and use it in GitHub Desktop.
prometheus metrics to markdown help
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment