Skrypt do monitorowania systemu. |
Autor |
Wiadomość |
Maciek_Rutecki
Administrator
JID: bc547@jabber.gda.pl
Pomógł: 39 razy Dołączył: 07 Cze 2005 Posty: 2959
|
Wysłany: 2006-12-30, 16:58 Skrypt do monitorowania systemu.
|
|
|
Skrypt do szybkiego podglądu obciążenia systemu. Pierwotnie miał być tylko do wyświetlania statusu baterii, ale szybko się rozrósł.
Krytyka mile widziana, ale poprawki po Nowym Roku ;-)
Kod: | #!/bin/sh
#skrypt informacyjny
#Autor: Maciej Rutecki <maciekATunixy.pl>
#licencja GPL/CC/BSD (do wyboru)
#wersja 20061230
#start
stan=
#nazwa
host=`uname -n`
system=`uname -o`
wersja=`uname -r`
stan=$stan" "$host" "$system" "$wersja"\n"
#uptime
czas_uptime=/proc/uptime
total_seconds=`cat $czas_uptime | sed -n 1p| cut -d '.' -f 1`
let seconds=$total_seconds%60
let minutes=($total_seconds-$seconds)%3600/60
let temp=$minutes*60
let hours=($total_seconds-$seconds-$temp)%86400/3600
let temp_2=$hours*3600
let days=($total_seconds-$seconds-$temp-$temp_2)/86400
uptime=" "$days"d"$hours"h"$minutes"m"$seconds"s"
stan=$stan" Uptime :"$uptime"\n"
##################################
#pomiar obciazenie CPU oraz chwilowy transfer w sieci
##################################
#CPU
statystyki=/proc/stat
last_user_czest_hz=`cat $statystyki | sed -n 1p| awk '{print $2}'`
last_nice_czest_hz=`cat $statystyki | sed -n 1p| awk '{print $3}'`
last_sys_czest_hz=`cat $statystyki | sed -n 1p| awk '{print $4}'`
last_idle_czest_hz=`cat $statystyki | sed -n 1p| awk '{print $5}'`
#Ethernet
INTERFEJS=eth0
last_Rx_ethernet=`/sbin/ifconfig $INTERFEJS | grep bytes | cut -d ':' -f 2 | cut -d ' ' -f 1`
last_Tx_ethernet=`/sbin/ifconfig $INTERFEJS | grep bytes | awk '{print $6}' | cut -d ':' -f 2 | cut -d ' ' -f 1`
#wifi
INTERFEJS=eth2
last_Rx_wifi=`/sbin/ifconfig $INTERFEJS | grep bytes | cut -d ':' -f 2 | cut -d ' ' -f 1`
last_Tx_wifi=`/sbin/ifconfig $INTERFEJS | grep bytes | awk '{print $6}' | cut -d ':' -f 2 | cut -d ' ' -f 1`
#czekamy 1 sekunde
sleep 1
#i patrzymy znowu, ale od ethernetu zaczynajac, a na CPU konczac
#Ethernet
INTERFEJS=eth0
new_Rx_ethernet=`/sbin/ifconfig $INTERFEJS | grep bytes | cut -d ':' -f 2 | cut -d ' ' -f 1`
new_Tx_ethernet=`/sbin/ifconfig $INTERFEJS | grep bytes | awk '{print $6}' | cut -d ':' -f 2 | cut -d ' ' -f 1`
#wifi
INTERFEJS=eth2
new_Rx_wifi=`/sbin/ifconfig $INTERFEJS | grep bytes | cut -d ':' -f 2 | cut -d ' ' -f 1`
new_Tx_wifi=`/sbin/ifconfig $INTERFEJS | grep bytes | awk '{print $6}' | cut -d ':' -f 2 | cut -d ' ' -f 1`
#CPU
user_czest_hz=`cat $statystyki | sed -n 1p| awk '{print $2}'`
nice_czest_hz=`cat $statystyki | sed -n 1p| awk '{print $3}'`
sys_czest_hz=`cat $statystyki | sed -n 1p| awk '{print $4}'`
idle_czest_hz=`cat $statystyki | sed -n 1p| awk '{print $5}'`
##########################
#a teraz juz obrobka danych i prezentacja
#interfejs ethernet
interfejs=eth0
#IP
MOJE_IP="`/sbin/ifconfig $interfejs | grep inet | cut -d ':' -f 2 | cut -d ' ' -f 1`"
#obecny transfer
let Rx_ethernet=($new_Rx_ethernet-$last_Rx_ethernet)/1024
let Tx_ethernet=($new_Tx_ethernet-$last_Tx_ethernet)/1024
#calkowita ilosc przeslanych danych
RX1=`/sbin/ifconfig $interfejs | grep bytes | awk '{print $3}'`
RX2=`/sbin/ifconfig $interfejs | grep bytes | awk '{print $4}'`
RX="RX: "$RX1" "$RX2
TX1=`/sbin/ifconfig $interfejs | grep bytes | awk '{print $7}'`
TX2=`/sbin/ifconfig $interfejs | grep bytes | awk '{print $8}'`
TX="TX: "$TX1" "$TX2
#prezentacja
stan=$stan" Interfejs "$interfejs" : "$MOJE_IP"\n"
stan=$stan" Transfer: Rx: "$Rx_ethernet"kB/s Tx: "$Tx_ethernet"kB/s\n"
stan=$stan" Calkowity: "$RX", "$TX"\n"
#interfejs wifi
interfejs=eth2
#IP
MOJE_IP="`/sbin/ifconfig $interfejs | grep inet | cut -d ':' -f 2 | cut -d ' ' -f 1`"
#obecny transfer
let Rx_wifi=($new_Rx_wifi-$last_Rx_wifi)/1024
let Tx_wifi=($new_Tx_wifi-$last_Tx_wifi)/1024
#calkowita ilosc przeslanych danych
RX1=`/sbin/ifconfig $interfejs | grep bytes | awk '{print $3}'`
RX2=`/sbin/ifconfig $interfejs | grep bytes | awk '{print $4}'`
RX="RX: "$RX1" "$RX2
TX1=`/sbin/ifconfig $interfejs | grep bytes | awk '{print $7}'`
TX2=`/sbin/ifconfig $interfejs | grep bytes | awk '{print $8}'`
TX="TX: "$TX1" "$TX2
#prezentacja
stan=$stan" Interfejs "$interfejs" : "$MOJE_IP"\n"
stan=$stan" Transfer: Rx: "$Rx_wifi"kB/s Tx: "$Tx_wifi"kB/s\n"
stan=$stan" Calkowity: "$RX", "$TX"\n"
#CPU
#chwilowe obciazenie procesora(-ow)
let user=$user_czest_hz-$last_user_czest_hz
let nice=$nice_czest_hz-$last_nice_czest_hz
let sys=$sys_czest_hz-$last_sys_czest_hz
let idle=$idle_czest_hz-$last_idle_czest_hz
let total=user+nice+sys+idle+1
let user_procent=$user*100/$total
let nice_procent=$nice*100/$total
let sys_procent=$sys*100/$total
let idle_procent=1+$idle*100/$total
#czestotliwosc procesora(-ow)
takt00=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq`
let takt0=$takt00/1000
takt11=`cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq`
let takt1=$takt11/1000
#zarzadca cpufreq
governor0=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`
governor1=`cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor`
#prezentacja
stan=$stan" CPU: ""User: "$user_procent"% Nice: "$nice_procent"% Sys: "$sys_procent"% Idle: "$idle_procent"%\n"
stan=$stan" CPU0: "$governor0", "$takt0" MHz\n"
stan=$stan" CPU1: "$governor1", "$takt1" MHz\n"
#pamiec RAM
total=`cat /proc/meminfo | sed -n 1p | awk '{print $2}'`;
let total_mem=$total/1024
#active=`cat /proc/meminfo | sed -n 6p | awk '{print $2}'`
#cached=`cat /proc/meminfo | sed -n 5p | awk '{print $2}'`
#buffers=`cat /proc/meminfo | sed -n 3p | awk '{print $2}'`
mem_free=`cat /proc/meminfo | sed -n 2p | awk '{print $2}'`
let used_mem=($total-$mem_free)/1024
#pamiec swap
swap_free=`cat /proc/meminfo | sed -n 13p | awk '{print $2}'`
swap_total=`cat /proc/meminfo | sed -n 12p | awk '{print $2}'`
let used_swap=($swap_total-$swap_free)/1024
let swap_total=$swap_total/1024
#prezentacja
stan=$stan" Pamiec : zajeta/calosc\n"
stan=$stan" RAM : "$used_mem" MB/"$total_mem" MB\n"
stan=$stan" SWAP : "$used_swap" MB/"$swap_total" MB\n"
#ACPI
acpi=`acpitool`
stan=$stan$acpi
Xdialog --left --title "Informacja" --msgbox "$stan" 25 57 & |
Plik do pobrania także tutaj:
http://maciek.unixy.pl/download/skrypty/battery.sh
battery2.png
|
 |
