shirou / gopsutil

psutil for golang
Other
10.53k stars 1.59k forks source link

Resolved Issue 1661 - AIX Runtime Panic in Host #1663

Closed aidangill-projects closed 3 months ago

aidangill-projects commented 4 months ago

Resolved an issue on AIX where a software panic was caused at 0 minutes on the hour when uptime was called.

When uptime is called at 00 minutes it shows as this:

08:47PM up 2 days, 20 hrs, 1 user, load average: 2.47, 2.17, 2.17

At 20:21 it shows as this:

08:47PM up 2 days, 20:21, 1 user, load average: 2.47, 2.17, 2.17

I've added logic to parse this new case, code now passes all given examples (tried to add some tests, not sure how you want to mock the command line use, would be happy to add with an example).

shirou commented 4 months ago

The PR seem good to me. However, given the variety of output results, could you separate the parse part into a different function and make it testable? Something like func parseUptime(in string) (unit64, error) could be considered. This function would take the output string of uptime as an argument and return the total_time.

aidangill-projects commented 4 months ago

I've done that + added tests.. it returns zero on error at the moment as before, let me know if you want any changes

aidangill-projects commented 4 months ago

Hey mate might need to check this, bit of a noob at Go to be honest, the numbers in those tests were incorrect but seemed like they were passing, updated to be correct - also the test suite here in github doesn't seem to check AIX, might need updating

aidangill-projects commented 4 months ago

Found another case of failure - added to code / tests:

01:16AM up 4 days, 29 mins, 1 user, load average: 2.29, 2.31, 2.21

This command line tool is pretty inconsistent huh

shirou commented 4 months ago

Does the uptime command of AIX has some option like -s? At least my Linux has the option and the output seems stable.

% uptime -s
2024-06-03 01:42:58
aidangill-projects commented 4 months ago

It's very rudimentary and does not I'm afraid, not the best platform, I've gone through the options and this is all it gives - I will be able to test this thoroughly though and update with any further issues if any however, I've got a script running every minute at the moment

aidangill-projects commented 3 months ago

Hey mate let me know what you want me to do with this one, worth noting it doesn't just effect the uptime call, it effects the whole host library on AIX as other calls also request uptime 👍

aidangill-projects commented 3 months ago

Nothing more I can see, if I find anything I'll be back 🤣

Dylan-M commented 3 months ago

This will need cherry picked to the 3.x maintenance bugfix releases too, if you can please.

Thank you @aidangill-projects for the additions on this. I thought I caught all of the variations on the formats when I wrote this, but obviously not.

Dylan-M commented 3 months ago

Fixes #1661