Ubuntu在标题栏显示CPU、内存、网速和温度

编程入门 行业动态 更新时间:2024-10-10 12:25:23

Ubuntu在标题栏显示CPU、内存、<a href=https://www.elefans.com/category/jswz/34/1767686.html style=网速和温度"/>

Ubuntu在标题栏显示CPU、内存、网速和温度

1. 安装System Monitor Indicator:
sudo add-apt-repository ppa:alexeftimie/ppa
sudo apt-get update
sudo apt-get install indicator-sysmonitor
也可以通过这个链接下载安装: .0/+download/indicator-sysmonitor_0.4.3_all.deb 2. 默认只显示CPU、内存,要显示上下行网速和温度的话需要安装另外两个东西:
sudo apt-get install dstat
sudo apt-get install acpi
3. 从链接 .info/Indicator-Sysmonitor-Show-Nework_speed-&-CPU-Temp/sysmon下载 sysmon文件,放入主目录,重命名为.sysmon。如果上面的链接下载不了,可以新建个sysmon文件,把下面的源代码复制过去:
#!/bin/bash#settings:
netspeed=true
ram=true
cpu=true
temp=false
#---------------- initialize ---------------------------
rm /tmp/.sysmon > /dev/null 2>&1
dstat --net --mem --cpu --output=/tmp/.sysmon 1 1 > /dev/null 2>&1
#----------- up/down speed -----------------------------
if [ $netspeed = true ]; then
upspeed=$(echo $(cat /tmp/.sysmon | tail -1 | cut -d ',' -f2)/1024 | bc)
upkbmb=$(if [ $upspeed -gt 1024 ]; then up1=$(echo $(cat /tmp/.sysmon | tail -1 | cut -d ',' -f2)/1024/1024 | bc -l)echo $up1 | head -c 4else echo $upspeed | head -c 3fi)
downspeed=$(echo $(cat /tmp/.sysmon | tail -1 | cut -d ',' -f1)/1024 | bc)
downkbmb=$(if [ $downspeed -gt 1024 ]; then down1=$(echo $(cat /tmp/.sysmon | tail -1 | cut -d ',' -f1)/1024/1024 | bc -l)echo $down1 | head -c 4else echo $downspeed | head -c 3fi)
#---------------- up/down speed unit --------------------
upunit=$(if [ $upspeed -gt 1024 ]; then echo "MiB/s"; else echo "KiB/s"; fi)
downunit=$(if [ $downspeed -gt 1024 ]; then echo "MiB/s"; else echo "KiB/s"; fi)
fi
#------------------- CPU % used -------------------------
if [ $cpu = true ]; then
cpufree=$(cat /tmp/.sysmon | tail -1 | cut -d ',' -f9)
cpuused=$(echo 100-$cpufree | bc | sed -e 's/\..*//')
fi
#------------------- RAM % used --------------------------
if [ $ram = true ]; then
memused=$(free -m | grep buffers/cache | tr -s ' ' | cut -d' ' -f 3)
memfree=$(free -m | grep buffers/cache | tr -s ' ' | cut -d' ' -f 4)
memtotal=$(echo $memused+$memfree | bc -l)
memusedpercent=$(echo 100-100*$memfree/$memtotal | bc)
fi
#------------------- CPU °C Temp-------------------------
if [ $temp = true ]; then
cputemp=$(acpi -t | cut -c 16-20)°C
fi  
#------------------ The Indicator Sysmonitor actual output -
echo $(if [ $cpu = true ]; then echo CPU: $cpuused% \|; fi) $(if [ $ram = true ]; then echo Mem: $memusedpercent% \|; fi) $(if [ $temp = true ]; then echo Temp: $cputemp \|; fi)  $(if [ $netspeed = true ]; then echo ↑ $upkbmb $upunit  ↓ $downkbmb $downunit; fi)
然后settings中想显示的设为true,不想显示的设为false。 4. 找到System Monitor Indicator的设置,按下图配置,Customize output中有{sysmon}就可以:
5. 由于软件默认显示图标是 sysmonitor.svg,而在 Ubuntu 14.04 系统中没有这个图标,就会导致图标显示错误,很不美观。我们可以把软件默认使用的图标改成一个存在的图标,当然也可以自己动手制作一个图标。但是系统中已经有很多图标了,找个好点的直接用上就行! 系统图标存放在 /usr/share/icons/Humanity/apps/XX目录下(XX 为:128、16、192、22、24、32、48、64中任意一个,对应同一图标的不同尺寸,同一图标并不是每个尺寸都有,其中48的最多)。例如打开/usr/share/icons/Humanity/apps/48,发现 utilities-system-monitor.svg 还不错,我就用这个图标,当然用其他的或者自己制作也是可以的。 找到喜欢的图标后,记下图标的文件名(不包括后缀),下面开始进行替换。终端执行命令:
sudo gedit /usr/bin/indicator-sysmonitor
将 724 行的 sysmonitor 改为刚才记下的utilities-system-monitor

更多推荐

Ubuntu在标题栏显示CPU、内存、网速和温度

本文发布于:2024-02-11 02:37:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1678687.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网速   标题栏   温度   内存   Ubuntu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!