首页 > 其他分享 >利用panda实现日志可视化分析的脚本

利用panda实现日志可视化分析的脚本

时间:2022-11-10 00:23:50浏览次数:42  
标签:log df 可视化 time ax 日志 csv panda

1. 准备慢日志的csv文件

import pandas as pd

import matplotlib.pyplot as plt

# 选取耗时大于7000的日志
# awk -F '耗时:' '{if (int(substr($2,0,length($2)-2)) >7000) print $0} '  debug.log.2022-11-02.log >7s.log
# 用,作为分隔符,使日志文件变成csv格式。awk -F','  'BEGIN{print "time" "," "log"}{print $1,",",$2,$3,$4}'  7s.log >timestamp_log07.csv

log_quality = pd.read_csv("D:\\Users\\usage_pandas\\data\\timestamp_log24.csv")

2. 用matplotlib.pyplot可视化

from pylab import mpl 
# 设置显示中文字体 
mpl.rcParams["font.sans-serif"] = ["SimHei"]
#设定绘图的画布
ax = pd.DataFrame(df_time_count.values).plot(grid=True,figsize=(80,12),legend=False)
ax.set_xlabel('time_5min') # X轴label
ax.set_ylabel('慢日志数数') # Y轴Label
ax.set_title('5min_interval_日志数') # 图题
#设定X轴月份显示格式
plt.xticks(
    range(len(df_time_count.index)), 
    [x.strftime('%H.%M') for x in df_time_count.index], 
    rotation=45)
plt.show() # 绘图

 

标签:log,df,可视化,time,ax,日志,csv,panda
From: https://www.cnblogs.com/hixiaowei/p/16875691.html

相关文章