Skip to content

Implement and fix Windows disk metrics parsing#17290

Open
HTHou wants to merge 6 commits intomasterfrom
new_win_metric
Open

Implement and fix Windows disk metrics parsing#17290
HTHou wants to merge 6 commits intomasterfrom
new_win_metric

Conversation

@HTHou
Copy link
Contributor

@HTHou HTHou commented Mar 12, 2026

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:

  • Added logic in SystemRelatedFileMetrics to 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:

  • Implemented the WindowsNetMetricManager class 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.
image image

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and netstat parsing.
  • 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.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
4 Security Hotspots

See analysis details on SonarQube Cloud

Comment on lines +239 to +244
Map<String, String[]> diskInfoMap = queryDiskInfo();
if (diskInfoMap.isEmpty()) {
return;
}
diskIdSet.clear();
diskIdSet.addAll(diskInfoMap.keySet());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diskIdSet is directly returned by getDiskIds().
If it is cleared here, could there be a concurrent issue?
How about assigning?

Comment on lines +264 to +270
Map<String, String[]> diskInfoMap = queryDiskInfo();
if (diskInfoMap.isEmpty()) {
return;
}

diskIdSet.clear();
diskIdSet.addAll(diskInfoMap.keySet());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as collectDiskId()?

command,
String.join(" | ", rawOutput));
} else {
result.addAll(rawOutput);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return rawOutput directly?

Comment on lines +512 to +515
if (Charset.isSupported("GBK")) {
return Charset.forName("GBK");
}
return Charset.defaultCharset();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that GBK is supported but not used?

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 0% with 375 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.68%. Comparing base (a53f960) to head (d9c7b5a).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...ics/metricsets/disk/WindowsDiskMetricsManager.java 0.00% 253 Missing ⚠️
...etrics/metricsets/net/WindowsNetMetricManager.java 0.00% 110 Missing ⚠️
...service/metrics/file/SystemRelatedFileMetrics.java 0.00% 12 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants