import psutil
import streamlit as st
import time
import datetime
from streamlit_autorefresh import st_autorefresh
from streamlit_apex_charts import line_chart, bar_chart, pie_chart, area_chart, radar_chart
import pandas as pd
from pandas.core.frame import DataFrame
import platform
st.set_page_config(page_title="系统信息查看器", page_icon="💻", layout="wide")
st_autorefresh(interval=5000, limit=100000, key="Mr.R")
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)
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
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)
#数据传输
data_receive_send = [[round(psutil.net_io_counters().bytes_sent/1024/1024/1024,2),round(psutil.net_io_counters().bytes_recv/1024/1024/1024,2)]]
df_data = pd.DataFrame(data_receive_send, columns=["发送数据大小","接收数据大小"])
bar_chart("发送接收数据情况(GB)", df_data)
with c3:
#网络速率
s1 = psutil.net_io_counters(pernic=True)['WLAN']
s2 = psutil.net_io_counters(pernic=True)['WLAN']
result = s2.bytes_recv - s1.bytes_recv
speed_internet = [[round(result/1024,2)]]
df_speed = pd.DataFrame(speed_internet, columns=["网络速率"])
bar_chart("网络速率(bytes/s)", df_speed)
#进程信息
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)
Nice… quick off the mark using the new st_autorefresh
component
Yes, I used the st-autorefresh component to refresh the system data.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.