---코드---
# 자동화 스크립트
# 문제. DBA 작업을 편하게 하는 자동화 스크립트 2번을 막대 그래프를 출력하는 것으로 변경
from collections import Counter
import matplotlib.pyplot as plt
import pandas as pd
oracle_alert = open("c:\\data\\alert_log.txt")
oracle_text = oracle_alert.read()
lines = oracle_text.split('\n') # 엔터로 분리하여 리스트에 저장
error = []
while True:
print('===============================================')
print('dba 작업을 편하게 하기 위한 자동화 스크립트')
print('1. alert log file 뒷부분')
print('2. 20회 이상 발생한 오라클 에러 시각화')
print('3. 오라클 에러별 개수 조회')
print('9. 종료')
print('===============================================')
num = int(input('번호를 입력하세요'))
if num == 1:
oracle_alert = open("c:\\data\\alert_log.txt")
oracle_text = oracle_alert.read()
print(oracle_text[-900:])
break
elif num == 2:
for i in lines:
if 'ORA-' in i:
error.append(i.split(' ')[0].strip(':'))
result = Counter(error)
df_error = pd.DataFrame(list(Counter(error).items()), columns=['에러 번호', '건수'])
df_err = df_error.loc[df_error.건수 >= 20, :]
df_sort = df_err.sort_values(by='건수', ascending=False)
k = df_sort.loc[:, ['에러 번호']]
n = df_sort.loc[:, ['건수']]
plt.rcParams['font.family'] = 'Malgun Gothic'
plt.bar(k['에러 번호'], n['건수'], color='lightcoral')
break
elif num == 3:
for i in lines:
if 'ORA-' in i:
error.append(i.split(' ')[0].strip(':'))
result = Counter(error)
print(result)
break
elif num == 9:
break
else:
print('잘못된 번호입니다.')
---코드 실행---