diff --git a/prometheus_client/exposition.py b/prometheus_client/exposition.py index 2e329851..238591b1 100644 --- a/prometheus_client/exposition.py +++ b/prometheus_client/exposition.py @@ -122,6 +122,8 @@ def sample_line(line): raise for suffix, lines in sorted(om_samples.items()): + output.append('# HELP {0}{1} {2}\n'.format(metric.name, suffix, + metric.documentation.replace('\\', r'\\').replace('\n', r'\n'))) output.append('# TYPE {0}{1} gauge\n'.format(metric.name, suffix)) output.extend(lines) return ''.join(output).encode('utf-8') diff --git a/tests/test_exposition.py b/tests/test_exposition.py index de116a07..44b197a1 100644 --- a/tests/test_exposition.py +++ b/tests/test_exposition.py @@ -56,6 +56,7 @@ def test_counter(self): self.assertEqual(b"""# HELP cc_total A counter # TYPE cc_total counter cc_total 1.0 +# HELP cc_created A counter # TYPE cc_created gauge cc_created 123.456 """, generate_latest(self.registry)) @@ -66,6 +67,7 @@ def test_counter_total(self): self.assertEqual(b"""# HELP cc_total A counter # TYPE cc_total counter cc_total 1.0 +# HELP cc_created A counter # TYPE cc_created gauge cc_created 123.456 """, generate_latest(self.registry)) @@ -82,6 +84,7 @@ def test_summary(self): # TYPE ss summary ss_count{a="c",b="d"} 1.0 ss_sum{a="c",b="d"} 17.0 +# HELP ss_created A summary # TYPE ss_created gauge ss_created{a="c",b="d"} 123.456 """, generate_latest(self.registry)) @@ -109,6 +112,7 @@ def test_histogram(self): hh_bucket{le="+Inf"} 1.0 hh_count 1.0 hh_sum 0.05 +# HELP hh_created A histogram # TYPE hh_created gauge hh_created 123.456 """, generate_latest(self.registry)) @@ -119,8 +123,10 @@ def test_gaugehistogram(self): # TYPE gh histogram gh_bucket{le="1.0"} 4.0 gh_bucket{le="+Inf"} 5.0 +# HELP gh_gcount help # TYPE gh_gcount gauge gh_gcount 5.0 +# HELP gh_gsum help # TYPE gh_gsum gauge gh_gsum 7.0 """, generate_latest(self.registry))