|
之前我们你已经说过了led管控机制
3 `2 L$ [4 }8 I2 W9 ]9 i- J 聊一聊x3p的LED控制机制' a+ B ]) K5 M, q! R! q/ N
和用led来显示硬盘温度0 S! d" S* D0 h* Q5 K& b
让你的RGB灯来指示系统温度 E4 z F+ @+ {- b" q* F5 U% K
现在我们可以进一步让led来显示系统网速,且往下看
( l G& W& f+ G5 b' D% k+ J- B1 I需要用到一个python脚本来获取系统的联网状态以及各个io状态$ { ?9 Q! B' b5 V
- import psutil# ]$ b1 I) S% q1 I
- print(psutil.net_io_counters(pernic=True))
复制代码 输出结果是下面的
( |# _8 S& E5 s: M- {1 ^, n* s; B" K" _! ^
- 'bond0': snetio(bytes_sent = 0, bytes_recv = 0, packets_sent = 0, packets_recv = 0, errin = 0, errout = 0, dropin = 0, dropout = 0),3 h0 Z+ m% }. h/ d* e9 I; ~
- 'lo': snetio(bytes_sent = 371531983, bytes_recv = 371531983, packets_sent = 649842, packets_recv = 649842, errin = 0, errout = 0, dropin = 0, dropout = 0),
: F7 a( n+ a8 j3 p' k+ ? - 'tun0': snetio(bytes_sent = 300576, bytes_recv = 0, packets_sent = 9393, packets_recv = 0, errin = 0, errout = 0, dropin = 0, dropout = 0),2 ~6 P" q% h P2 B# k
- 'sit0': snetio(bytes_sent = 0, bytes_recv = 0, packets_sent = 0, packets_recv = 0, errin = 0, errout = 0, dropin = 0, dropout = 0),% J! y. J8 q* L
- 'ip_vti0': snetio(bytes_sent = 0, bytes_recv = 0, packets_sent = 0, packets_recv = 0, errin = 0, errout = 0, dropin = 0, dropout = 0),. B2 g* I3 h$ M1 ]& ^, o
- 'eth0': snetio(bytes_sent = 10911429402, bytes_recv = 387312110, packets_sent = 722569, packets_recv = 1194110, errin = 0, errout = 0, dropin = 5, dropout = 0)' [8 P5 Q% [- G& D# K+ e. `( n
- }
复制代码 有了数据就能够处理数据转化为网速了。. B( K3 [! {/ P! c# m
. E T$ Z- \. E( @
因为网速差别实在太大,所以我用了分级显示的方案:1 p* H* U: N5 e0 O! B3 t+ T- x
网速为B级别时显示红灯,网速越大,红灯越亮,不过放心,几乎看不到红灯
: z3 \% B% q4 r. z/ h网速为K级别时显示绿灯,网速越快,绿灯越绿。这个比较常见,几乎上硬盘待机时就一直是绿灯
9 H' R w7 j7 [- {" n7 W网速为M级别时显示蓝灯,网速越高,蓝灯越艳丽,当你下载东西或者往硬盘传文件时就是蓝灯了。
0 Z- g. e! K# E( v- net_led_dn() {
+ x8 ? A! p+ T2 O - python /root/netspeed.py | sed -e "s/'/\n/g" -e 's/, /=/g' | grep } | awk -F '=' '{print $4}' >/root/new.rtx1 L) T8 j4 j& Q( a/ R
- new_rtx=$(cat /root/new.rtx)# F, e( k+ G- E$ [# I
- old_rtx=$(cat /root/rtx.log)" ]$ J. d, L; B$ b! e
- rtx=$(expr $new_rtx - $old_rtx)
8 Q* S. k: h# b: Y) @# r/ n2 {" `" J; g - echo $rtx
, c c; u P+ @8 j! U+ E - if [ $rtx -lt 1024 ]; then
6 _ Y" \* ^8 { -
, V7 k% l, j: X# B/ A - rtx_led=$(expr $rtx / 4)' V2 y' @: c1 V0 d' u3 N4 W
-
" S# }' B: ?0 [4 q+ N8 m" @/ m3 i0 M - set_led c1 $rtx_led 0
. f4 m$ j2 t( k/ w2 [2 n - set_led c2 0 01 u9 ^8 I @: M- g1 v$ e. ]3 l
- set_led c3 0 0+ y6 J# @' m0 c" \
-
$ R6 |) W- ^3 F' _/ E: \! ] - elif [ $rtx -lt 1048576 ]; then# B0 \6 J. Y4 T6 P1 ?3 {* G
- rtx_led=$(expr $rtx / 4096)% m7 u5 n; d% g6 {
- set_led c1 0 0& D8 Y# y3 |7 k9 r
- set_led c2 $rtx_led 0
1 d5 K q2 E* u$ Z3 k5 n& i - set_led c3 0 0 V1 R1 a2 [/ Z- U) |( a0 F# |2 J
- elif [ $rtx -lt 1073741824 ]; then
5 F0 ^1 M* m( O! u - rtx_led=$(expr $rtx / 4194304)
; B- P, C6 h+ s! O - set_led c1 0 08 N8 J4 _" G4 \8 U
- set_led c2 0 0- W: y6 \! S5 U& {* s
- set_led c3 $rtx_led 0; Q% F- B) Q- a2 G9 y- e1 y3 t
- fi
1 @" {" F! s+ f - echo $new_rtx >/root/rtx.log( n% j0 ?$ ?2 x+ j7 b
- }
复制代码 这个只是显示下载网速的,如果想要显示上传网速也很简单,把第二行的$4改为$2就行了。" w$ S! A! o# F; |; y* T
下面是完整脚本,看附件吧。$ B7 G5 @8 M2 N+ o
一共有五个文件
5 n4 _; T# T2 t) F n- ledstatus.sh #放在/opt/bin文件夹下替换* M( e! G, ]& U1 b9 l4 v
- netspeed.py #放在root下
$ e# F0 r7 Y0 Y+ t - new.rt #放在root下
6 x" J& w- w" s5 L+ f7 h - mew.rtx #放在root下* e9 s7 m k, J7 L$ R1 B) d2 s* d
- rtx #放在root下
复制代码 9 ]6 f0 b# C' A, r$ b& Q0 ]% W- u
9 c* p g% a) K/ M- P2 O0 N
led_control.zip
(1015 Bytes, 下载次数: 114)
: B V; A% M7 D
解压密码(刮刮乐):chwhsen! \8 `$ U) B7 T
+ K7 i0 |1 Y# t" v# u+ I" D. u. \( V& |* S4 g6 S
# X2 W* k8 t4 @) E5 D |
评分
-
查看全部评分
|