|
之前我们你已经说过了led管控机制
4 _1 \4 p! f) ]5 j/ m* d7 } 聊一聊x3p的LED控制机制
# W% J% O, N0 r& W和用led来显示硬盘温度6 \4 U4 ?+ ]5 B' Y) x
让你的RGB灯来指示系统温度6 J2 Q: s: Y; T. k/ n
现在我们可以进一步让led来显示系统网速,且往下看
9 c5 R4 k" z5 o) s3 K" y6 v& \需要用到一个python脚本来获取系统的联网状态以及各个io状态- e: K6 \" c- H
- import psutil
. Y# M, |" r7 W - print(psutil.net_io_counters(pernic=True))
复制代码 输出结果是下面的
* Y8 i6 E1 i R% g9 G- {
' `" L+ h5 n) t. s5 s: U3 y - 'bond0': snetio(bytes_sent = 0, bytes_recv = 0, packets_sent = 0, packets_recv = 0, errin = 0, errout = 0, dropin = 0, dropout = 0),
0 p0 |% b: I/ t$ F. t" `' j - 'lo': snetio(bytes_sent = 371531983, bytes_recv = 371531983, packets_sent = 649842, packets_recv = 649842, errin = 0, errout = 0, dropin = 0, dropout = 0),
+ H" B$ S4 I# O' k - 'tun0': snetio(bytes_sent = 300576, bytes_recv = 0, packets_sent = 9393, packets_recv = 0, errin = 0, errout = 0, dropin = 0, dropout = 0),
@& N) W8 y$ t - 'sit0': snetio(bytes_sent = 0, bytes_recv = 0, packets_sent = 0, packets_recv = 0, errin = 0, errout = 0, dropin = 0, dropout = 0),
/ @1 a, A; k8 K* D - 'ip_vti0': snetio(bytes_sent = 0, bytes_recv = 0, packets_sent = 0, packets_recv = 0, errin = 0, errout = 0, dropin = 0, dropout = 0),; ^( K" Z/ O( i) C
- 'eth0': snetio(bytes_sent = 10911429402, bytes_recv = 387312110, packets_sent = 722569, packets_recv = 1194110, errin = 0, errout = 0, dropin = 5, dropout = 0)' i5 r9 R6 C% E( d
- }
复制代码 有了数据就能够处理数据转化为网速了。( i6 L2 Q2 ]$ q. q# I
8 Q& U& w- B+ c- l+ z3 h
因为网速差别实在太大,所以我用了分级显示的方案:
2 ]% F% m; d" } S网速为B级别时显示红灯,网速越大,红灯越亮,不过放心,几乎看不到红灯
; x' ~; b" m+ x H8 I网速为K级别时显示绿灯,网速越快,绿灯越绿。这个比较常见,几乎上硬盘待机时就一直是绿灯7 H/ u, h k) T- t! `4 Q
网速为M级别时显示蓝灯,网速越高,蓝灯越艳丽,当你下载东西或者往硬盘传文件时就是蓝灯了。
3 M1 H% c. U$ H$ W- net_led_dn() {
& p- E, z& M5 g/ B - python /root/netspeed.py | sed -e "s/'/\n/g" -e 's/, /=/g' | grep } | awk -F '=' '{print $4}' >/root/new.rtx
& T# i- D0 S: R- a - new_rtx=$(cat /root/new.rtx)
( }) W! M* I( P. q0 s6 g - old_rtx=$(cat /root/rtx.log)8 t9 H8 m' B* \. w
- rtx=$(expr $new_rtx - $old_rtx)
7 c8 G) x/ s9 [ x1 t - echo $rtx: O& E0 y; c2 \# }& P5 S# m* }& O
- if [ $rtx -lt 1024 ]; then6 D: I+ H: f" y0 x
- ) J$ Q1 F% n( E- L9 l& _0 T0 m
- rtx_led=$(expr $rtx / 4)
5 L7 T" G3 q6 z6 X4 {, b - ' U; b7 G7 ^& Q( X# M% W% L+ W
- set_led c1 $rtx_led 0$ E% ]( n' l) n# S5 \
- set_led c2 0 09 T3 Z& ]: e3 l0 Y9 v* e
- set_led c3 0 0
9 X+ [; v1 r8 y, u, I - , m( O6 P! m0 u" n
- elif [ $rtx -lt 1048576 ]; then2 O {) B9 {7 l0 y! @4 z7 U
- rtx_led=$(expr $rtx / 4096)
- j0 z8 w* y' v+ h+ q# B - set_led c1 0 0
' x o7 P4 E7 g3 q+ k& r/ V# G. L - set_led c2 $rtx_led 0
1 q9 E" U) j0 o3 w0 {: s4 S7 n6 M5 q - set_led c3 0 0% d$ h. O* u; w& \
- elif [ $rtx -lt 1073741824 ]; then
6 \8 j+ B, f# j% v - rtx_led=$(expr $rtx / 4194304)
) z% X; a% |- ^6 o- M, l5 | - set_led c1 0 0% Y- _( m4 t; ?% S' o
- set_led c2 0 06 {# a0 L6 S. X) i5 v
- set_led c3 $rtx_led 0
- M% `8 Z4 k; V1 m. n* K' P1 D - fi
/ {/ o4 K' m5 h) e( T! [& M - echo $new_rtx >/root/rtx.log: d6 c; o$ Q% R' g8 n# Q" j6 b
- }
复制代码 这个只是显示下载网速的,如果想要显示上传网速也很简单,把第二行的$4改为$2就行了。
2 |# D1 ~6 h( b+ g下面是完整脚本,看附件吧。/ M4 u4 f" o8 \2 s* |
一共有五个文件
( w" M3 V6 ~3 a- }1 H" J- Y3 F- ledstatus.sh #放在/opt/bin文件夹下替换
- c5 K3 T! B" U1 r" @' g& p' B$ H - netspeed.py #放在root下
* `5 S# d4 O4 k- ^: m% P - new.rt #放在root下9 ?/ ?# \" Y. C$ k
- mew.rtx #放在root下9 J* d X5 i- Y$ ]2 b N
- rtx #放在root下
复制代码 ( ?( J( s; } ~+ D5 m' t
3 K# M _0 J. L9 z1 k
led_control.zip
(1015 Bytes, 下载次数: 114)
' _ W6 Z3 r4 ~解压密码(刮刮乐):chwhsen
m9 V7 ~ n3 p( `$ [; b9 R7 v; p6 ~5 f% \. K
7 _$ N" [% H. o
; u8 v! }( N2 N. B W- m7 P/ z9 b
|
评分
-
查看全部评分
|