Implement and fix Windows disk metrics parsing#17290
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Windows-specific implementations for collecting system metrics so disk, network, and file-handle-related metrics can be reported consistently across OSes.
Changes:
- Implement Windows network metrics collection via PowerShell (
Get-NetAdapter,Get-NetAdapterStatistics) andnetstatparsing. - Implement Windows disk metrics collection via PowerShell CIM perf counters and accumulate sampled per-second values into cumulative totals.
- Add Windows support for “open file handlers” by querying the current process handle count via Windows API (JNA).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/WindowsNetMetricManager.java |
Implements Windows network interface + connection metrics via command execution and parsing. |
iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/WindowsDiskMetricsManager.java |
Implements Windows disk and process IO metrics by sampling Win32 perf counters using PowerShell. |
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/metrics/file/SystemRelatedFileMetrics.java |
Extends open-file/handle metrics support to Windows using JNA and kernel32. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...erface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/WindowsDiskMetricsManager.java
Show resolved
Hide resolved
...atanode/src/main/java/org/apache/iotdb/db/service/metrics/file/SystemRelatedFileMetrics.java
Show resolved
Hide resolved
...interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/WindowsNetMetricManager.java
Outdated
Show resolved
Hide resolved
...interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/WindowsNetMetricManager.java
Outdated
Show resolved
Hide resolved
...interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/WindowsNetMetricManager.java
Show resolved
Hide resolved
...interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/WindowsNetMetricManager.java
Show resolved
Hide resolved
...interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/WindowsNetMetricManager.java
Show resolved
Hide resolved
...interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/WindowsNetMetricManager.java
Show resolved
Hide resolved
|
| Map<String, String[]> diskInfoMap = queryDiskInfo(); | ||
| if (diskInfoMap.isEmpty()) { | ||
| return; | ||
| } | ||
| diskIdSet.clear(); | ||
| diskIdSet.addAll(diskInfoMap.keySet()); |
There was a problem hiding this comment.
diskIdSet is directly returned by getDiskIds().
If it is cleared here, could there be a concurrent issue?
How about assigning?
| Map<String, String[]> diskInfoMap = queryDiskInfo(); | ||
| if (diskInfoMap.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| diskIdSet.clear(); | ||
| diskIdSet.addAll(diskInfoMap.keySet()); |
There was a problem hiding this comment.
The same as collectDiskId()?
| command, | ||
| String.join(" | ", rawOutput)); | ||
| } else { | ||
| result.addAll(rawOutput); |
There was a problem hiding this comment.
Why not return rawOutput directly?
| if (Charset.isSupported("GBK")) { | ||
| return Charset.forName("GBK"); | ||
| } | ||
| return Charset.defaultCharset(); |
There was a problem hiding this comment.
Is it possible that GBK is supported but not used?
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #17290 +/- ##
============================================
- Coverage 39.72% 39.68% -0.05%
Complexity 282 282
============================================
Files 5101 5101
Lines 342143 342524 +381
Branches 43583 43635 +52
============================================
+ Hits 135919 135923 +4
- Misses 206224 206601 +377 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|


This pull request adds and improves support for collecting system and network metrics on Windows systems. The main changes include implementing Windows-specific logic for tracking open file handles and network interface statistics, ensuring consistent metrics collection across different operating systems.
Windows System Metrics Support:
SystemRelatedFileMetricsto count open file handles on Windows using JNA to call the Windows API (GetProcessHandleCount), extending existing support for Linux and Mac. [1] [2] [3] [4] [5]Windows Network Metrics Implementation:
WindowsNetMetricManagerclass to collect network interface statistics and connection counts on Windows by invoking PowerShell and system commands. This includes gathering interface names, bytes/packets sent and received, and active connection numbers for the current process.