|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import psutil |
|
import streamlit as st |
|
import time |
|
import datetime |
|
from streamlit_autorefresh import st_autorefresh |
|
from streamlit_apex_charts import bar_chart, pie_chart |
|
import pandas as pd |
|
import platform |
|
import os |
|
|
|
|
|
st.set_page_config(page_title="系统信息查看器", page_icon="💻", layout="wide") |
|
|
|
|
|
|
|
st.header("系统信息查看器") |
|
base_infor = [[datetime.datetime.now().strftime("%Y-%m-%d %H: %M: %S"),str(psutil.users()[0][0]),platform.platform()]] |
|
df_base_infor = pd.DataFrame(base_infor, columns=["当前时间","登陆者","操作系统"]) |
|
st.table(df_base_infor) |
|
|
|
|
|
def get_key(): |
|
key_info = psutil.net_io_counters(pernic=True).keys() |
|
recv = {} |
|
sent = {} |
|
for key in key_info: |
|
recv.setdefault(key, psutil.net_io_counters(pernic=True).get(key).bytes_recv) |
|
sent.setdefault(key, psutil.net_io_counters(pernic=True).get(key).bytes_sent) |
|
return key_info, recv, sent |
|
|
|
|
|
def get_rate(func): |
|
key_info, old_recv, old_sent = func() |
|
time.sleep(1) |
|
key_info, now_recv, now_sent = func() |
|
net_in = {} |
|
net_out = {} |
|
for key in key_info: |
|
net_in.setdefault(key, (now_recv.get(key) - old_recv.get(key)) / 1024) |
|
net_out.setdefault(key, (now_sent.get(key) - old_sent.get(key)) / 1024) |
|
return key_info, net_in, net_out |
|
|
|
|
|
c1, c2, c3 = st.columns(3) |
|
|
|
with c1: |
|
|
|
mem = psutil.virtual_memory() |
|
zj = float(mem.total) / 1024 / 1024 / 1024 |
|
ysy = float(mem.used) / 1024 / 1024 / 1024 |
|
kx = float(mem.free) / 1024 / 1024 / 1024 |
|
|
|
data_neicun = [[round(ysy,2),round(kx, 2)]] |
|
df_neicun = pd.DataFrame(data_neicun, columns=["已用内存","空闲内存"]) |
|
pie_chart("内存使用情况(GB)", df_neicun) |
|
|
|
|
|
|
|
cpu_liyonglv = (str(psutil.cpu_percent(1))) + '%' |
|
cpu_data = [[cpu_liyonglv]] |
|
df_cpu = pd.DataFrame(cpu_data, columns=["CPU利用率"]) |
|
bar_chart("CPU利用率(%)", df_cpu) |
|
|
|
with c2: |
|
|
|
dk = psutil.disk_usage('/') |
|
total = dk.total / 1024 / 1024 / 1024 |
|
used = dk.used / 1024 / 1024 / 1024 |
|
free = dk.free / 1024 / 1024 / 1024 |
|
|
|
cipan_shiyong = [[used, free]] |
|
df_cipan = pd.DataFrame(cipan_shiyong, columns=["已使用磁盘大小","空闲磁盘大小"]) |
|
pie_chart("磁盘使用率(%)", df_cipan) |
|
|
|
|
|
key_info, net_in, net_out = get_rate(get_key) |
|
wangka_liuliang = [] |
|
for key in key_info: |
|
wangka_liuliang.append([net_in.get(key),net_out.get(key)]) |
|
speed_internet = wangka_liuliang |
|
df_speed = pd.DataFrame(speed_internet, columns=["下行速率","上行速率"]) |
|
bar_chart("网络速率(kb/s)", df_speed) |
|
|
|
|
|
|
|
with c3: |
|
|
|
pids = psutil.pids() |
|
process = [] |
|
for pid in pids: |
|
p = psutil.Process(pid) |
|
process_name = p.name() |
|
process.append([pid, process_name, p.is_running()]) |
|
|
|
df_process = pd.DataFrame(process, columns=["PID","进程名","是否还在运行"]) |
|
st.dataframe(df_process) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|