Plik ściągnięto 869 raz(y) 662,16 KB |
|
_________________ Maciek
http://www.maciek.unixy.pl |
|
|
|
 |
Lorenzo
Pomógł: 5 razy Dołączył: 31 Paź 2005 Posty: 141
|
Wysłany: 2006-12-30, 17:45
|
|
|
Ładne to.
Proponowałbym przy uzyciu ram'u oddzielić pamiec zuzyta przez programy od pamięci użytej a bufory (np. kombinacja free i bc). Jeszcze kod skryptu troche rozjaśnić (wcięcia porobić, i takie tam. I oczywiście komentarze pa inglisz ).
I jeszcze zamiast "thermal zone <liczba>" wrzucić coś bardziej strawnego (bo ja np. nie wiem co to )
//EDIT:
I zmienne dużymi literami |
|
|
|
 |
Maciek_Rutecki
Administrator
JID: bc547@jabber.gda.pl
Pomógł: 39 razy Dołączył: 07 Cze 2005 Posty: 2959
|
Wysłany: 2006-12-30, 18:44
|
|
|
Lorenzo napisał/a: | Ładne to.
Proponowałbym przy uzyciu ram'u oddzielić pamiec zuzyta przez programy od pamięci użytej a bufory (np. kombinacja free i bc). Jeszcze kod skryptu troche rozjaśnić (wcięcia porobić, i takie tam. I oczywiście komentarze pa inglisz ).
I jeszcze zamiast "thermal zone <liczba>" wrzucić coś bardziej strawnego (bo ja np. nie wiem co to )
//EDIT:
I zmienne dużymi literami |
Co do ramu, robiłem to, ale tak do końca nie wiadomo jak to liczyć, wolałem zostać przy dotychczasowej formie. Wcięcia, hmm, trudno powiedzieć, gdzie je dodać, żadnych pętli, funkcji itp.. Co do komentarzy po angielsku, dorobię w kolejnej wersji. W przypadku thermal zone jest ten problem, że co laptop to co innego, różna ilość TZ, o błędach w DSDT nie wspomnę Z resztą podobnie jest z monitorowaniem zasilania, chyba byłoby prościej napisać już normalny program w C.
Nie mam zwyczaju używać dużych liter w zmiennych, dłużej się pisze |
_________________ Maciek
http://www.maciek.unixy.pl |
|
|
|
 |
Lorenzo
Pomógł: 5 razy Dołączył: 31 Paź 2005 Posty: 141
|
Wysłany: 2006-12-30, 18:50
|
|
|
No tak, jak zwykle nie mysle.
Przeca jak miałem 686 (które sie sprzedało by spłacić długi za wódke), to monitory od temperatury, zasilania i wiatraków wciskały farmazony. A po przenosinach na innego szpeja kłamstwa były jeszcze wieksze
Więc trzeba by mu dawać rozeznanie - jaki szpej -> implikuje który parametr co oznacza. Dużo zabawy
//EDIT:
A wciecia mozna robić całego bloku pod komentarzem do niego - a'la takie cóś lub takie szpejstwo
Przejrzystość skryptu wiele wnosi dla kogoś kto go nie pisał a potrzebuje użyc |
|
|
|
 |
Maciek_Rutecki
Administrator
JID: bc547@jabber.gda.pl
Pomógł: 39 razy Dołączył: 07 Cze 2005 Posty: 2959
|
Wysłany: 2006-12-30, 19:42
|
|
|
Lorenzo napisał/a: | A wciecia mozna robić całego bloku pod komentarzem do niego |
Dorobię w przyszłym roku, jak jeszcze jakieś uwagi się zbiorą |
_________________ Maciek
http://www.maciek.unixy.pl |
|
|
|
 |
