Adopt netstatus and sensors-monitor scripts

This commit is contained in:
Adam Goldsmith 2018-01-19 16:45:10 -05:00
parent 8fb0346166
commit 97cdbe029b
4 changed files with 65 additions and 2 deletions

View File

@ -1,4 +1,4 @@
Command=/home/adam/.bin/netstatus.sh Command=/home/adam/.config/xfce4/panel/scripts/netstatus.sh
UseLabel=0 UseLabel=0
Text=(genmon) Text=(genmon)
UpdatePeriod=2000 UpdatePeriod=2000

View File

@ -1,4 +1,4 @@
Command=/home/adam/.bin/sensors-monitor.py Command=/home/adam/.config/xfce4/panel/scripts/sensors-monitor.py
UseLabel=0 UseLabel=0
Text=(genmon) Text=(genmon)
UpdatePeriod=5000 UpdatePeriod=5000

View File

@ -0,0 +1,22 @@
#!/bin/bash
function doPing () {
# $1 = target
# $2 = letter
ping -c1 -W1 "$1" | \
(grep "bytes from" || echo "<span fgcolor=\"red\">$2:Down</span>") | \
sed 's/.*time=\([0-9\.]*\).*/'"$2"':\1ms/'
}
if [[ "$@" -ne "" ]]
then
interfaces=$(ip -4 -o a | grep "$@")
else
interfaces=$(ip -4 -o a)
fi
ip=$(echo "$interfaces" | \
sed 's/^[0-9]*: \([^ ]*\) inet \([0-9.]*\).*/\1:\2/g' | \
grep -v lo | \
tr '\n' ' ')
echo -n "<txt>${ip}$(doPing 8.8.8.8 G)</txt>"

View File

@ -0,0 +1,41 @@
#!/usr/bin/python2
import sensors
import subprocess
from glob import glob
import re
sensorsToShow = {'Physical id 0': ["C", 70,100],
'temp1' : ["C", 70,100],
'Left side ' : ["RPM", 3000,5000]}
cpuGovernors = { "powersave" : '<span fgcolor="green">s</span>',
"performance": '<span fgcolor="red">p</span>',
"ondemand": '<span fgcolor="yellow">o</span>'}
out = ""
cpuGovernor = ""
sensors.init()
try:
for chip in sensors.iter_detected_chips():
for feature in chip:
if feature.label in sensorsToShow:
color = ("#00B000" if feature.get_value() < sensorsToShow[feature.label][1]
else ("yellow" if feature.get_value() < sensorsToShow[feature.label][2]
else "red"))
out += '<span fgcolor="%s">%.f%s</span> ' % (color, feature.get_value(), sensorsToShow[feature.label][0])
CPUFreq = 0
for line in open("/proc/cpuinfo"):
if "cpu MHz" in line:
speed = float(line.replace("cpu MHz : ", "").replace("\n", ""))
CPUFreq = max(speed, CPUFreq)
#print CPUFreq
out += '<span>%.2fGHz</span>' % (CPUFreq/1000)
out += " "
for i in glob("/sys/devices/system/cpu/cpu[0-9]/cpufreq/scaling_governor"):
out += cpuGovernors[open(i).read().replace("\n", "")]
print "<txt>" + out + "</txt>"
finally:
sensors.cleanup()