[MUNIN] Überwachung AVM Fritzbox Traffic via UPNP mit Munin

1 Stern2 Sterne3 Sterne4 Sterne5 Sterne (2 Stimmen, Durchschnitt: 3,00 von 5)
Loading...

Heute stelle ich ein weiteres Plugin für die Überwachung der AVM FritzBox Modelle vor. Auch dieses Plugin nutzt die UPNP Schnittstelle, welche ich bereits im letzten Beitrag vorgestellt habe. Das Plugin liest die globale Anzahl Transferierter Bytes der Box aus und errechnet automatisch den Diff seit dem letzten Update. Die Daten werden in Bits angezeigt.

Auch hier wird die globale Klasse MuninPlugin benötigt, welche Sie hier finden.

avm_traffic_router-day

  1. #!/usr/bin/php
  2. <?php
  3. ##############################
  4. #%# family=auto
  5. #%# capabilities=autoconf
  6.  
  7. require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MuninPlugin.php';
  8.  
  9. /**
  10.  * AVM Traffic plugin for Munin
  11.  *
  12.  * - Add symlink:
  13.  * ln -s <pathtothisfile> /etc/munin/plugins/avm_traffic_router
  14.  *
  15.  * - Add plugin configuration to /etc/munin/plugin-conf.d/avm
  16.  * [avm_traffic_router]
  17.  * env.ip 192.168.178.1:49000
  18.  * env.host fritz.box
  19.  *
  20.  * @author Mike Goldhausen
  21.  * @copyright Copyright (c) 2015 by MiGo-WebDesign, www.migo-webdesign.de, Germany
  22.  */
  23.  
  24. class AvmTraffic extends MuninPlugin {
  25.  
  26. 	/**
  27. 	 * general Config for Plugin
  28. 	 *
  29. 	 * @return array
  30. 	*/
  31. 	protected function getPluginSetup() {
  32. 		return array(
  33. 				'host_name' => $this->avm['host'],
  34. 				'graph_order' => 'down up',
  35. 				'graph_title' => 'AVM Fritz!Box WAN traffic',
  36. 				'graph_category' => 'network',
  37. 				'graph_info' => 'This graph shows the traffic of the AVM Fritz!Box WAN network interface. Please note that the traffic is shown in bits per second, not bytes.',
  38. 				'graph_vlabel' => 'bits in (-) / out (+) per \${graph_period}',
  39. 				'graph_args' => '--base 1024'
  40. 		);
  41. 	}
  42.  
  43. 	/**
  44. 	 * Config for Graphs
  45. 	 *
  46. 	 * @return array
  47. 	 */
  48. 	protected function getPluginGraphs() {
  49. 		$graphs = array();
  50.  
  51. 		$graphs['down']['label'] = "received";
  52. 		$graphs['down']['type'] = "COUNTER";
  53. 		$graphs['down']['graph'] = "no";
  54. 		$graphs['down']['cdef'] = "down,8,*";
  55. 		$graphs['down']['max'] = "1000000000";
  56.  
  57. 		$graphs['up']['label'] = "send";
  58. 		$graphs['up']['type'] = "COUNTER";
  59. 		$graphs['up']['draw'] = "AREA";
  60. 		$graphs['up']['cdef'] = "up,8,*";
  61. 		$graphs['up']['max'] = "1000000000";
  62. 		$graphs['up']['negative'] = "down";
  63. 		$graphs['up']['info'] = "Traffic of the WAN interface.";
  64.  
  65. 		return $graphs;
  66. 	}
  67.  
  68. 	/**
  69. 	 * Transform data from RAW HTML into XML Structure
  70. 	 *
  71. 	 * @return data
  72. 	 */
  73. 	protected function transformData() {
  74. 		$client = new SoapClient(
  75. 			null,
  76. 			array(
  77. 					'location'   => "http://".$this->avm['ip']."/igdupnp/control/WANCommonIFC1",
  78. 					'uri'        => "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1",
  79. 					'soapaction' => "",
  80. 					'noroot'     => True
  81. 			)
  82. 		);
  83.  
  84. 		$data_prop = $client->GetCommonLinkProperties();
  85. 		$data_stats = $client->GetAddonInfos();
  86.  
  87. 		$graphs['up'] = $data_stats['NewTotalBytesSent'];
  88. 		$graphs['down'] = $data_stats['NewTotalBytesReceived'];
  89.  
  90. 		return $graphs;
  91. 	}
  92.  
  93. 	/**
  94. 	 * Read source & collecting values
  95. 	 *
  96. 	 * @return array
  97. 	 */
  98. 	protected function getValues() {
  99. 		$data = $this->transformData();
  100. 		return $data;
  101. 	}
  102.  
  103. }
  104.  
  105. $plugin = new AvmTraffic($argv);
  106. $plugin->start($argv);
  107. ?>

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*

Sicherheitsfrage * Time limit is exhausted. Please reload CAPTCHA.