2013-07-08 140 views
2

我有一臺服務器(Ubuntu的),該服務器上的多個域和運行一系列的cron腳本。但是無法預測服務器上的負載,因此我無法在cron腳本中設置正確的負載量。服務器負載均衡腳本

然而,在cron運行的腳本,從時間過載時間和生成CPU和內存在巨大的負荷,從而導致服務器的幾個服務的停止(如郵件服務器爲例)。

的問題是:我怎麼能寫在運行,現在都在cron僅在服務器負載最小閾值以下的程序腳本?有什麼應用程序可以在Linux下執行此操作嗎?

謝謝您的時間!

+0

您是否嘗試過重新整理流程? – mnagel

+0

是的,實際上我試圖簡化腳本很多,但我無法預測是否有任何迭代需要花費1分鐘或15分鐘,因此當在cron中運行的幾個腳本同時運行時,服務器上會出現巨大的負載 – Mike

回答

1

可以檢查monit系統管理。 您可以添加到這個配置文件:

 


    # Monitoring the apache2 web services. 
    # It will check process apache2 with given pid file. 
    # If process name or pidfile path is wrong then monit will 
    # give the error of failed. tough apache2 is running. 
    check process apache2 with pidfile /var/run/apache2.pid 
    start program = "/etc/init.d/apache2 start" 
    stop program = "/etc/init.d/apache2 stop" 
    # Admin will notify by mail if below of the condition satisfied. 
    if cpu is greater than 60% for 2 cycles then alert 
    if cpu > 80% for 5 cycles then restart 
    if totalmem > 200.0 MB for 5 cycles then restart 
    if children > 250 then restart 
    if loadavg(5min) greater than 10 for 8 cycles then stop 
    if 3 restarts within 5 cycles then timeout 
    group server 

這是一個很好的工具,你可以搜索如何執行自己的腳本,當條件滿足。