0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

メモリ使用率を監視し、閾値を超えたら処理を実行する

Posted at

メモリ使用率の監視

今回はメモリ使用率を監視し、閾値を超えたら処理を実行するコードを紹介。

メモリ使用率が高くなったらアプリケーションを再起動するコードです。

#!/bin/bash
MEM_LIMIT=80
while true
do
    sleep 10
    USED_MEM=`free | grep Mem | awk '{print int($3/$2*100)}'`
    if [ $USED_MEM -gt $MEM_LIMIT ]
    then
        lsof -t -i :80 | xargs kill -9
        sleep 2
        <アプリケーション起動コマンド> &

    fi
done

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?