Replace AIX uptime function with ps etimes-based implementation#1967
Merged
shirou merged 3 commits intoshirou:masterfrom Dec 23, 2025
Merged
Replace AIX uptime function with ps etimes-based implementation#1967shirou merged 3 commits intoshirou:masterfrom
shirou merged 3 commits intoshirou:masterfrom
Conversation
Previously, the AIX host module parsed the output of the `uptime` command to determine system uptime. This approach had limitations in terms of reliability and parsing complexity due to the variable output format of the uptime command. This change replaces the uptime-based approach with a more reliable method: querying PID 1's elapsed time using `ps -o etimes -p 1`. This directly accesses the process table rather than relying on human-readable output. The new implementation handles three possible etimes output formats: - DAYS-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 zero Changes: - Updated UptimeWithContext() to execute `ps -o etimes -p 1` - Added validation to ensure at least 2 rows of output (header + data) - Modified parseUptime() to handle the new etimes format with flexible time component parsing - Added graceful error handling that returns 0 for malformed input - Updated function comments to document the new approach and formats Tests: - Replaced all test cases to use the new etimes format - Added test coverage for all three time format variations - Updated invalid input test cases to reflect new parsing logic
- Convert if-else chain to switch statement in parseUptime() to satisfy gocritic - Format files with goimports/gofmt to resolve gci formatting issues These changes address all remaining linter warnings reported by golangci-lint.
4 tasks
shirou
reviewed
Dec 20, 2025
shirou
approved these changes
Dec 23, 2025
Owner
shirou
left a comment
There was a problem hiding this comment.
Thank you for your update. now LGTM!
This was referenced Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.