ダイナミック・モニタリング・matplotlibのは、PythonのCUP 1分(60秒)をプロット

インポートは、AS PLT matplotlib.pyplot 
 インポートpsutil
 インポート時間

#1 、エクスポートのフォント設定ステップ1 
から matplotlibのインポートfont_managerの 
 #のステップ2は、フォント、フォント・モジュールと位置リードアウト定義 
my_font = font_manager.FontProperties(FNAME = " は/ usr /共有/フォント/ TrueTypeフォント/ノート/ simsun.ttf 

plt.ion() 

定義グローバル変数 
CPU = [] 
タイムズ = [] 
MEM = [] 、メモリMEMを注意=記憶= 
IO = [] 

定義関数
DEF GET_INFO( ):
    cpu_per = psutil.cpu_percent()
    MEM = psutil.virtual_memory()
    mem_used = mem.used 
    mem_total = mem.total 
    mem_used_per =(mem_used / mem_total * 100 
    IO = psutil.disk_io_counters()
    io_cnt = io.read_count + io.write_count 

    戻りcpu_per、mem_used_per、io_cnt 

C = 0    変数を設定し
ながら、 C <61である:#が真以前デッドサイクルであるが、カスタマイズすることができ、停止、特定の数を観察した 
    T = time.strftime(" %H:%M:%のS " 、time.localtime() )
    cpu_per、mem_used_per、io_cnt = GET_INFO() 
    times.append(T)
    cpu.append(cpu_per)
    mem.append(mem_used_per)
    io.append(io_cnt) 

    AX1:最初の図の 
    AX1 = plt.subplot(221) アイコンAX1の位置:2行の2、最初の行1 
    ax1.patch.set_facecolor(ブラック#は、背景色領域Axの設定  
    ax1.figure.set_facecolor(ピンク設定した後、全体図ポップ、または写真の後に、背景色はピンクです

    PLTを。プロット(タイムズ、CPU、ラベル = ' CPU '、色= ' B ' #のステップ3:中国の表示:プラスU = my_fontとfontproperties 
    plt.ylabel(uは' CPU使用率%'。、のfontSize = 8、fontproperties = my_font、カラー= ' ' 
    plt.xticks(回転 = 30、= 4のfontSize。 
    plt.yticks(範囲(0、 110、10 )) 
    
    2図の: 
    PLTのAX2 =。サブプロット(222) 2行2列で、最初の行2 
    ax2.patch.set_facecolor(' ブラック' 

    plt.plot(タイムズ、MEM、ラベル = ' MEM '、カラー= ' G ' 
    plt.ylabel (U ' MEM利用%'、=のfontSize。8、fontproperties = my_font、カラー= ' '  
    Plt.xticks(回転 = 30、= 4のfontSize。 
    plt.yticks(範囲(0、 110、10 )) 

    図3: 
    plt.subplot =(212)のAX3 2行1列において、第2第二列= 2 
    ax3.patch.set_facecolor(' ブラック' 
    
    plt.plot(タイムズ、IO、ラベル = ' IO '、カラー= ' Y ' 
    plt.ylabel(U ' IO処理数の%'、のfontSize = 。8、fontproperties = my_font、カラー= ' ' 
    plt.xticks(回転 = 30、=のfontSize。4 
    
    plt.pause(1 

    C + 1 = + +1当たり
    
plt.ioff()
plt.show()
コードの表示

おすすめ

転載: www.cnblogs.com/ysysbky/p/12212436.html