diff --git a/main.py b/main.py index d4ea6c8..140d520 100644 --- a/main.py +++ b/main.py @@ -57,12 +57,19 @@ def metrics(): }, ] - ret_str = '' + ret_strs = list() for item in ret_data: - ret_str += f'# TYPE {item["key"]} {item["type"]}\r\n' - ret_str += f'{item["key"]} {item["value"]}\r\n' + ret_strs.append(f'# HELP {item["key"]} Weather metric') + ret_strs.append(f'# TYPE {item["key"]} {item["type"]}') + ret_strs.append( + item["key"] + + '{' + + " ".join([f'{key}="{val}"' for key, val in item["labels"].items()]) + + '} ' + + str(item["value"]) + ) - resp = Response(ret_str) + resp = Response('\n'.join(ret_strs)) resp.headers['Content-type'] = 'text/plain' return resp