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

1. 安装System Monitor Indicator:
sudo add-apt-repository ppa:alexeftimie/ppa
sudo apt-get update
sudo apt-get install indicator-sysmonitor
2. 默认只显示CPU、内存,要显示上下行网速和温度的话需要安装另外两个东西:
sudo apt-get install dstat
sudo apt-get install acpi
3. 从链接 http://anerd.sourceforge.net/a-nerd.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 4
	else 
		echo $upspeed | head -c 3
	fi)
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 4
	else 
		echo $downspeed | head -c 3
	fi)
#---------------- 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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孙强 Jimmy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值