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?

More than 1 year has passed since last update.

監視系ワンライナー

Posted at

監視系ワンライナーです。下記サイトを参考にしています。ログ監視系は新規作成しました。

環境に合わせて読み直してください。

■CPU使用率
```cat /proc/loadavg | cut -d ' ' -f 2 |while read i; do if [ echo "${i} >= 0.01" | bc -eq 1 ]; then echo ${i} ;fi ; done

■メモリ利用率
```free | grep Mem | awk '{ print ($2-$7)/$2*100 }' | while read i; do  if [ `echo "${i} >= 40" | bc` -eq 1 ]; then echo ${i}  ;fi ; done

■Disk使用率
```df / | tail -1 | /bin/sed 's/^.* ([0-9])%.$/\1/' | while read i; do if [ echo "${i} >= 40" | bc -eq 1 ]; then echo ${i} ;fi ; done

■ログ監視系
AWKを利用した場合
```tail -n 0 -F /var/log/messages | awk '/error/ {system("date")}'
```Ctl+Cを行うまで監視継続

grepを利用した場合
```tail -n 0 -F  /var/log/messages | grep -q "error"  | if [ $? = "0" ]; then more test.txt  ;fi
```一回検知後にIF文終了とともにシェルも終了します。
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?