1
0
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:
Christian Stade-Schuldt 2015-06-05 00:59:24 +02:00
parent 9e8e067531
commit 2bd15e836d
7 changed files with 57 additions and 46 deletions

View File

@ -22,7 +22,7 @@ import sys
import fritzbox_helper as fh import fritzbox_helper as fh
PAGE = '/system/ecostat.lua' PAGE = '/system/ecostat.lua'
pattern = re.compile('.*\/(StatTemperature)".*=.*"(.*?)"') pattern = re.compile(".*/(StatTemperature)\".*=.*\"(.*?)\"")
def get_cpu_temperature(): def get_cpu_temperature():

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python ##!/usr/bin/env python
""" """
fritzbox_cpu_usage - A munin plugin for Linux to monitor AVM Fritzbox fritzbox_cpu_usage - A munin plugin for Linux to monitor AVM Fritzbox
Copyright (C) 2015 Christian Stade-Schuldt Copyright (C) 2015 Christian Stade-Schuldt
@ -22,7 +22,7 @@ import sys
import fritzbox_helper as fh import fritzbox_helper as fh
PAGE = '/system/ecostat.lua' PAGE = '/system/ecostat.lua'
pattern = re.compile('.*\/(StatCPU)".*=.*"(.*?)"') pattern = re.compile(".*/(StatCPU)\".*=.*\"(.*?)\"")
def get_cpu_usage(): def get_cpu_usage():

View File

@ -22,7 +22,7 @@ import sys
import fritzbox_helper as fh import fritzbox_helper as fh
PAGE = '/system/ecostat.lua' PAGE = '/system/ecostat.lua'
pattern = re.compile('.*\/(StatRAM.*?)".*=.*"(.*?)"') pattern = re.compile(".*/(StatRAM.*?)\".*=.*\"(.*?)\"")
USAGE_MAPPING = {'StatRAMCacheUsed': 'cache', 'StatRAMPhysFree': 'free', 'StatRAMStrictlyUsed': 'strict'} USAGE_MAPPING = {'StatRAMCacheUsed': 'cache', 'StatRAMPhysFree': 'free', 'StatRAMStrictlyUsed': 'strict'}

View File

@ -22,10 +22,11 @@ import sys
import fritzbox_helper as fh import fritzbox_helper as fh
PAGE = '/system/energy.lua' PAGE = '/system/energy.lua'
pattern = re.compile('.*\/(.*act?)".*=.*"(.*?)"') pattern = re.compile(".*/(.*act?)\".*=.*\"(.*?)\"")
DEVICE_MAPPING = {'rate_abact': 'ab', 'rate_dspact': 'dsl', 'rate_sumact': 'system', DEVICE_MAPPING = {'rate_abact': 'ab', 'rate_dspact': 'dsl', 'rate_sumact': 'system',
'rate_systemact': 'cpu', 'rate_usbhostact': 'usb', 'rate_wlanact': 'wifi'} 'rate_systemact': 'cpu', 'rate_usbhostact': 'usb', 'rate_wlanact': 'wifi'}
def get_power_consumption(): def get_power_consumption():
"""get the current power consumption usage""" """get the current power consumption usage"""

View File

@ -14,27 +14,32 @@
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import sys, os import sys
from fritzconnection import FritzConnection from fritzconnection import FritzConnection
def print_values(): def print_values():
try: try:
connection = FritzConnection() con = FritzConnection()
except Exception as e: except Exception as e:
sys.exit("Couldn't get WAN traffic") 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) 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) 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) 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) print ('maxup.value %d' % max_up_traffic)
def print_config(): def print_config():
print "graph_title AVM Fritz!Box WAN traffic" print "graph_title AVM Fritz!Box WAN traffic"
print "graph_args --base 1000" print "graph_args --base 1000"
@ -64,6 +69,7 @@ def print_config():
print "maxup.draw LINE1" print "maxup.draw LINE1"
print "maxup.info Maximum speed of the WAN interface." print "maxup.info Maximum speed of the WAN interface."
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()

View File

@ -14,9 +14,11 @@
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import sys, os import sys
from fritzconnection import FritzConnection from fritzconnection import FritzConnection
def print_values(): def print_values():
try: try:
connection = FritzConnection() connection = FritzConnection()
@ -26,6 +28,7 @@ def print_values():
uptime = connection.call_action('WANIPConnection', 'GetStatusInfo')['NewUptime'] 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(): def print_config():
print "graph_title AVM Fritz!Box Connection Uptime" print "graph_title AVM Fritz!Box Connection Uptime"
print "graph_args --base 1000 -l 0" print "graph_args --base 1000 -l 0"
@ -35,6 +38,7 @@ def print_config():
print "uptime.label uptime" print "uptime.label uptime"
print "uptime.draw AREA" print "uptime.draw AREA"
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()

View File

@ -22,7 +22,7 @@ import sys
import fritzbox_helper as fh import fritzbox_helper as fh
PAGE = '/system/energy.lua' PAGE = '/system/energy.lua'
pattern = re.compile('(\d+) WLAN') pattern = re.compile("(\d+) WLAN")
def get_connected_wifi_devices(): def get_connected_wifi_devices():