Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/content.zh/docs/ops/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,35 @@ Some metrics might not be exposed when using other JVM implementations (e.g. IBM
</tbody>
</table>

### File Descriptors
<table class="table table-bordered">
<thead>
<tr>
<th class="text-left" style="width: 18%">Scope</th>
<th class="text-left" style="width: 22%">Infix</th>
<th class="text-left" style="width: 20%">Metrics</th>
<th class="text-left" style="width: 32%">Description</th>
<th class="text-left" style="width: 8%">Type</th>
</tr>
</thead>
<tbody>
<tr>
<th rowspan="1"><strong>Job-/TaskManager</strong></th>
<td rowspan="1">Status.FileDescriptor.Max</td>
<td>Count</td>
<td>The max number of file descriptors.</td>
<td>Gauge</td>
</tr>
<tr>
<th rowspan="1"><strong>Job-/TaskManager</strong></th>
<td rowspan="1">Status.FileDescriptor.Open</td>
<td>Count</td>
<td>The total open of file descriptors.</td>
<td>Gauge</td>
</tr>
</tbody>
</table>

### Threads
<table class="table table-bordered">
<thead>
Expand Down
29 changes: 29 additions & 0 deletions docs/content/docs/ops/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,35 @@ Some metrics might not be exposed when using other JVM implementations (e.g. IBM
</tbody>
</table>

### File Descriptors
<table class="table table-bordered">
<thead>
<tr>
<th class="text-left" style="width: 18%">Scope</th>
<th class="text-left" style="width: 22%">Infix</th>
<th class="text-left" style="width: 20%">Metrics</th>
<th class="text-left" style="width: 32%">Description</th>
<th class="text-left" style="width: 8%">Type</th>
</tr>
</thead>
<tbody>
<tr>
<th rowspan="1"><strong>Job-/TaskManager</strong></th>
<td rowspan="1">Status.FileDescriptor.Max</td>
<td>Count</td>
<td>The max number of file descriptors.</td>
<td>Gauge</td>
</tr>
<tr>
<th rowspan="1"><strong>Job-/TaskManager</strong></th>
<td rowspan="1">Status.FileDescriptor.Open</td>
<td>Count</td>
<td>The total open of file descriptors.</td>
<td>Gauge</td>
</tr>
</tbody>
</table>

### Threads
<table class="table table-bordered">
<thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ private MetricNames() {}
public static final String MEMORY_COMMITTED = "Committed";
public static final String MEMORY_MAX = "Max";

public static final String FILE_DESCRIPTOR_MAX = "Max";
public static final String FILE_DESCRIPTOR_OPEN = "Open";

public static final String IS_BACK_PRESSURED = "isBackPressured";

public static final String CHECKPOINT_ALIGNMENT_TIME = "checkpointAlignmentTime";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public static void instantiateStatusMetrics(MetricGroup metricGroup) {
instantiateMemoryMetrics(jvm.addGroup(METRIC_GROUP_MEMORY));
instantiateThreadMetrics(jvm.addGroup("Threads"));
instantiateCPUMetrics(jvm.addGroup("CPU"));
instantiateFileDescriptorMetrics(jvm.addGroup("FileDescriptor"));
}

public static void instantiateFlinkMemoryMetricGroup(
Expand Down Expand Up @@ -338,6 +339,30 @@ static void instantiateMetaspaceMemoryMetrics(final MetricGroup parentMetricGrou
}
}

static void instantiateFileDescriptorMetrics(MetricGroup metrics) {
try {
final com.sun.management.OperatingSystemMXBean mxBean =
(com.sun.management.OperatingSystemMXBean)
ManagementFactory.getOperatingSystemMXBean();

if (mxBean instanceof com.sun.management.UnixOperatingSystemMXBean) {
com.sun.management.UnixOperatingSystemMXBean unixMXBean =
(com.sun.management.UnixOperatingSystemMXBean) mxBean;
metrics.<Long, Gauge<Long>>gauge("Max", unixMXBean::getMaxFileDescriptorCount);
metrics.<Long, Gauge<Long>>gauge("Open", unixMXBean::getOpenFileDescriptorCount);

} else {
throw new UnsupportedOperationException(
"Can't find com.sun.management.UnixOperatingSystemMXBean in JVM.");
}
} catch (Exception e) {
LOG.warn(
"Cannot access com.sun.management.UnixOperatingSystemMXBean.getOpenFileDescriptorCount()"
+ " - FileDescriptor metrics will not be available.",
e);
}
}

private static void instantiateMemoryUsageMetrics(
final MetricGroup metricGroup, final Supplier<MemoryUsage> memoryUsageSupplier) {
metricGroup.<Long, Gauge<Long>>gauge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ void testHeapMetricsCompleteness() {
assertThat(heapMetrics.get(MetricNames.MEMORY_MAX)).isNotNull();
}

@Test
void testFileDescriptorMetricsCompleteness() {
final InterceptingOperatorMetricGroup heapMetrics = new InterceptingOperatorMetricGroup();

MetricUtils.instantiateFileDescriptorMetrics(heapMetrics);

assertThat(heapMetrics.get(MetricNames.FILE_DESCRIPTOR_MAX)).isNotNull();
assertThat(heapMetrics.get(MetricNames.FILE_DESCRIPTOR_OPEN)).isNotNull();
}

/**
* Tests that heap/non-heap metrics do not rely on a static MemoryUsage instance.
*
Expand Down