Maciek_Rutecki
Administrator
JID: bc547@jabber.gda.pl
Pomógł: 39 razy Dołączył: 07 Cze 2005 Posty: 2959
|
Wysłany: 2006-12-31, 11:49
|
|
|
Pod adresem:
http://maciek.unixy.pl/download/skrypty/battery.sh
Znajduje się poprawiona wersja, zmiany:
- anglojęzyczne komentarze i nazwy zmiennych ;-)
- wcięcia (powinno być czytelniej)
- wyświetlanie pamięci zajętej przez aplikacje, cache, bufory i wolna
- kosmetyka
Pomiar temperatury pozostał niezmieniony, co sprzęt, to wynalazek, u mnie thermal zone 5 pokazuje.. obroty wentylatora... wyrażone w procentach |
_________________ Maciek
http://www.maciek.unixy.pl |
|
|
|
 |
kriks
Administrator
JID: kszymczak@jabber.gda.pl
Pomógł: 15 razy Dołączył: 07 Cze 2005 Posty: 609
|
Wysłany: 2006-12-31, 14:11
|
|
|
Działa fajnie nawet na zwykłej maszynie. Dla bajeru mógł by sprawdzać na początku czy w systemie są potrzebne programy typu Xdialog, acpitool...
na początku skryptu:
Kod: | # nazwa programu
W=("Xdialog" "acpitool")
# sprawdz czy zainstalowany
T[0]=`ls /usr/bin/ | grep Xdialog`
T[1]=`ls /usr/bin | grep acpitool`
COUNTER=0
STATUS=0
while [ $COUNTER -lt ${#W[@]} ]; do
if [ "${T[$COUNTER]}" != "${W[$COUNTER]}" ]; then
echo "Do poprawnego dzialania skryptu brakuje ${W[$COUNTER]}"
let STATUS=STATUS+1
fi
let COUNTER=COUNTER+1
done
if [ "$STATUS" != 0 ]; then
exit
fi
|
|
_________________ jesteś nowy, przeczytaj to.. |
|
|
|
 |
marcinus
JID: zygfrydos(na)gmail(kropka)com
Pomógł: 2 razy Dołączył: 12 Cze 2005 Posty: 118
|
|
|
|
 |
Lorenzo
Pomógł: 5 razy Dołączył: 31 Paź 2005 Posty: 141
|
Wysłany: 2007-01-11, 00:04
|
|
|
Znalazłem małego bug'a
Stan swap'a chyba lepiej by było wyłuśkać z /proc/meminfo poprzez
Kod: | swap_free=`cat /proc/meminfo | grep -i swapfree | awk '{print $2}'`
swap_total=`cat /proc/meminfo | grep -i swaptotal | awk '{print $2}'` |
Gdyż u mnie skrypt w obecnej formie podaje jako swap te linie:
Cytat: | dominik@m31-3:~$ cat /proc/meminfo | sed -n 13p
Mapped: 53664 kB
dominik@m31-3:~$ cat /proc/meminfo | sed -n 12p
AnonPages: 128684 kB
|
|
|
|
|
 |
Maciek_Rutecki
Administrator
JID: bc547@jabber.gda.pl
Pomógł: 39 razy Dołączył: 07 Cze 2005 Posty: 2959
|
Wysłany: 2007-01-11, 09:36
|
|
|
Ale jazda:
Kod: | maciek@rutek:~$ cat /proc/meminfo | sed -n 13p
SwapFree: 2980008 kB
maciek@rutek:~$ cat /proc/meminfo | sed -n 12p
SwapTotal: 2980008 kB |
Poprawione:
http://maciek.unixy.pl/download/skrypty/battery.sh
Taka prośba, jak ktoś używa sensors, to niech mi poda przykładowy wynik tego polecenia, trzeba dopisać jakiś przykład dla tych, którzy nie używają ACPI. |
_________________ Maciek
http://www.maciek.unixy.pl |
|
|
|
 |
zielony_83
JID: zielony@jabber.autocom.pl
Dołączył: 03 Cze 2006 Posty: 31
|
Wysłany: 2007-01-15, 11:59
|
|
|
Proszę bardzo wynik sensors
Kod: | ~@g-point $: sensors
w83627hf-isa-0290
Adapter: ISA adapter
VCore 1: +1.71 V (min = +1.66 V, max = +1.84 V)
VCore 2: +1.23 V (min = +1.66 V, max = +1.84 V) ALARM
+3.3V: +3.09 V (min = +3.14 V, max = +3.47 V) ALARM
+5V: +4.73 V (min = +4.76 V, max = +5.24 V) ALARM
+12V: +12.28 V (min = +10.82 V, max = +13.19 V)
-12V: -12.28 V (min = -13.18 V, max = -10.80 V)
-5V: -5.20 V (min = -5.25 V, max = -4.75 V)
V5SB: +5.51 V (min = +4.76 V, max = +5.24 V) ALARM
VBat: +3.31 V (min = +2.40 V, max = +3.60 V)
fan1: 0 RPM (min = 4560 RPM, div = 2) ALARM
fan2: 0 RPM (min = 14062 RPM, div = 2) ALARM
fan3: 5532 RPM (min = 3552 RPM, div = 2)
temp1: +38°C (high = +42°C, hyst = +36°C) sensor = thermistor ALARM
temp2: +49.0°C (high = +80°C, hyst = +75°C) sensor = thermistor
temp3: -48.0°C (high = +80°C, hyst = +75°C) sensor = thermistor
vid: +1.750 V (VRM Version 9.0)
alarms:
beep_enable:
Sound alarm enabled
|
Z tym mogą być problemy bo na przykład u mnie temp na procku to temp2. U każdego może być inaczej |
_________________ Zostałeś zarejestrowany jako użytkownik #416423 przez..
##
FluxboxPL | Mój Lepszy Świat | Debian Users Gang |
|
|
|
 |
Maciek_Rutecki
Administrator
JID: bc547@jabber.gda.pl
Pomógł: 39 razy Dołączył: 07 Cze 2005 Posty: 2959
|
Wysłany: 2007-01-15, 21:35
|
|
|
Dzięki
Generalnie:
temperatura="CPU:
temp=`sensors | sed -n Xp | awk '{print $Y}'`
temperatura=$temperatura$temp
Dla tego przypadku
X=16
Y=2
Dla mostka:
X=15
Y=2
Dla nie znających basha:
X - numer wiersza
Y - numer kolejnej kolumny (tekstu).
To powinno ułatwić tworzenie własnych wersji skryptu. |
_________________ Maciek
http://www.maciek.unixy.pl |
|
|
|
 |
zielony_83
JID: zielony@jabber.autocom.pl
Dołączył: 03 Cze 2006 Posty: 31
|
|
|
|
 |
Maciek_Rutecki
Administrator
JID: bc547@jabber.gda.pl
Pomógł: 39 razy Dołączył: 07 Cze 2005 Posty: 2959
|
Wysłany: 2007-02-25, 11:58
|
|
|
Zmieniłem nieco kolejność odczytywania informacji. Było:
Kod: | ##################################
#temporary CPU and network load
##################################
#CPU
...
#Ethernet
...
#wifi
...
#wait 1 second
sleep 1
#read new values from network interfaces and CPU
#Ethernet
...
#wifi
...
#CPU
...
########################## |
Jest:
Kod: |
##################################
#temporary CPU and network load
##################################
#CPU
...
#Ethernet
...
#wifi
...
#wait 1 second
sleep 1
#read new values from network interfaces and CPU
#CPU
...
#Ethernet
...
#wifi
...
########################## |
Plik do pobrania:
http://maciek.unixy.pl/download/skrypty/battery.sh |
_________________ Maciek
http://www.maciek.unixy.pl |
|
|
|
 |
Maciek_Rutecki
Administrator
JID: bc547@jabber.gda.pl
Pomógł: 39 razy Dołączył: 07 Cze 2005 Posty: 2959
|
Wysłany: 2009-09-27, 12:54
|
|
|
Czas na jakąś aktualizację, przepisałem skrypt praktycznie od zera, być może będzie dzięki temu bardziej uniwersalny:
Kod: | # !/bin/bash
# skrypt informacyjny
# Autor: Maciej Rutecki <maciekATunixy.pl>
# GPL/CC/BSD (do wyboru)
# ver. 20090927
# add support for 2.6.32 (cpufreq sysfs)
# OPTIONS
# enter ethernet interface eg. eth0, leave empty to disable
EthernetInterface=eth0
# enter wireless inteface eg. wlan0, leave empty to disable
WirelessInterface=wlan0
# temperature from acpi sensors - CPU temp eg. TZ1
thermalZoneCPU=TZ1
# fan speed from acpi sensors - CPU eg. TZ2
thermalZoneCPUFAN=TZ4
# disk eg. /dev/sda
hddDisk=/dev/sda
# temperature from lm-sensors - CPU eg. temp1
lmSensorsTempCPU=temp3
# fan speed lm-sensors - CPU eg. fan1
lmSensorsFanCPU=fan1
# fan speed lm-sensors - CASE eg. fan2
lmSensorsFanCASE=fan2
# show hostname/kernel version? yes/no
showHostname=yes
# show uptime? yes/no
showUptime=yes
# show CPU load? yes/no
showCPULoad=yes
# check cpu frequrency scalling? yes/no
cpufreq=yes
# check RAM usage yes/no
usageRAM=yes
# check SWAP usage yes/no
usageSWAP=yes
# check ACPI power state? yes/no
powerACPI=yes
# show temperature from acpi? yes/no
showThermalZoneCPU=yes
# show fan speed from acpi? yes/no (depends: "showThermalZoneCPU=yes")
showThermalZoneCPUFan=yes
# show disk temperature? yes/no
showDiskTemperature=yes
# show CPU temperature from lm-sensors? yes/no
showLMSensorsCPU=no
# show CPU fan speed from lm-sensors? yes/no (depends: "showLMSensorsCPU=yes")
showLMSensorsFanCPU=no
# show CASE fan speed from lm-sensors? yes/no
showLMSensorsFanCASE=no
# FILES
# uptime
time_uptime=/proc/uptime
# cpu statistics
statistic=/proc/stat
# thermal zone
thermalZoneDir=/proc/acpi/thermal_zone
# DIRECORY
# cpufreq
cpuFreqPath=/sys/devices/system/cpu
# BINARY
# ifconfig
IFconfig=/sbin/ifconfig
# iwconfig
IWconfig=/sbin/iwconfig
# acpitool
ACPItool=acpitool
# hddtemp
hddTempApplication="sudo /usr/sbin/hddtemp"
# lm-sensors
lmSensors=sensors
#start
stan=
#hostname, kernel version
if [ "$showHostname" == "yes" ] ; then
host=`uname -n`
system=`uname -o`
version=`uname -r`
stan=$stan" "$host" "$system" "$version"\n"
fi
#uptime
if [ "$showUptime" == "yes" ] ; then
total_seconds=`cat $time_uptime | sed -n 1p| cut -d '.' -f 1`
let seconds=$total_seconds%60
let minutes=($total_seconds-$seconds)%3600/60
let temp=$minutes*60
let hours=($total_seconds-$seconds-$temp)%86400/3600
let temp_2=$hours*3600
let days=($total_seconds-$seconds-$temp-$temp_2)/86400
uptime=" "$days"d"$hours"h"$minutes"m"$seconds"s"
stan=$stan" Uptime: "$uptime"\n"
fi
##################################
#temporary CPU and network load
##################################
#CPU
if [ "$showCPULoad" == "yes" ] ; then
last_user_czest_hz=`cat $statistic | sed -n 1p| awk '{print $2}'`
last_nice_czest_hz=`cat $statistic | sed -n 1p| awk '{print $3}'`
last_sys_czest_hz=`cat $statistic | sed -n 1p| awk '{print $4}'`
last_idle_czest_hz=`cat $statistic | sed -n 1p| awk '{print $5}'`
fi
#Ethernet
if [ "$EthernetInterface" != "" ] ; then
last_Rx_ethernet=`$IFconfig $EthernetInterface | grep bytes | cut -d ':' -f 2 | cut -d ' ' -f 1`
last_Tx_ethernet=`$IFconfig $EthernetInterface | grep bytes | awk '{print $6}' | cut -d ':' -f 2 | cut -d ' ' -f 1`
fi
#wifi
if [ "$WirelessInterface" != "" ] ; then
last_Rx_wifi=`$IFconfig $WirelessInterface | grep bytes | cut -d ':' -f 2 | cut -d ' ' -f 1`
last_Tx_wifi=`$IFconfig $WirelessInterface | grep bytes | awk '{print $6}' | cut -d ':' -f 2 | cut -d ' ' -f 1`
fi
#wait 1 second
sleep 1
#read new values from network interfaces and CPU
#CPU
if [ "$showCPULoad" == "yes" ] ; then
user_czest_hz=`cat $statistic | sed -n 1p| awk '{print $2}'`
nice_czest_hz=`cat $statistic | sed -n 1p| awk '{print $3}'`
sys_czest_hz=`cat $statistic | sed -n 1p| awk '{print $4}'`
idle_czest_hz=`cat $statistic | sed -n 1p| awk '{print $5}'`
fi
#Ethernet
if [ "$EthernetInterface" != "" ] ; then
new_Rx_ethernet=`$IFconfig $EthernetInterface | grep bytes | cut -d ':' -f 2 | cut -d ' ' -f 1`
new_Tx_ethernet=`$IFconfig $EthernetInterface | grep bytes | awk '{print $6}' | cut -d ':' -f 2 | cut -d ' ' -f 1`
fi
#wifi
if [ "$WirelessInterface" != "" ] ; then
new_Rx_wifi=`$IFconfig $WirelessInterface | grep bytes | cut -d ':' -f 2 | cut -d ' ' -f 1`
new_Tx_wifi=`$IFconfig $WirelessInterface | grep bytes | awk '{print $6}' | cut -d ':' -f 2 | cut -d ' ' -f 1`
fi
##########################
#prepare and present data
#ethernet
if [ "$EthernetInterface" != "" ] ; then
#check IP
my_IP=`$IFconfig $EthernetInterface | grep inet | cut -d ':' -f 2 | cut -d ' ' -f 1`
if [ "$my_IP" == "" ] ; then
my_IP="N/A"
fi
#current transfer, last 1 second
let Rx_ethernet=($new_Rx_ethernet-$last_Rx_ethernet)/1024
let Tx_ethernet=($new_Tx_ethernet-$last_Tx_ethernet)/1024
#total receive and send data
RX1=`$IFconfig $EthernetInterface | grep bytes | awk '{print $3}'`
RX2=`$IFconfig $EthernetInterface | grep bytes | awk '{print $4}'`
RX="RX: "$RX1" "$RX2
TX1=`$IFconfig $EthernetInterface | grep bytes | awk '{print $7}'`
TX2=`$IFconfig $EthernetInterface | grep bytes | awk '{print $8}'`
TX="TX: "$TX1" "$TX2
#show data
stan=$stan" Ethernet "$EthernetInterface": IP - "$my_IP"\n"
stan=$stan" Transfer: Rx: "$Rx_ethernet" kB/s, Tx: "$Tx_ethernet" kB/s\n"
stan=$stan" Total: "$RX", "$TX"\n"
fi
#WiFi
if [ "$WirelessInterface" != "" ] ; then
# check ESSID
my_ESSID=`$IWconfig $WirelessInterface | grep ESSID | cut -d ':' -f 2`
if [ "$my_ESSID" == "" ] ; then
my_ESSID="N/A"
fi
# check IP
my_IP=`$IFconfig $WirelessInterface | grep inet | cut -d ':' -f 2 | cut -d ' ' -f 1`
if [ "$my_IP" == "" ] ; then
my_IP="N/A"
fi
#current transfer, last 1 second
let Rx_wifi=($new_Rx_wifi-$last_Rx_wifi)/1024
let Tx_wifi=($new_Tx_wifi-$last_Tx_wifi)/1024
#total receive and send data
RX1=`$IFconfig $WirelessInterface | grep bytes | awk '{print $3}'`
RX2=`$IFconfig $WirelessInterface | grep bytes | awk '{print $4}'`
RX="RX: "$RX1" "$RX2
TX1=`$IFconfig $WirelessInterface | grep bytes | awk '{print $7}'`
TX2=`$IFconfig $WirelessInterface | grep bytes | awk '{print $8}'`
TX="TX: "$TX1" "$TX2
#show data
stan=$stan" WiFi "$WirelessInterface": IP - "$my_IP", ESSID - "$my_ESSID"\n"
stan=$stan" Transfer: Rx: "$Rx_wifi" kB/s, Tx: "$Tx_wifi" kB/s\n"
stan=$stan" Total: "$RX", "$TX"\n"
fi
#CPU
#temporary load CPU(s) - last 1 second
if [ "$showCPULoad" == "yes" ] ; then
let user=$user_czest_hz-$last_user_czest_hz
let nice=$nice_czest_hz-$last_nice_czest_hz
let sys=$sys_czest_hz-$last_sys_czest_hz
let idle=$idle_czest_hz-$last_idle_czest_hz
let total=user+nice+sys+idle+1
let user_procent=$user*100/$total
let nice_procent=$nice*100/$total
let sys_procent=$sys*100/$total
let idle_procent=1+$idle*100/$total
# show data
stan=$stan" CPU: ""User: "$user_procent"% Nice: "$nice_procent"% Sys: "$sys_procent"% Idle: "$idle_procent"%\n"
fi
#CPU FREQUENCY
if [ "$cpufreq" == "yes" ] ; then
cd $cpuFreqPath
i=0
for cpu in cpu*; do
# check if we in "cpu?" directory
temp1=`echo $cpu | cut -c1-4`
temp2="cpu"$i
if [ "$temp1" == "$temp2" ]; then
# frequency
taktk=`cat $cpuFreqPath"/"$cpu"/cpufreq/scaling_cur_freq"`
let takt=$taktk/1000
#governor
governor=`cat $cpuFreqPath"/"$cpu"/cpufreq/scaling_governor"`
stan=$stan" CPU"$i": "$governor", "$takt" MHz \n"
let i++
fi
done
fi
#RAM
if [ "$usageRAM" == "yes" ] ; then
#total memory, "free" memory, buffers, cached
total_memory=`cat /proc/meminfo | sed -n 1p | awk '{print $2}'`
free_memory=`cat /proc/meminfo | sed -n 2p | awk '{print $2}'`
buffers_memory=`cat /proc/meminfo | sed -n 3p | awk '{print $2}'`
cached_memory=`cat /proc/meminfo | sed -n 4p | awk '{print $2}'`
#memory all, applications, buffers, cached, free
let all_mem=$total_memory/1024
let applications_mem=($total_memory-$free_memory-$buffers_memory-$cached_memory)/1024
let buffers_mem=$buffers_memory/1024
let cached_mem=$cached_memory/1024
let free_mem=$free_memory/1024
#show data
stan=$stan" RAM: Total: "$all_mem" MB, Applications: "$applications_mem" MB\n"
stan=$stan" Buffers: "$buffers_mem" MB, Cached: "$cached_mem" MB, Free: "$free_mem" MB\n"
fi
#SWAP
if [ "$usageSWAP" == "yes" ] ; then
#free and total memory
swap_free=`cat /proc/meminfo | grep -i swapfree | awk '{print $2}'`
swap_total=`cat /proc/meminfo | grep -i swaptotal | awk '{print $2}'`
#used and total memory
let used_swap=($swap_total-$swap_free)/1024
let swap_total=$swap_total/1024
#show data
stan=$stan" SWAP: Total: "$swap_total" MB, Used: "$used_swap" MB\n"
fi
#ACPI - power sources
if [ "$powerACPI" == "yes" ] ; then
# AC
acpi=`$ACPItool -a`
if [ "$acpi" != "" ] ; then
stan=$stan$acpi"\n"
fi
# Battery
acpi=`$ACPItool -b`
if [ "$acpi" != "" ] ; then
stan=$stan$acpi"\n"
fi
fi
#temperature from ACPI
if [ "$showThermalZoneCPU" == "yes" ] ; then
temp=" CPU: "
thermalZoneFile=$thermalZoneDir"/"$thermalZoneCPU"/temperature"
temp=$temp`cat $thermalZoneDir"/"$thermalZoneCPU"/temperature" | awk '{print $2}'`" C"
stan=$stan$temp
if [ "$showThermalZoneCPUFan" == "yes" ] ; then
temp=`cat $thermalZoneDir"/"$thermalZoneCPUFAN"/temperature" | awk '{print $2}'`
stan=$stan" FAN: "$temp" % (RPM)\n"
else
stan=$stan"\n"
fi
fi
#temperature and fan from lm-sensors
if [ "$showLMSensorsCPU" == "yes" ] ; then
sensors_temp=`$lmSensors | grep $lmSensorsTempCPU | awk '{print $2}'`
stan=$stan" CPU: "$sensors_temp
if [ "$showLMSensorsFanCPU" == "yes" ] ; then
sensors_temp=`$lmSensors | grep $lmSensorsFanCPU | awk '{print $2}'`
stan=$stan" FAN: "$sensors_temp" RPM\n"
else
stan=$stan"\n"
fi
fi
if [ "$showLMSensorsFanCASE" == "yes" ] ; then
sensors_temp=`$lmSensors | grep $lmSensorsFanCASE | awk '{print $2}'`
stan=$stan" CASE: "$sensors_temp" RPM\n"
fi
#DISK
if [ "$showDiskTemperature" == "yes" ] ; then
disk_temp=`$hddTempApplication $hddDisk`
stan=$stan" Dysk "$disk_temp"\n"
fi
# Xdialog --left --title "Informacja" --msgbox "$stan" 35 57 &
echo -e "$stan"
kdialog --caption "system" --msgbox "$stan" & |
Download:
http://maciek.unixy.pl/do...y/battery.sh.gz |
_________________ Maciek
http://www.maciek.unixy.pl |
|
|
|
 |
|