Replace AIX uptime function with ps etimes-based implementation #1967
+79
−57
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR replaces the AIX host module's uptime determination method from parsing the
uptimecommand output to a more reliable approach usingps -o etimes -p 1. This directly queries the process table for PID 1's elapsed time rather than relying on variable human-readable output formatting.Fixes #1809 (comment)
Motivation
The previous implementation parsing
uptimecommand output had several limitations:Direct access to the process table via
ps etimesis more robust and efficient.Technical Changes
Implementation
ps -o etimes -p 1instead ofuptimeDAYS-HOURS:MINUTES:SECONDS(e.g.,124-01:40:39)HOURS:MINUTES:SECONDS(e.g.,15:03:02)MINUTES:SECONDS(e.g.,01:02) - from just-rebooted systems where hours are omitted when zeroTesting
Files Changed
host/host_aix.go: Updated UptimeWithContext() and parseUptime()host/host_aix_test.go: Updated test cases for new formatBackward Compatibility
The function signature and behavior remain unchanged from the caller's perspective. The return value (uptime in minutes) is consistent with the previous implementation.