19
19
20
20
import com .codahale .metrics .*;
21
21
import com .google .common .annotations .VisibleForTesting ;
22
+ import com .google .common .collect .ImmutableMap ;
22
23
import org .apache .hadoop .metrics2 .MetricsCollector ;
23
24
import org .apache .hadoop .metrics2 .MetricsInfo ;
24
25
import org .apache .hadoop .metrics2 .MetricsRecordBuilder ;
25
26
import org .apache .hadoop .metrics2 .MetricsSource ;
26
27
27
28
import java .util .Map ;
29
+ import java .util .concurrent .TimeUnit ;
28
30
29
31
/**
30
32
* Modeled off of YARN's NodeManagerMetrics.
31
33
*/
32
34
public class YarnShuffleServiceMetrics implements MetricsSource {
33
35
36
+ // Converting from the dropwizard-metrics default of nanoseconds into milliseconds to match how
37
+ // MetricsServlet serializes times (to milliseconds) configured via the MetricsModule passed into
38
+ // its Jackson ObjectMapper. Without this rate factor applied, the Timer metrics from
39
+ // ExternalShuffleBlockManager#ShuffleMetrics with "Millis" suffixes are misleading, as they
40
+ // would otherwise contain values in nanoseconds units
41
+ private static final double rateFactor = (double ) TimeUnit .MILLISECONDS .toNanos (1L );
42
+
34
43
private final MetricSet metricSet ;
35
44
36
45
public YarnShuffleServiceMetrics (MetricSet metricSet ) {
@@ -52,13 +61,50 @@ public void getMetrics(MetricsCollector collector, boolean all) {
52
61
}
53
62
}
54
63
64
+ private static void addSnapshotToMetricRecordBuilder (Snapshot snapshot ,
65
+ MetricsRecordBuilder builder ,
66
+ String name ,
67
+ String metricType ) {
68
+
69
+ ImmutableMap <String , Double > doubleValues = ImmutableMap .<String , Double >builder ()
70
+ .put ("median" , snapshot .getMedian ())
71
+ .put ("mean" , snapshot .getMean ())
72
+ .put ("75th" , snapshot .get75thPercentile ())
73
+ .put ("95th" , snapshot .get95thPercentile ())
74
+ .put ("98th" , snapshot .get98thPercentile ())
75
+ .put ("99th" , snapshot .get99thPercentile ())
76
+ .put ("999th" , snapshot .get999thPercentile ())
77
+ .build ();
78
+
79
+ ImmutableMap <String , Long > longValues = ImmutableMap .<String , Long >builder ()
80
+ .put ("min" , snapshot .getMin ())
81
+ .put ("max" , snapshot .getMax ())
82
+ .build ();
83
+
84
+ for (Map .Entry <String , Double > entry : doubleValues .entrySet ()) {
85
+ builder .addGauge (
86
+ new ShuffleServiceMetricsInfo (name + "_" + entry .getKey (),
87
+ entry .getKey () + " of " + metricType + " " + name ),
88
+ entry .getValue () / rateFactor );
89
+ }
90
+
91
+ for (Map .Entry <String , Long > entry : longValues .entrySet ()) {
92
+ builder .addGauge (
93
+ new ShuffleServiceMetricsInfo (name + "_" + entry .getKey (),
94
+ entry .getKey () + " of " + metricType + " " + name ),
95
+ entry .getValue () / rateFactor );
96
+ }
97
+
98
+ }
99
+
55
100
@ VisibleForTesting
56
101
public static void collectMetric (
57
102
MetricsRecordBuilder metricsRecordBuilder , String name , Metric metric ) {
58
103
59
104
// The metric types used in ExternalShuffleBlockHandler.ShuffleMetrics
60
105
if (metric instanceof Timer ) {
61
106
Timer t = (Timer ) metric ;
107
+ Snapshot snapshot = t .getSnapshot ();
62
108
metricsRecordBuilder
63
109
.addCounter (new ShuffleServiceMetricsInfo (name + "_count" , "Count of timer " + name ),
64
110
t .getCount ())
@@ -73,6 +119,7 @@ public static void collectMetric(
73
119
t .getOneMinuteRate ())
74
120
.addGauge (new ShuffleServiceMetricsInfo (name + "_rateMean" , "Mean rate of timer " + name ),
75
121
t .getMeanRate ());
122
+ addSnapshotToMetricRecordBuilder (snapshot , metricsRecordBuilder , name , "timer" );
76
123
} else if (metric instanceof Meter ) {
77
124
Meter m = (Meter ) metric ;
78
125
metricsRecordBuilder
0 commit comments