Skip to content

Commit

Permalink
[FLINK-5209] [webfrontend] Fix TaskManager metrics
Browse files Browse the repository at this point in the history
Fixes a capitalization incompatibility when providing memory metrics to
the webfrontend. Numeric metrics now returned as numbers in the JSON
API. Non-byte numbers now localized in the webfrontend.

This closes apache#2902
  • Loading branch information
greghogan committed Dec 2, 2016
1 parent 45b770b commit 4e336c6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,27 @@ public String handleJsonRequest(Map<String, String> pathParams, Map<String, Stri
gen.writeNumberField("totalUsed", heapUsed + nonHeapUsed);
gen.writeNumberField("totalMax", heapTotal + nonHeapTotal);

gen.writeStringField("directCount", metrics.getMetric("Status.JVM.Memory.Direct.Count", "0"));
gen.writeStringField("directUsed", metrics.getMetric("Status.JVM.Memory.Direct.MemoryUsed", "0"));
gen.writeStringField("directMax", metrics.getMetric("Status.JVM.Memory.Direct.TotalCapacity", "0"));
long directCount = Long.valueOf(metrics.getMetric("Status.JVM.Memory.Direct.Count", "0"));
long directUsed = Long.valueOf(metrics.getMetric("Status.JVM.Memory.Direct.MemoryUsed", "0"));
long directMax = Long.valueOf(metrics.getMetric("Status.JVM.Memory.Direct.TotalCapacity", "0"));

gen.writeStringField("mappedCount", metrics.getMetric("Status.JVM.Memory.Mapped.Count", "0"));
gen.writeStringField("mappedUsed", metrics.getMetric("Status.JVM.Memory.Mapped.MemoryUsed", "0"));
gen.writeStringField("mappedMax", metrics.getMetric("Status.JVM.Memory.Mapped.TotalCapacity", "0"));
gen.writeNumberField("directCount", directCount);
gen.writeNumberField("directUsed", directUsed);
gen.writeNumberField("directMax", directMax);

gen.writeStringField("memorySegmentsAvailable", metrics.getMetric("Status.Network.AvailableMemorySegments", "0"));
gen.writeStringField("memorySegmentsTotal", metrics.getMetric("Status.Network.TotalMemorySegments", "0"));
long mappedCount = Long.valueOf(metrics.getMetric("Status.JVM.Memory.Mapped.Count", "0"));
long mappedUsed = Long.valueOf(metrics.getMetric("Status.JVM.Memory.Mapped.MemoryUsed", "0"));
long mappedMax = Long.valueOf(metrics.getMetric("Status.JVM.Memory.Mapped.TotalCapacity", "0"));

gen.writeNumberField("mappedCount", mappedCount);
gen.writeNumberField("mappedUsed", mappedUsed);
gen.writeNumberField("mappedMax", mappedMax);

long memorySegmentsAvailable = Long.valueOf(metrics.getMetric("Status.Network.AvailableMemorySegments", "0"));
long memorySegmentsTotal = Long.valueOf(metrics.getMetric("Status.Network.TotalMemorySegments", "0"));

gen.writeNumberField("memorySegmentsAvailable", memorySegmentsAvailable);
gen.writeNumberField("memorySegmentsTotal", memorySegmentsTotal);

gen.writeArrayFieldStart("garbageCollectors");

Expand All @@ -143,8 +154,8 @@ public String handleJsonRequest(Map<String, String> pathParams, Map<String, Stri
if (count != null && time != null) {
gen.writeStartObject();
gen.writeStringField("name", gcName);
gen.writeStringField("count", count);
gen.writeStringField("time", time);
gen.writeNumberField("count", Long.valueOf(count));
gen.writeNumberField("time", Long.valueOf(time));
gen.writeEndObject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ div(ng-if="metrics.id")
tbody
tr
td Heap
td {{ metrics.metrics.heapCommitted | humanizeBytes }}
td {{ metrics.metrics.heapUsed | humanizeBytes }}
td {{ metrics.metrics.heapMax | humanizeBytes }}
td {{ metrics.metrics.heapCommitted | humanizeBytes }}
td {{ metrics.metrics.heapUsed | humanizeBytes }}
td {{ metrics.metrics.heapMax | humanizeBytes }}
tr
td Non-Heap
td {{ metrics.metrics.nonHeapCommitted | humanizeBytes }}
td {{ metrics.metrics.nonHeapUsed | humanizeBytes }}
td {{ metrics.metrics.nonHeapMax | humanizeBytes }}
td {{ metrics.metrics.nonHeapCommitted | humanizeBytes }}
td {{ metrics.metrics.nonHeapUsed | humanizeBytes }}
td {{ metrics.metrics.nonHeapMax | humanizeBytes }}
tr
td Total
td {{ metrics.metrics.totalCommitted | humanizeBytes }}
td {{ metrics.metrics.totalUsed | humanizeBytes }}
td {{ metrics.metrics.totalMax | humanizeBytes }}
td {{ metrics.metrics.totalCommitted | humanizeBytes }}
td {{ metrics.metrics.totalUsed | humanizeBytes }}
td {{ metrics.metrics.totalMax | humanizeBytes }}

h2 Outside JVM
table.table.table-properties
Expand All @@ -75,18 +75,18 @@ div(ng-if="metrics.id")
tbody
tr
td Direct
td {{ metrics.metrics.directCount }}
td {{ metrics.metrics.directUsed }}
td {{ metrics.metrics.directTotal }}
td {{ metrics.metrics.directCount | toLocaleString }}
td {{ metrics.metrics.directUsed | humanizeBytes }}
td {{ metrics.metrics.directMax | humanizeBytes }}
tr
td Mapped
td {{ metrics.metrics.mappedCount }}
td {{ metrics.metrics.mappedUsed }}
td {{ metrics.metrics.mappedMax }}
td {{ metrics.metrics.mappedCount | toLocaleString }}
td {{ metrics.metrics.mappedUsed | humanizeBytes }}
td {{ metrics.metrics.mappedMax | humanizeBytes }}

h1 Network

h2 MemorySegments
h2 Memory Segments
table.table.table-properties
thead
tr
Expand All @@ -95,11 +95,10 @@ div(ng-if="metrics.id")
tbody
tr
td Available
td {{ metrics.metrics.memorySegmentsAvailable }}
td {{ metrics.metrics.memorySegmentsAvailable | toLocaleString }}
tr
td Total
td {{ metrics.metrics.memorySegmentsTotal }}

td {{ metrics.metrics.memorySegmentsTotal | toLocaleString }}

h1 Garbage Collection
table.table.table-properties
Expand All @@ -109,7 +108,7 @@ div(ng-if="metrics.id")
th Count
th Time
tbody(ng-repeat="g in metrics.metrics.garbageCollectors")
tr
tr
td {{ g.name }}
td {{ g.count }}
td {{ g.time }}
td {{ g.count | toLocaleString }}
td {{ g.time | toLocaleString }}
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@ angular.module('flinkApp')
return "" if typeof bytes is "undefined" or bytes is null
if bytes < 1000 then bytes + " B" else converter(bytes, 1)

.filter "toLocaleString", ->
(text) -> text.toLocaleString()

.filter "toUpperCase", ->
(text) -> text.toUpperCase()
6 changes: 5 additions & 1 deletion flink-runtime-web/web-dashboard/web/js/index.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ <h2>JVM (Heap/Non-Heap)</h2>
<tbody>
<tr>
<td>Heap</td>
<td>{{ metrics.metrics.heapCommitted | humanizeBytes }}</td>
<td>{{ metrics.metrics.heapUsed | humanizeBytes }}</td>
<td>{{ metrics.metrics.heapMax | humanizeBytes }}</td>
<td>{{ metrics.metrics.heapCommitted | humanizeBytes }}</td>
<td>{{ metrics.metrics.heapUsed | humanizeBytes }}</td>
<td>{{ metrics.metrics.heapMax | humanizeBytes }}</td>
</tr>
<tr>
<td>Non-Heap</td>
<td>{{ metrics.metrics.nonHeapCommitted | humanizeBytes }}</td>
<td>{{ metrics.metrics.nonHeapUsed | humanizeBytes }}</td>
<td>{{ metrics.metrics.nonHeapMax | humanizeBytes }}</td>
<td>{{ metrics.metrics.nonHeapCommitted | humanizeBytes }}</td>
<td>{{ metrics.metrics.nonHeapUsed | humanizeBytes }}</td>
<td>{{ metrics.metrics.nonHeapMax | humanizeBytes }}</td>
</tr>
<tr>
<td>Total</td>
<td>{{ metrics.metrics.totalCommitted | humanizeBytes }}</td>
<td>{{ metrics.metrics.totalUsed | humanizeBytes }}</td>
<td>{{ metrics.metrics.totalMax | humanizeBytes }}</td>
<td>{{ metrics.metrics.totalCommitted | humanizeBytes }}</td>
<td>{{ metrics.metrics.totalUsed | humanizeBytes }}</td>
<td>{{ metrics.metrics.totalMax | humanizeBytes }}</td>
</tr>
</tbody>
</table>
Expand All @@ -88,20 +88,20 @@ <h2>Outside JVM</h2>
<tbody>
<tr>
<td>Direct</td>
<td>{{ metrics.metrics.directCount }}</td>
<td>{{ metrics.metrics.directUsed }}</td>
<td>{{ metrics.metrics.directTotal }}</td>
<td>{{ metrics.metrics.directCount | toLocaleString }}</td>
<td>{{ metrics.metrics.directUsed | humanizeBytes }}</td>
<td>{{ metrics.metrics.directMax | humanizeBytes }}</td>
</tr>
<tr>
<td>Mapped</td>
<td>{{ metrics.metrics.mappedCount }}</td>
<td>{{ metrics.metrics.mappedUsed }}</td>
<td>{{ metrics.metrics.mappedMax }}</td>
<td>{{ metrics.metrics.mappedCount | toLocaleString }}</td>
<td>{{ metrics.metrics.mappedUsed | humanizeBytes }}</td>
<td>{{ metrics.metrics.mappedMax | humanizeBytes }}</td>
</tr>
</tbody>
</table>
<h1>Network</h1>
<h2>MemorySegments</h2>
<h2>Memory Segments</h2>
<table class="table table-properties">
<thead>
<tr>
Expand All @@ -112,11 +112,11 @@ <h2>MemorySegments</h2>
<tbody>
<tr>
<td>Available</td>
<td>{{ metrics.metrics.memorySegmentsAvailable }}</td>
<td>{{ metrics.metrics.memorySegmentsAvailable | toLocaleString }}</td>
</tr>
<tr>
<td>Total</td>
<td>{{ metrics.metrics.memorySegmentsTotal }}</td>
<td>{{ metrics.metrics.memorySegmentsTotal | toLocaleString }}</td>
</tr>
</tbody>
</table>
Expand All @@ -130,10 +130,10 @@ <h1>Garbage Collection</h1>
</tr>
</thead>
<tbody ng-repeat="g in metrics.metrics.garbageCollectors">
<tr>
<tr>
<td>{{ g.name }}</td>
<td>{{ g.count }}</td>
<td>{{ g.time }}</td>
<td>{{ g.count | toLocaleString }}</td>
<td>{{ g.time | toLocaleString }}</td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.flink.runtime.metrics.util;

import org.apache.commons.lang3.text.WordUtils;
import org.apache.flink.metrics.Gauge;
import org.apache.flink.metrics.MetricGroup;
import org.apache.flink.runtime.io.network.NetworkEnvironment;
Expand Down Expand Up @@ -46,13 +47,16 @@ public static void instantiateNetworkMetrics(
final NetworkEnvironment network) {
MetricGroup status = metrics.addGroup(METRIC_GROUP_STATUS_NAME);

status.gauge("TotalMemorySegments", new Gauge<Integer>() {
MetricGroup networkGroup = status
.addGroup("Network");

networkGroup.gauge("TotalMemorySegments", new Gauge<Integer>() {
@Override
public Integer getValue() {
return network.getNetworkBufferPool().getTotalNumberOfMemorySegments();
}
});
status.gauge("AvailableMemorySegments", new Gauge<Integer>() {
networkGroup.gauge("AvailableMemorySegments", new Gauge<Integer>() {
@Override
public Integer getValue() {
return network.getNetworkBufferPool().getNumberOfAvailableMemorySegments();
Expand Down Expand Up @@ -157,7 +161,7 @@ public Long getValue() {
List<BufferPoolMXBean> bufferMxBeans = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);

for (final BufferPoolMXBean bufferMxBean : bufferMxBeans) {
MetricGroup bufferGroup = metrics.addGroup(bufferMxBean.getName());
MetricGroup bufferGroup = metrics.addGroup(WordUtils.capitalize(bufferMxBean.getName()));
bufferGroup.gauge("Count", new Gauge<Long>() {
@Override
public Long getValue() {
Expand Down

0 comments on commit 4e336c6

Please sign in to comment.