Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_head.sh assumes uptime has same format all the time #576

Closed
krzyk opened this issue Sep 5, 2014 · 15 comments
Closed

_head.sh assumes uptime has same format all the time #576

krzyk opened this issue Sep 5, 2014 · 15 comments
Labels

Comments

@krzyk
Copy link

krzyk commented Sep 5, 2014

The line below:

load=$(uptime | awk '{print $12}' | cut -d ',' -f 1)

Is not always correct.

On my system load average currently has such value:

 17:31:21 up  8:39,  9 users,  load average: 0.85, 0.92, 0.91

as you can see it has only 11 values, not 12 like is assumed in the awk above.

12 value will appear when system is up for at least 1-2 days then it will look like this:

 10:31:27 up 266 days, 10:51,  2 users,  load average: 2.29, 2.76, 3.01

Now instead of 8:39 it is 266 days.
So for instances that are younger than 1 day it will return empty string which will always pass load average check that is below and overload given machine.

I would propose to instead use cat /proc/loadavg and get value at third position (here number 0.82).

0.48 0.71 0.82 2/800 7706
@yegor256 yegor256 added the bug label Sep 5, 2014
@yegor256
Copy link
Owner

yegor256 commented Sep 5, 2014

definitely a bug, thanks for reporting!

@alex-palevsky
Copy link
Contributor

I'll find a developer for the task soon...

@alex-palevsky
Copy link
Contributor

thank you for the ticket reported, I topped your account for 15 mins, transaction 44194627

@alex-palevsky
Copy link
Contributor

@yegor256 please proceed, it's yours

@yegor256
Copy link
Owner

yegor256 commented Sep 7, 2014

the problem is that /proc/loadavg doesn't exist in MacOS...

@krzyk
Copy link
Author

krzyk commented Sep 8, 2014

In this case using $NF (instrad of $12) in awk will also do the trick.

@yegor256
Copy link
Owner

yegor256 commented Sep 8, 2014

I'm thinking how to unit test this problem first...

@alex-palevsky
Copy link
Contributor

@yegor256 the task is not yours any more,stop now

@alex-palevsky
Copy link
Contributor

@dpisarenko this ticket is yours now, please proceed, and keep in mind this. Any technical questions you should ask right here

Total fixed cost of this task is 30 mins (see this for more info)

@mentiflectax
Copy link
Contributor

Is it correct that

  1. for input string 14:11:29 up 254 days, 6:11, 1 user, load average: 0.16, 0.05, 0.06 the result should be 0.06 and
  2. for input string 17:31:21 up 8:39, 9 users, load average: 0.85, 0.92, 0.91 the result should be 0.91

?

@mentiflectax
Copy link
Contributor

I found a preliminary solution for this problem: | sed 's/ /\n/g' | tail -n 1.

On my machine (Windows, Git bash) both following commands return the expected result (0.06 and 0.91, respectively).

  • echo 14:11:29 up 254 days, 6:11, 1 user, load average: 0.16, 0.05, 0.06 | sed 's/ /\n/g' | tail -n 1
  • echo 17:31:21 up 8:39, 9 users, load average: 0.85, 0.92, 0.91 | sed 's/ /\n/g' | tail -n 1

Are there any reasons not to use | sed 's/ /\n/g' | tail -n 1 instead of | awk '{print $12}' | cut -d ',' -f 1 ?

@krzyk
Copy link
Author

krzyk commented Dec 26, 2014

@dpisarenko looks correct (I would use different command, but there is nothing wrong with the one you used), let's see what the reviewer will say

@mentiflectax
Copy link
Contributor

@yegor256 @krzyk Can this task be closed now, or is there anything else to do?

@krzyk
Copy link
Author

krzyk commented Dec 30, 2014

Thanks

@krzyk krzyk closed this as completed Dec 30, 2014
@alex-palevsky
Copy link
Contributor

@dpisarenko Many thanks! 30 mins were added to your account in Transaction ID 49695304

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants