@@ -41,7 +41,7 @@ public class PrometheusHadoopServlet extends HttpServlet {
41
41
42
42
@ Override
43
43
protected void doGet (HttpServletRequest req , HttpServletResponse resp ) throws IOException {
44
- writeMetrics (resp .getWriter ());
44
+ writeMetrics (resp .getWriter (), "true" . equals ( req . getParameter ( "description" )) );
45
45
}
46
46
47
47
static String toPrometheusName (String metricRecordName , String metricName ) {
@@ -57,15 +57,21 @@ static String toPrometheusName(String metricRecordName, String metricName) {
57
57
*/
58
58
@ RestrictedApi (explanation = "Should only be called in tests or self" , link = "" ,
59
59
allowedOnPath = ".*/src/test/.*|.*/PrometheusHadoopServlet\\ .java" )
60
- void writeMetrics (Writer writer ) throws IOException {
60
+ void writeMetrics (Writer writer , boolean desc ) throws IOException {
61
61
Collection <MetricsRecord > metricRecords = MetricsExportHelper .export ();
62
62
for (MetricsRecord metricsRecord : metricRecords ) {
63
63
for (AbstractMetric metrics : metricsRecord .metrics ()) {
64
64
if (metrics .type () == MetricType .COUNTER || metrics .type () == MetricType .GAUGE ) {
65
65
66
66
String key = toPrometheusName (metricsRecord .name (), metrics .name ());
67
+
68
+ if (desc ) {
69
+ String description = metrics .description ();
70
+ if (!description .isEmpty ()) writer .append ("# HELP " ).append (description ).append ('\n' );
71
+ }
72
+
67
73
writer .append ("# TYPE " ).append (key ).append (" " )
68
- .append (metrics .type ().toString ().toLowerCase ()).append (" \n " ).append (key ).append ("{" );
74
+ .append (metrics .type ().toString ().toLowerCase ()).append ('\n' ).append (key ).append ("{" );
69
75
70
76
/* add tags */
71
77
String sep = "" ;
0 commit comments