mirror of
https://github.com/Tafkas/fritzbox-munin.git
synced 2023-10-10 13:36:55 +02:00
code optimization
This commit is contained in:
parent
9e8e067531
commit
2bd15e836d
@ -22,7 +22,7 @@ import sys
|
||||
import fritzbox_helper as fh
|
||||
|
||||
PAGE = '/system/ecostat.lua'
|
||||
pattern = re.compile('.*\/(StatTemperature)".*=.*"(.*?)"')
|
||||
pattern = re.compile(".*/(StatTemperature)\".*=.*\"(.*?)\"")
|
||||
|
||||
|
||||
def get_cpu_temperature():
|
||||
@ -36,7 +36,7 @@ def get_cpu_temperature():
|
||||
|
||||
m = re.search(pattern, data)
|
||||
if m:
|
||||
print 'temp.value %d' %(int(m.group(2).split(',')[0]))
|
||||
print 'temp.value %d' % (int(m.group(2).split(',')[0]))
|
||||
|
||||
|
||||
def print_config():
|
||||
@ -58,7 +58,7 @@ if __name__ == '__main__':
|
||||
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||
print 'yes'
|
||||
elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch':
|
||||
# Some docs say it'll be called with fetch, some say no arg at all
|
||||
# Some docs say it'll be called with fetch, some say no arg at all
|
||||
try:
|
||||
get_cpu_temperature()
|
||||
except:
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
##!/usr/bin/env python
|
||||
"""
|
||||
fritzbox_cpu_usage - A munin plugin for Linux to monitor AVM Fritzbox
|
||||
Copyright (C) 2015 Christian Stade-Schuldt
|
||||
@ -22,7 +22,7 @@ import sys
|
||||
import fritzbox_helper as fh
|
||||
|
||||
PAGE = '/system/ecostat.lua'
|
||||
pattern = re.compile('.*\/(StatCPU)".*=.*"(.*?)"')
|
||||
pattern = re.compile(".*/(StatCPU)\".*=.*\"(.*?)\"")
|
||||
|
||||
|
||||
def get_cpu_usage():
|
||||
@ -36,7 +36,7 @@ def get_cpu_usage():
|
||||
|
||||
m = re.search(pattern, data)
|
||||
if m:
|
||||
print 'cpu.value %d' %(int(m.group(2).split(',')[0]))
|
||||
print 'cpu.value %d' % (int(m.group(2).split(',')[0]))
|
||||
|
||||
|
||||
def print_config():
|
||||
@ -58,7 +58,7 @@ if __name__ == '__main__':
|
||||
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||
print 'yes'
|
||||
elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch':
|
||||
# Some docs say it'll be called with fetch, some say no arg at all
|
||||
# Some docs say it'll be called with fetch, some say no arg at all
|
||||
try:
|
||||
get_cpu_usage()
|
||||
except:
|
||||
|
@ -22,7 +22,7 @@ import sys
|
||||
import fritzbox_helper as fh
|
||||
|
||||
PAGE = '/system/ecostat.lua'
|
||||
pattern = re.compile('.*\/(StatRAM.*?)".*=.*"(.*?)"')
|
||||
pattern = re.compile(".*/(StatRAM.*?)\".*=.*\"(.*?)\"")
|
||||
USAGE_MAPPING = {'StatRAMCacheUsed': 'cache', 'StatRAMPhysFree': 'free', 'StatRAMStrictlyUsed': 'strict'}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ def get_memory_usage():
|
||||
matches = re.finditer(pattern, data)
|
||||
if matches:
|
||||
for m in matches:
|
||||
print'%s.value %d' % (USAGE_MAPPING[m.group(1)], int(m.group(2).split(',')[0]))
|
||||
print'%s.value %d' % (USAGE_MAPPING[m.group(1)], int(m.group(2).split(',')[0]))
|
||||
|
||||
|
||||
def print_config():
|
||||
@ -65,7 +65,7 @@ if __name__ == '__main__':
|
||||
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||
print 'yes'
|
||||
elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch':
|
||||
# Some docs say it'll be called with fetch, some say no arg at all
|
||||
# Some docs say it'll be called with fetch, some say no arg at all
|
||||
try:
|
||||
get_memory_usage()
|
||||
except:
|
||||
|
@ -22,9 +22,10 @@ import sys
|
||||
import fritzbox_helper as fh
|
||||
|
||||
PAGE = '/system/energy.lua'
|
||||
pattern = re.compile('.*\/(.*act?)".*=.*"(.*?)"')
|
||||
DEVICE_MAPPING = { 'rate_abact' : 'ab', 'rate_dspact': 'dsl' , 'rate_sumact': 'system',
|
||||
'rate_systemact': 'cpu', 'rate_usbhostact': 'usb', 'rate_wlanact': 'wifi'}
|
||||
pattern = re.compile(".*/(.*act?)\".*=.*\"(.*?)\"")
|
||||
DEVICE_MAPPING = {'rate_abact': 'ab', 'rate_dspact': 'dsl', 'rate_sumact': 'system',
|
||||
'rate_systemact': 'cpu', 'rate_usbhostact': 'usb', 'rate_wlanact': 'wifi'}
|
||||
|
||||
|
||||
def get_power_consumption():
|
||||
"""get the current power consumption usage"""
|
||||
@ -37,7 +38,7 @@ def get_power_consumption():
|
||||
matches = re.finditer(pattern, data)
|
||||
if matches:
|
||||
for m in matches:
|
||||
print'%s.value %d' % (DEVICE_MAPPING[m.group(1)], int(m.group(2)))
|
||||
print'%s.value %d' % (DEVICE_MAPPING[m.group(1)], int(m.group(2)))
|
||||
|
||||
|
||||
def print_config():
|
||||
@ -89,7 +90,7 @@ if __name__ == '__main__':
|
||||
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||
print 'yes'
|
||||
elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch':
|
||||
# Some docs say it'll be called with fetch, some say no arg at all
|
||||
# Some docs say it'll be called with fetch, some say no arg at all
|
||||
try:
|
||||
get_power_consumption()
|
||||
except:
|
||||
|
@ -14,27 +14,32 @@
|
||||
#%# capabilities=autoconf
|
||||
"""
|
||||
|
||||
import sys, os
|
||||
import sys
|
||||
|
||||
from fritzconnection import FritzConnection
|
||||
|
||||
|
||||
def print_values():
|
||||
try:
|
||||
connection = FritzConnection()
|
||||
con = FritzConnection()
|
||||
except Exception as e:
|
||||
sys.exit("Couldn't get WAN traffic")
|
||||
|
||||
down_traffic = connection.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived']
|
||||
down_traffic = con.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived']
|
||||
print ('down.value %d' % down_traffic)
|
||||
|
||||
up_traffic = connection.call_action('WANCommonInterfaceConfig', 'GetTotalBytesSent')['NewTotalBytesSent']
|
||||
up_traffic = con.call_action('WANCommonInterfaceConfig', 'GetTotalBytesSent')['NewTotalBytesSent']
|
||||
print ('up.value %d' % up_traffic)
|
||||
|
||||
max_down_traffic = connection.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')['NewLayer1DownstreamMaxBitRate']
|
||||
max_down_traffic = con.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[
|
||||
'NewLayer1DownstreamMaxBitRate']
|
||||
print ('maxdown.value %d' % max_down_traffic)
|
||||
|
||||
max_up_traffic = connection.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')['NewLayer1UpstreamMaxBitRate']
|
||||
max_up_traffic = con.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[
|
||||
'NewLayer1UpstreamMaxBitRate']
|
||||
print ('maxup.value %d' % max_up_traffic)
|
||||
|
||||
|
||||
def print_config():
|
||||
print "graph_title AVM Fritz!Box WAN traffic"
|
||||
print "graph_args --base 1000"
|
||||
@ -64,11 +69,12 @@ def print_config():
|
||||
print "maxup.draw LINE1"
|
||||
print "maxup.info Maximum speed of the WAN interface."
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
||||
print_config()
|
||||
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||
print "yes" # Some docs say it'll be called with fetch, some say no arg at all
|
||||
print "yes" # Some docs say it'll be called with fetch, some say no arg at all
|
||||
elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'):
|
||||
try:
|
||||
print_values()
|
||||
|
@ -14,9 +14,11 @@
|
||||
#%# capabilities=autoconf
|
||||
"""
|
||||
|
||||
import sys, os
|
||||
import sys
|
||||
|
||||
from fritzconnection import FritzConnection
|
||||
|
||||
|
||||
def print_values():
|
||||
try:
|
||||
connection = FritzConnection()
|
||||
@ -24,7 +26,8 @@ def print_values():
|
||||
sys.exit("Couldn't get connection uptime")
|
||||
|
||||
uptime = connection.call_action('WANIPConnection', 'GetStatusInfo')['NewUptime']
|
||||
print ('uptime.value %.2f' % (int(uptime)/86400.0))
|
||||
print ('uptime.value %.2f' % (int(uptime) / 86400.0))
|
||||
|
||||
|
||||
def print_config():
|
||||
print "graph_title AVM Fritz!Box Connection Uptime"
|
||||
@ -35,11 +38,12 @@ def print_config():
|
||||
print "uptime.label uptime"
|
||||
print "uptime.draw AREA"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
||||
print_config()
|
||||
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||
print "yes" # Some docs say it'll be called with fetch, some say no arg at all
|
||||
print "yes" # Some docs say it'll be called with fetch, some say no arg at all
|
||||
elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'):
|
||||
try:
|
||||
print_values()
|
||||
|
@ -22,7 +22,7 @@ import sys
|
||||
import fritzbox_helper as fh
|
||||
|
||||
PAGE = '/system/energy.lua'
|
||||
pattern = re.compile('(\d+) WLAN')
|
||||
pattern = re.compile("(\d+) WLAN")
|
||||
|
||||
|
||||
def get_connected_wifi_devices():
|
||||
@ -57,7 +57,7 @@ if __name__ == '__main__':
|
||||
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||
print 'yes'
|
||||
elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch':
|
||||
# Some docs say it'll be called with fetch, some say no arg at all
|
||||
# Some docs say it'll be called with fetch, some say no arg at all
|
||||
try:
|
||||
get_connected_wifi_devices()
|
||||
except:
|
||||
|
Loading…
Reference in New Issue
Block a user