@@ -55,10 +55,7 @@ public int getOrder() {
55
55
public Collection <Metric <?>> metrics () {
56
56
Collection <Metric <?>> result = new LinkedHashSet <Metric <?>>();
57
57
addBasicMetrics (result );
58
- addHeapMetrics (result );
59
- addThreadMetrics (result );
60
- addClassLoadingMetrics (result );
61
- addGarbageCollectionMetrics (result );
58
+ addManagementMetrics (result );
62
59
return result ;
63
60
}
64
61
@@ -67,17 +64,34 @@ public Collection<Metric<?>> metrics() {
67
64
* @param result the result
68
65
*/
69
66
protected void addBasicMetrics (Collection <Metric <?>> result ) {
67
+ // NOTE: ManagementFactory must not be used here since it fails on GAE
70
68
result .add (new Metric <Long >("mem" , Runtime .getRuntime ().totalMemory () / 1024 ));
71
69
result .add (new Metric <Long >("mem.free" , Runtime .getRuntime ().freeMemory () / 1024 ));
72
70
result .add (new Metric <Integer >("processors" , Runtime .getRuntime ()
73
71
.availableProcessors ()));
74
- // Add JVM up time in ms
75
- result .add (new Metric <Long >("uptime" , ManagementFactory .getRuntimeMXBean ()
76
- .getUptime ()));
77
72
result .add (new Metric <Long >("instance.uptime" , System .currentTimeMillis ()
78
73
- this .timestamp ));
79
- result .add (new Metric <Double >("systemload.average" , ManagementFactory
80
- .getOperatingSystemMXBean ().getSystemLoadAverage ()));
74
+ }
75
+
76
+ /**
77
+ * Add metrics from ManagementFactory if possible. Note that ManagementFactory is not
78
+ * available on Google App Engine.
79
+ */
80
+ private void addManagementMetrics (Collection <Metric <?>> result ) {
81
+ try {
82
+ // Add JVM up time in ms
83
+ result .add (new Metric <Long >("uptime" , ManagementFactory .getRuntimeMXBean ()
84
+ .getUptime ()));
85
+ result .add (new Metric <Double >("systemload.average" , ManagementFactory
86
+ .getOperatingSystemMXBean ().getSystemLoadAverage ()));
87
+ addHeapMetrics (result );
88
+ addThreadMetrics (result );
89
+ addClassLoadingMetrics (result );
90
+ addGarbageCollectionMetrics (result );
91
+ }
92
+ catch (NoClassDefFoundError ex ) {
93
+ // Expected on Google App Engine
94
+ }
81
95
}
82
96
83
97
/**
0 commit comments