Linux ETC

watch 로 시스템 모니터링 하기

2008.05.19 20:38

호스트웨이 조회 수:25533

주기적으로 실행한 프로그램 결과를 화면에 보여 주는 기능을 함.
시간이 오래 걸리는 작업이나 주기적인 모니터링이 필요한 작업시 유용함.

[사용법]
[root@localhost]# watch --help
Usage: watch [-dhnv] [--differences[=cumulative]]
[--help] [--interval=<n>] [--version] <command>
  -d, --differences[=cumulative]        highlight changes between updates
                (cumulative means highlighting is cumulative)
  -h, --help                            print a summary of the options
  -n, --interval=<seconds>              seconds to wait between updates
  -v, --version                         print the version number



기본 사용 방법)
[root@localhost]# watch [-d] [-n seconds] 'command'
종료는 [Ctrl + c]

예제 1)
실시간으로 바뀌는 시스템의 uptime 값을 화면에 계속 출력(1초간격)

[root@localhost]# watch -d -n 1 'cat /proc/uptime'

Every 1s: cat /proc/uptime          Mon Jan 23 15:09:28 2006

5285573.48 5257905.40

uptime과 loadavg를 한꺼번에 출력
[root@localhost]# watch 'cat /proc/{loadavg,uptime}'


예제 2)
아파치 프로세스를 모니터링 하기
[root@localhost]# watch -d -n 1 'ps -ef | grep httpd | grep -v grep'


예제 3)
여러가지 명령어를 조합해서도 가능 함.
- 현재 접속한 모든 사용자 출력
- 현재 디스크의 파티션별 사용량 출력
- 최근 접속자 10줄 출력
(명령어들을 ';'로 구분함, echo는 공백줄을 출력,추기 2초 간격)

[root@localhost]# watch -d 'w; echo; df -k; echo; last -n 10'