{% for metric_name, metric_details in metrics.items() -%}
{% if metric_details.instances | length > 0 -%}
{% if metric_details.help != "" %}# HELP {{ metric_name }} {{ metric_details.help | replace("\\", "\\\\" ) | replace("\n", "\\n") }}{%- endif %}{% if metric_details.type != "" %}
# TYPE {{ metric_name }} {{ metric_details.type }}{%- endif %}
{% if metric_details.comments | length > 0 %}
{%- for comment in metric_details.comments -%}
# {{ comment | replace("\\", "\\\\" ) | replace("\n", "\\n") }}
{% endfor -%}
{% endif %}
{%- for instance in metric_details.instances -%}
{{ metric_name }}{%- if instance.labels | length > 0 %} {{- "{" -}} {% for label, value in instance.labels.items() %}{{ label }}="{{ value | replace("\\", "\\\\" ) | replace("\n", "\\n") }}"{% if not loop.last %},{% endif %}{% endfor %} {{- "}" -}} {% endif %} {{ instance.value }}
{% endfor %}
{% endif -%}
{%- endfor -%}
