CPU Limit

I need some input.

As of the moment, I am taking a new CPU reading and averaging it with the existing value. In the case that there is no reading, I average a zero.

Is that how it should work? I can't decide.
 
Yes I guess that's how you'd do it. No running processes would mean a cpu load of 0.

Will this be a problem with the second reread though? The actual reading will take some time as well, and perhaps this way some domains can slip through. Although that won't be for the large ones eating up the resources that's true...

I'll think I'm really liking the way this project is taking! :D
 
I would think the best way is:

=================================
MySQL
=================================
Domain || 1 || 2 || 3 || avg
=================================
test.com || 0.01 || 0.08 || 0.03 || 0.04
test2.com || 0.08 || 0.03 || 0.01 || 0.04
=================================

Basically the avg value is the average over 10 minutes which the script could use....

Every 5 minutes you get the cpu usage and do the following

1, 2 and 3 are the 5 minutes intervals - 1 being the most recent 2 being 5 minutes ago and 3 being 10 minutes ago.

Move the current value in 2 to 3
Move the current value in 1 to 2
Get the current CPU usage for this domain and insert that into 1

Basically every 5 minutes you move the previous value to 5 minutes later on.... after 10 minutes it gets overwirriten and removed.

Im getting the average by simply adding the last 3 usage amounts up then dividing it by 3 :)

Chris
 
S2S-Robert said:
Yes I guess that's how you'd do it. No running processes would mean a cpu load of 0.

Will this be a problem with the second reread though? The actual reading will take some time as well, and perhaps this way some domains can slip through. Although that won't be for the large ones eating up the resources that's true...

I'll think I'm really liking the way this project is taking! :D

Have you tried the method?... if not, try it and view the page - the page gets updated every refresh, basically everytime http is accessed.

Chris
 
Why would you want a 5 minute 'screenshot' of the actual processes running? I see the second delay already as a problem, let alone the 5 minutes!

That would mean a lot of domains wouldn't have any cpu usage at all but will still be serving pages.

[edit]
So you would just set the refresh to 1 second then and put the calculated values into the mysql?
 
If you were updating @1 second I suppose your columns would be 1sec, 2sec and 3sec.

I like that method (of course the update interval will be changable).
 
The php script can be set to get the values every X seconds... what you want to do with them is your choice - my idea to put them into mysql allows them to be stored neatly and easy access is then enabled.

An average over 10 minutes would be much more fair then an average over 3 seconds...... if there was something huggely wrong worth worrying about it would probably last more than 3 seconds.

Chris
 
Dont like the idea of 1 second...... that means you have mysql running processes every second moving table rows every second along with that a php script parsing information of all data being accessed through apache to simply monitor the cpu usage of a domain.

As I stated in my previous post.... if they are doing something such as trying to kill your server or causing the server to slow down drastically for any reason it would surely last more than 3 seconds?!

Chris
 
l0rdphi1 said:
Next will be the account suspension stuff @X, I guess.

I will do that if you want..... first we need John or Mark to get us a command to suspend and suspend for any reason

Could always finish it up by making a complete package.... with the idea:

make a copy / backup of your current php.ini
add whats needed to the php.ini
setup the sql tables
restart apache
setup cron jobs for php script
setup cron jobs for shell script to check usage and suspend appropritely.

Would make a neat little package i think :D

Chris
 
Yeah, cool. There is one small problem though. To get a username based on their domain, I need to go through each of /usr/local/directadmin/data/users/*/domains.list until I find a match, correct? I guess that is the easiest way, is it not?

Thanks :D
 
Would it be possibly to have a simple 1 line script.... I think the idea of an option to suspend accounts generally in the panel may also be a good idea..... if the site is an 'offender' you could simply tap that button instaed of removing their site totally or flooding the their quotas :p

/usr/local/directadmin/scripts/suspenduser suspend <user>
/usr/local/directadmin/scripts/suspenduser unsuspend <user>

Anything thats a 1 line argument and has 2 simple options of unsuspend or suspend and an option to specify the user will do me :D

Chris
 
That would make things easier, yes, but if we use a command line method like that, won't it render the script useless under safe_mode? I am *not* sure of that, let alone whether it's important or not, but it's something to find out.

On a side note, I set up a cron job this morning to run the script every 5 minutes, and let me tell you, I love this thing! :P
 
No, this half would be totally seperate to the php.... the php has its own cron job and that would simply keep mysql up-to-date I assume and possibly just make a table of domains to suspend..... then the shell script simply checks that database for any domains, if its there it will suspend else nothing is affected.....

But dont forget everything is executed via shell and what scripts are run as can be chnaged..... aslong as nothing is accessable via the web (just set the area of your php.ini to deny all)

Chris
 
Ah yes, that makes sense. Great! :)

The script that disables/enables the accounts will be nothing more than:
Code:
SUSPENSION_DURATION = 300
MAX_CPU = 20

while "SELECT domain FROM cpu_monitor WHERE cpu_x1>MAX_CPU" {

      user = GET_USER(domain)

      `/usr/local/directadmin/scripts/suspenduser suspend <user>`

      "INSERT INTO suspended (domain,user,time) VALUES (domain,user,TIME)"
      // above could be cached and inserted all at once after the while()

}

while "SELECT user, domain FROM suspended WHERE time<TIME-SUSPENSION_DURATION" {

      `/usr/local/directadmin/scripts/suspenduser unsuspend <user>`

      "DELETE FROM suspended WHERE domain='domain' LIMIT 1"
      // again, could be cached and ran all at once after the while()

}
 
The idea of suspending the entire domain is somewhat rough for my taste. If the domain exceeds a certain threshold I'd rather be e-mailed about that fact especially if the average of that domain exceeds the threshold for more than xxx hours.

I don't think load balancing will be in place right? Because that would be ideal, if the load of that particular domain is over the threshol level then just cap that domain at whatever you want.
 
S2S-Robert said:
The idea of suspending the entire domain is somewhat rough for my taste. If the domain exceeds a certain threshold I'd rather be e-mailed about that fact especially if the average of that domain exceeds the threshold for more than xxx hours.
I like that. Sounds like a nice alternative to pissing off people :) However, since the script that would suspend or email is separate from the one that collects data, you can do whatever you want.

S2S-Robert said:
I don't think load balancing will be in place right? Because that would be ideal, if the load of that particular domain is over the threshol level then just cap that domain at whatever you want.
Limiting the users' load would be ideal, but I'm not sure it's possible.
 
Or an inbetween suggestion that covers both problems - set email alerts as soon as the usage goes to X then once it goes to X2 the site gets suspended..... after a certain load it would be quite stupid to leave the site up I would think
 
Back
Top