Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- hash table
- 알고리즘
- Priority Queue
- django
- boj
- aws
- spring boot
- 코테
- 구현
- Trie
- 모의SW역량테스트
- Bruth Force
- Back tracking
- 시뮬레이션
- BFS
- CSV
- 알고리듬
- Python
- 코딩테스트
- Vue.js
- Data Structure
- SWEA
- DFS
- SQL
- gpdb
- programmers
- JavaScript
- Algorithm
- GitHub
- Linked list
Archives
- Today
- Total
hotamul의 개발 이야기
python으로 sar 명령 실행하기 본문
sysstat, sar을 이용한 resource 모니터링에서 sar
을 이용해 resource 사용량 확인 방법에 대해서 알아보았다.
아래는 python으로 해당 명령을 실행하고 결과를 print
하기 예시
import subprocess
# sar 명령어 실행
sar_process = subprocess.Popen(['sar', '-u', '1', '3'], stdout=subprocess.PIPE)
# sar 결과를 딕셔너리로 파싱
output = sar_process.communicate()[0].decode()
lines = output.split('\n')
header = lines[2].split()
cpu_usage = {}
for line in lines[3:]:
if line:
fields = line.split()
timestamp = fields[0] + ' ' + fields[1]
cpu_stats = {}
for i, field in enumerate(fields[2:]):
cpu_stats[header[i+2]] = float(field)
cpu_usage[timestamp] = cpu_stats
# 출력
print(cpu_usage)
'etc.' 카테고리의 다른 글
cgroup으로 pids.max 제한하기 (0) | 2023.03.14 |
---|---|
cgroup으로 CPU 제한하기 (1) | 2023.03.14 |
sysstat, sar을 이용한 resource 모니터링 (0) | 2023.03.12 |
cgroups을 이용한 메모리 동적 할당 (Facebook 사례 분석) (0) | 2023.03.11 |
[AWS] Unprotected private key file (0) | 2023.03.08 |
Comments